diff --git a/main.go b/main.go index 3206b666..2ea34eca 100644 --- a/main.go +++ b/main.go @@ -205,6 +205,46 @@ func main() { // fmt.Println("pods:", pods[pod].Name) // } + // start podHandler + handlerPodConfig := api.PodHandlerConfig{ + GetContainerLogs: nodeProvider.GetLogs, + GetPods: nodeProvider.GetPods, + GetStatsSummary: nodeProvider.GetStatsSummary, + } + + mux := http.NewServeMux() + + podRoutes := api.PodHandlerConfig{ + GetContainerLogs: handlerPodConfig.GetContainerLogs, + GetStatsSummary: handlerPodConfig.GetStatsSummary, + GetPods: handlerPodConfig.GetPods, + } + + api.AttachPodRoutes(podRoutes, mux, true) + + parsedIP := net.ParseIP(os.Getenv("POD_IP")) + retriever := newSelfSignedCertificateRetriever(cfg.NodeName, parsedIP) + + server := &http.Server{ + Addr: fmt.Sprintf("0.0.0.0:%d", 10255), + Handler: mux, + ReadHeaderTimeout: 10 * time.Second, // Required to limit the effects of the Slowloris attack. + TLSConfig: &tls.Config{ + GetCertificate: retriever, + MinVersion: tls.VersionTLS12, + }, + } + + go func() { + log.G(ctx).Infof("Starting the virtual kubelet HTTPs server listening on %q", server.Addr) + + // Key and certificate paths are not specified, since already configured as part of the TLSConfig. + if err := server.ListenAndServeTLS("", ""); err != nil { + log.G(ctx).Errorf("Failed to start the HTTPs server: %v", err) + os.Exit(1) + } + }() + pc, err := node.NewPodController(podControllerConfig) // <-- instatiates the pod controller if err != nil { log.G(ctx).Fatal(err) diff --git a/pkg/common/func.go b/pkg/common/func.go index 1e85b4e2..f03c688c 100644 --- a/pkg/common/func.go +++ b/pkg/common/func.go @@ -6,7 +6,6 @@ import ( "encoding/json" "errors" "fmt" - "io/ioutil" "net/http" "os" "time" @@ -192,7 +191,7 @@ func NewServiceAccount() error { time.Sleep(5 * time.Second) continue } else { - returnValue, _ = ioutil.ReadAll(resp.Body) + returnValue, _ = os.ReadAll(resp.Body) } if resp.StatusCode == http.StatusOK { diff --git a/pkg/interlink/create.go b/pkg/interlink/create.go index e98b1c43..184256b7 100644 --- a/pkg/interlink/create.go +++ b/pkg/interlink/create.go @@ -3,7 +3,6 @@ package interlink import ( "bytes" "encoding/json" - "io/ioutil" "net/http" "time" @@ -14,7 +13,7 @@ import ( func CreateHandler(w http.ResponseWriter, r *http.Request) { log.G(Ctx).Info("InterLink: received Create call") - bodyBytes, err := ioutil.ReadAll(r.Body) + bodyBytes, err := os.ReadAll(r.Body) statusCode := http.StatusOK if err != nil { statusCode = http.StatusInternalServerError @@ -91,7 +90,7 @@ func CreateHandler(w http.ResponseWriter, r *http.Request) { log.G(Ctx).Debug(statusCode) } - returnValue, _ := ioutil.ReadAll(resp.Body) + returnValue, _ := os.ReadAll(resp.Body) log.G(Ctx).Debug(string(returnValue)) w.WriteHeader(statusCode) w.Write(returnValue) diff --git a/pkg/interlink/delete.go b/pkg/interlink/delete.go index 846b8f79..3246b639 100644 --- a/pkg/interlink/delete.go +++ b/pkg/interlink/delete.go @@ -3,8 +3,8 @@ package interlink import ( "bytes" "encoding/json" - "io/ioutil" "net/http" + "os" "github.com/containerd/containerd/log" commonIL "github.com/intertwin-eu/interlink/pkg/common" @@ -13,7 +13,7 @@ import ( func DeleteHandler(w http.ResponseWriter, r *http.Request) { log.G(Ctx).Info("InterLink: received Delete call") - bodyBytes, err := ioutil.ReadAll(r.Body) + bodyBytes, err := os.ReadAll(r.Body) statusCode := http.StatusOK if err != nil { @@ -41,7 +41,7 @@ func DeleteHandler(w http.ResponseWriter, r *http.Request) { return } - returnValue, _ := ioutil.ReadAll(resp.Body) + returnValue, _ := os.ReadAll(resp.Body) statusCode = resp.StatusCode if statusCode != http.StatusOK { diff --git a/pkg/interlink/kubeCFG.go b/pkg/interlink/kubeCFG.go index 1368e0fe..5a423939 100644 --- a/pkg/interlink/kubeCFG.go +++ b/pkg/interlink/kubeCFG.go @@ -1,7 +1,6 @@ package interlink import ( - "io/ioutil" "net/http" "os" @@ -15,7 +14,7 @@ func SetKubeCFGHandler(w http.ResponseWriter, r *http.Request) { path := "/tmp/.kube/" statusCode := http.StatusOK - bodyBytes, err := ioutil.ReadAll(r.Body) + bodyBytes, err := os.ReadAll(r.Body) if err != nil { statusCode = http.StatusInternalServerError w.WriteHeader(statusCode) diff --git a/pkg/interlink/status.go b/pkg/interlink/status.go index 085140a0..7a5c7f6c 100644 --- a/pkg/interlink/status.go +++ b/pkg/interlink/status.go @@ -2,7 +2,7 @@ package interlink import ( "bytes" - "io/ioutil" + "io" "net/http" "strconv" @@ -13,7 +13,7 @@ import ( func StatusHandler(w http.ResponseWriter, r *http.Request) { statusCode := http.StatusOK log.G(Ctx).Info("InterLink: received GetStatus call") - bodyBytes, err := ioutil.ReadAll(r.Body) + bodyBytes, err := io.ReadAll(r.Body) if err != nil { log.G(Ctx).Fatal(err) } @@ -38,7 +38,7 @@ func StatusHandler(w http.ResponseWriter, r *http.Request) { statusCode = http.StatusInternalServerError } - returnValue, _ := ioutil.ReadAll(resp.Body) + returnValue, _ := io.ReadAll(resp.Body) log.G(Ctx).Debug("InterLink: status " + string(returnValue)) w.WriteHeader(statusCode) diff --git a/pkg/sidecars/docker/handlers.go b/pkg/sidecars/docker/handlers.go index f453611e..464ced98 100644 --- a/pkg/sidecars/docker/handlers.go +++ b/pkg/sidecars/docker/handlers.go @@ -2,7 +2,7 @@ package docker import ( "encoding/json" - "io/ioutil" + "io" "net/http" "os" "strings" @@ -19,7 +19,7 @@ func StatusHandler(w http.ResponseWriter, r *http.Request) { var req []*v1.Pod statusCode := http.StatusOK - bodyBytes, err := ioutil.ReadAll(r.Body) + bodyBytes, err := io.ReadAll(r.Body) if err != nil { statusCode = http.StatusInternalServerError w.WriteHeader(statusCode) @@ -86,7 +86,7 @@ func CreateHandler(w http.ResponseWriter, r *http.Request) { log.G(Ctx).Info("Docker Sidecar: received Create call") var execReturn exec.ExecResult statusCode := http.StatusOK - bodyBytes, err := ioutil.ReadAll(r.Body) + bodyBytes, err := io.ReadAll(r.Body) if err != nil { statusCode = http.StatusInternalServerError w.WriteHeader(statusCode) @@ -201,7 +201,7 @@ func DeleteHandler(w http.ResponseWriter, r *http.Request) { log.G(Ctx).Info("Docker Sidecar: received Delete call") var execReturn exec.ExecResult statusCode := http.StatusOK - bodyBytes, err := ioutil.ReadAll(r.Body) + bodyBytes, err := io.ReadAll(r.Body) if err != nil { statusCode = http.StatusInternalServerError diff --git a/pkg/sidecars/slurm/handlers.go b/pkg/sidecars/slurm/handlers.go index e2e4e106..ff9732f7 100644 --- a/pkg/sidecars/slurm/handlers.go +++ b/pkg/sidecars/slurm/handlers.go @@ -2,7 +2,7 @@ package slurm import ( "encoding/json" - "io/ioutil" + "io" "net/http" "os" "strings" @@ -20,7 +20,7 @@ func SubmitHandler(w http.ResponseWriter, r *http.Request) { log.G(Ctx).Info("Slurm Sidecar: received Submit call") statusCode := http.StatusOK - bodyBytes, err := ioutil.ReadAll(r.Body) + bodyBytes, err := io.ReadAll(r.Body) if err != nil { statusCode = http.StatusInternalServerError w.WriteHeader(statusCode) @@ -128,7 +128,7 @@ func StopHandler(w http.ResponseWriter, r *http.Request) { log.G(Ctx).Info("Slurm Sidecar: received Stop call") statusCode := http.StatusOK - bodyBytes, err := ioutil.ReadAll(r.Body) + bodyBytes, err := io.ReadAll(r.Body) if err != nil { statusCode = http.StatusInternalServerError w.WriteHeader(statusCode) @@ -172,7 +172,7 @@ func StatusHandler(w http.ResponseWriter, r *http.Request) { statusCode := http.StatusOK log.G(Ctx).Info("Slurm Sidecar: received GetStatus call") - bodyBytes, err := ioutil.ReadAll(r.Body) + bodyBytes, err := io.ReadAll(r.Body) if err != nil { statusCode = http.StatusInternalServerError w.WriteHeader(statusCode) diff --git a/pkg/virtualkubelet/execute.go b/pkg/virtualkubelet/execute.go index 2d3c016f..ff4b2454 100644 --- a/pkg/virtualkubelet/execute.go +++ b/pkg/virtualkubelet/execute.go @@ -6,7 +6,7 @@ import ( "encoding/json" "errors" "fmt" - "io/ioutil" + "io" "net/http" "os" "strconv" @@ -47,7 +47,7 @@ func createRequest(pods []*v1.Pod, token string) ([]byte, error) { return nil, errors.New("Unexpected error occured while creating Pods. Status code: " + strconv.Itoa(resp.StatusCode) + ". Check InterLink's logs for further informations") } else { log.G(context.Background()).Info(string(returnValue)) - returnValue, err = ioutil.ReadAll(resp.Body) + returnValue, err = io.ReadAll(resp.Body) if err != nil { log.L.Error(err) return nil, err @@ -84,7 +84,7 @@ func deleteRequest(pods []*v1.Pod, token string) ([]byte, error) { if statusCode != http.StatusOK { return nil, errors.New("Unexpected error occured while deleting Pods. Status code: " + strconv.Itoa(resp.StatusCode) + ". Check InterLink's logs for further informations") } else { - returnValue, _ = ioutil.ReadAll(resp.Body) + returnValue, _ = os.ReadAll(resp.Body) log.G(context.Background()).Info(string(returnValue)) var response []commonIL.PodStatus err = json.Unmarshal(returnValue, &response) @@ -124,7 +124,7 @@ func statusRequest(podsList []*v1.Pod, token string) ([]byte, error) { if resp.StatusCode != http.StatusOK { return nil, errors.New("Unexpected error occured while getting status. Status code: " + strconv.Itoa(resp.StatusCode) + ". Check InterLink's logs for further informations") } else { - returnValue, _ = ioutil.ReadAll(resp.Body) + returnValue, _ = io.ReadAll(resp.Body) if err != nil { log.L.Error(err) return nil, err