diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 3a8ed27c..26fa5667 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -31,6 +31,7 @@ you submit the pull request). We have a 3 steps process for contributions. understanding and appreciating your pull request, please use the template to explain _why_ you are making this contribution, rather than just _what_ the contribution entails. +2. **Run E2E tests with success**. You can follow the steps described [here](https://intertwin-eu.github.io/interLink/docs/Developers) ### Code Review Process @@ -44,7 +45,7 @@ follows: 1. A maintainer will review your code and merge it if no changes are necessary. Your change will be merged into the repository's `main` branch. -1. If a maintainer has feedback or questions on your changes then they will set +2. If a maintainer has feedback or questions on your changes then they will set `request changes` in the review and provide an explanation. ## Using git diff --git a/ci/main.go b/ci/main.go index 74143371..cae6ed29 100644 --- a/ci/main.go +++ b/ci/main.go @@ -15,19 +15,6 @@ import ( ) var ( - interLinkPatch = ` -kind: Deployment -metadata: - name: interlink - namespace: interlink -spec: - template: - spec: - containers: - - name: interlink - image: "{{.InterLinkRef}}" - -` virtualKubeletPatch = ` kind: Deployment metadata: @@ -39,6 +26,8 @@ spec: containers: - name: inttw-vk image: "{{.VirtualKubeletRef}}" + - name: interlink + image: "{{.InterLinkRef}}" ` ) @@ -144,18 +133,8 @@ EOF`}, ContainerWithExecOpts{SkipEntrypoint: true}). VirtualKubeletRef: m.VirtualKubeletRef, } - interLinkCompiler, err := template.New("interlink").Parse(interLinkPatch) - if err != nil { - return nil, err - } - bufferIL := new(bytes.Buffer) - err = interLinkCompiler.Execute(bufferIL, patch) - if err != nil { - return nil, err - } - virtualKubeletCompiler, err := template.New("vk").Parse(virtualKubeletPatch) if err != nil { return nil, err @@ -209,34 +188,11 @@ EOF`}, ContainerWithExecOpts{SkipEntrypoint: true}). fmt.Println(vkConfig) return m, nil - //maxRetries := 10 - //retryBackoff := 10 * time.Second - // for i := 0; i < maxRetries; i++ { - // kubectlGetNodes, err := kubectl.WithExec([]string{"get", "nodes", "-o", "wide", "virtual-kubelet"}).Stdout(ctx) - // if err != nil { - // fmt.Println(fmt.Errorf("could not fetch nodes: %v", err)) - // fmt.Println("waiting for k8s to start:", kubectlGetNodes) - // time.Sleep(retryBackoff) - // continue - // } - // if strings.Contains(kubectlGetNodes, " Ready") { - // time.Sleep(30 * time.Second) - // return m, nil - // } - // time.Sleep(retryBackoff) - // } - // kubectlAll, err := kubectl.WithExec([]string{"logs", "-n", "interlink", "-l", "nodeName=virtual-kubelet"}).Stdout(ctx) - // if err != nil { - // return nil, err - // } - // fmt.Println(kubectlAll) - // - // return nil, fmt.Errorf("k8s took too long to start") } // Returns the kubeconfig file of the k3s cluster func (m *Interlink) Config() *File { - return m.KubeConfigHost + return dag.K3S(m.Name).Config(true) } // Build interLink and virtual kubelet docker images from source diff --git a/ci/manifests/interlink-config.yaml b/ci/manifests/interlink-config.yaml index a8782bbd..dc5cd701 100644 --- a/ci/manifests/interlink-config.yaml +++ b/ci/manifests/interlink-config.yaml @@ -5,7 +5,8 @@ metadata: namespace: interlink data: InterLinkConfig.yaml: | - InterlinkAddress: "http://0.0.0.0" + InterlinkAddress: "unix:///var/run/interlink.socket" + #InterlinkAddress: "http://0.0.0.0" InterlinkPort: "3000" #SidecarURL: "http://plugin.interlink.svc.cluster.local" SidecarURL: "http://plugin" diff --git a/ci/manifests/interlink.yaml b/ci/manifests/interlink.yaml deleted file mode 100644 index b7a3c048..00000000 --- a/ci/manifests/interlink.yaml +++ /dev/null @@ -1,47 +0,0 @@ -apiVersion: v1 -kind: Service -metadata: - name: interlink - namespace: interlink -spec: - selector: - app: interlink - ports: - - protocol: TCP - port: 3000 - targetPort: 3000 ---- -apiVersion: apps/v1 -kind: Deployment -metadata: - name: interlink - namespace: interlink - labels: - app: interlink -spec: - replicas: 1 - selector: - matchLabels: - app: interlink - template: - metadata: - labels: - app: interlink - spec: - hostNetwork: true - containers: - - name: interlink - image: "ghcr.io/intertwin-eu/interlink/interlink" - imagePullPolicy: Always - env: - - name: CONFIGPATH - value: "/etc/interlink/InterLinkConfig.yaml" - volumeMounts: - - name: config - mountPath: /etc/interlink/InterLinkConfig.yaml - subPath: InterLinkConfig.yaml - volumes: - - name: config - configMap: - # Provide the name of the ConfigMap you want to mount. - name: interlink-config diff --git a/ci/manifests/kustomization.yaml b/ci/manifests/kustomization.yaml index 168dc6f7..b13558f2 100644 --- a/ci/manifests/kustomization.yaml +++ b/ci/manifests/kustomization.yaml @@ -2,7 +2,7 @@ resources: - virtual-kubelet-config.yaml - virtual-kubelet.yaml - interlink-config.yaml -- interlink.yaml +#- interlink.yaml #- plugin-k8s-config.yaml #- plugin.yaml patches: @@ -10,8 +10,4 @@ patches: target: kind: Deployment labelSelector: nodeName=virtual-kubelet -- path: interlink-merge.yaml - target: - kind: Deployment - labelSelector: app=interlink diff --git a/ci/manifests/plugin-config.yaml b/ci/manifests/plugin-config.yaml index 2163d46a..15b9c56f 100644 --- a/ci/manifests/plugin-config.yaml +++ b/ci/manifests/plugin-config.yaml @@ -6,9 +6,9 @@ VerboseLogging: true ErrorsOnlyLogging: false ExportPodData: true # NEEDED PATH FOR GITHUB ACTIONS -DataRootFolder: "/home/runner/work/interLink/interLink/.interlink/" +#DataRootFolder: "/home/runner/work/interLink/interLink/.interlink/" # on your host use something like: -#DataRootFolder: "/home/ubuntu/.interlink/" +DataRootFolder: "/home/ubuntu/.interlink/" SbatchPath: "/usr/bin/sbatch" ScancelPath: "/usr/bin/scancel" SqueuePath: "/usr/bin/squeue" diff --git a/ci/manifests/virtual-kubelet-config.yaml b/ci/manifests/virtual-kubelet-config.yaml index 4f13b589..087525a4 100644 --- a/ci/manifests/virtual-kubelet-config.yaml +++ b/ci/manifests/virtual-kubelet-config.yaml @@ -5,14 +5,14 @@ metadata: namespace: interlink data: InterLinkConfig.yaml: | - InterlinkURL: http://interlink.interlink.svc.cluster.local - InterlinkPort: 3000 + InterlinkURL: unix:///var/run/interlink.socket + #InterlinkPort: 3000 ExportPodData: true VerboseLogging: true ErrorsOnlyLogging: false ServiceAccount: "virtual-kubelet" Namespace: interlink - VKTokenFile: /dev/null + VKTokenFile: "" CPU: "100" Memory: "128Gi" Pods: "100" diff --git a/ci/manifests/virtual-kubelet.yaml b/ci/manifests/virtual-kubelet.yaml index 51b34a88..2a5ce0cb 100644 --- a/ci/manifests/virtual-kubelet.yaml +++ b/ci/manifests/virtual-kubelet.yaml @@ -18,6 +18,18 @@ spec: automountServiceAccountToken: true serviceAccountName: virtual-kubelet containers: + - name: interlink + image: "ghcr.io/intertwin-eu/interlink/interlink" + imagePullPolicy: Always + env: + - name: INTERLINKCONFIGPATH + value: "/etc/interlink/InterLinkConfig.yaml" + volumeMounts: + - name: il-config + mountPath: /etc/interlink/InterLinkConfig.yaml + subPath: InterLinkConfig.yaml + - name: sockets + mountPath: /var/run/ - name: inttw-vk image: "ghcr.io/intertwin-eu/interlink/virtual-kubelet-inttw" imagePullPolicy: Always @@ -36,8 +48,20 @@ spec: - name: config mountPath: /etc/interlink/InterLinkConfig.yaml subPath: InterLinkConfig.yaml + - name: sockets + mountPath: /var/run/ volumes: - name: config configMap: # Provide the name of the ConfigMap you want to mount. name: virtual-kubelet-config + - name: sockets + hostPath: + path: /var/run + type: Directory + - name: il-config + configMap: + # Provide the name of the ConfigMap you want to mount. + name: interlink-config + - name: sockets + emptyDir: {} diff --git a/cmd/interlink/main.go b/cmd/interlink/main.go index 3d6aed56..8ce6ef9c 100644 --- a/cmd/interlink/main.go +++ b/cmd/interlink/main.go @@ -5,9 +5,12 @@ import ( "crypto/tls" "flag" "fmt" + "net" "net/http" "os" + "os/signal" "strings" + "syscall" "time" "github.com/sirupsen/logrus" @@ -157,15 +160,39 @@ func main() { interLinkEndpoint := "" if strings.HasPrefix(interLinkConfig.InterlinkAddress, "unix://") { interLinkEndpoint = interLinkConfig.InterlinkAddress + + // Create a Unix domain socket and listen for incoming connections. + socket, err := net.Listen("unix", strings.Replace(interLinkEndpoint, "unix://", "", -1)) + if err != nil { + panic(err) + } + + // Cleanup the sockfile. + c := make(chan os.Signal, 1) + signal.Notify(c, os.Interrupt, syscall.SIGTERM) + go func() { + <-c + os.Remove(interLinkEndpoint) + os.Exit(1) + }() + server := http.Server{ + Handler: mutex, + } + + log.G(ctx).Info(socket) + + if err := server.Serve(socket); err != nil { + log.G(ctx).Fatal(err) + } } else if strings.HasPrefix(interLinkConfig.InterlinkAddress, "http://") { interLinkEndpoint = strings.Replace(interLinkConfig.InterlinkAddress, "http://", "", -1) + ":" + interLinkConfig.Interlinkport - } else { - log.G(ctx).Fatal("Sidecar URL should either start per unix:// or http://") - } - err = http.ListenAndServe(interLinkEndpoint, mutex) + err = http.ListenAndServe(interLinkEndpoint, mutex) - if err != nil { - log.G(ctx).Fatal(err) + if err != nil { + log.G(ctx).Fatal(err) + } + } else { + log.G(ctx).Fatal("Sidecar URL should either start per unix:// or http://") } } diff --git a/cmd/virtual-kubelet/main.go b/cmd/virtual-kubelet/main.go index ab63153d..67a7fa14 100644 --- a/cmd/virtual-kubelet/main.go +++ b/cmd/virtual-kubelet/main.go @@ -24,6 +24,7 @@ import ( "os" "path" "strconv" + "strings" "time" // "k8s.io/client-go/rest" @@ -185,6 +186,8 @@ func main() { } log.L = logruslogger.FromLogrus(logrus.NewEntry(logger)) + log.G(ctx).Info("Config dump", interLinkConfig) + if os.Getenv("ENABLE_TRACING") == "1" { shutdown, err := initProvider(ctx) if err != nil { @@ -207,6 +210,19 @@ func main() { http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true} + if strings.HasPrefix(interLinkConfig.InterlinkURL, "unix://") { + // Dial the Unix socket + interLinkEndpoint := strings.Replace(interLinkConfig.InterlinkURL, "unix://", "", -1) + conn, err := net.Dial("unix", interLinkEndpoint) + if err != nil { + panic(err) + } + + http.DefaultTransport.(*http.Transport).DialContext = func(_ context.Context, _, _ string) (net.Conn, error) { + return conn, nil + } + } + dport, err := strconv.ParseInt(os.Getenv("KUBELET_PORT"), 10, 32) if err != nil { log.G(ctx).Fatal(err) diff --git a/docker-plugin b/docker-plugin deleted file mode 100755 index ebda63fa..00000000 Binary files a/docker-plugin and /dev/null differ diff --git a/helm/interlink/.helmignore b/helm/interlink/.helmignore deleted file mode 100644 index 0e8a0eb3..00000000 --- a/helm/interlink/.helmignore +++ /dev/null @@ -1,23 +0,0 @@ -# Patterns to ignore when building packages. -# This supports shell glob matching, relative path matching, and -# negation (prefixed with !). Only one pattern per line. -.DS_Store -# Common VCS dirs -.git/ -.gitignore -.bzr/ -.bzrignore -.hg/ -.hgignore -.svn/ -# Common backup files -*.swp -*.bak -*.tmp -*.orig -*~ -# Various IDEs -.project -.idea/ -*.tmproj -.vscode/ diff --git a/helm/interlink/Chart.yaml b/helm/interlink/Chart.yaml deleted file mode 100644 index cc8bd96d..00000000 --- a/helm/interlink/Chart.yaml +++ /dev/null @@ -1,24 +0,0 @@ -apiVersion: v2 -name: interlink -description: A Helm chart for interLink virtual kubelet provider - -# A chart can be either an 'application' or a 'library' chart. -# -# Application charts are a collection of templates that can be packaged into versioned archives -# to be deployed. -# -# Library charts provide useful utilities or functions for the chart developer. They're included as -# a dependency of application charts to inject those utilities and functions into the rendering -# pipeline. Library charts do not define any templates and therefore cannot be deployed. -type: application - -# This is the chart version. This version number should be incremented each time you make changes -# to the chart and its templates, including the app version. -# Versions are expected to follow Semantic Versioning (https://semver.org/) -version: 0.1.0 - -# This is the version number of the application being deployed. This version number should be -# incremented each time you make changes to the application. Versions are not expected to -# follow Semantic Versioning. They should reflect the version the application is using. -# It is recommended to use it with quotes. -appVersion: "0.2.3" diff --git a/helm/interlink/README.md b/helm/interlink/README.md deleted file mode 100644 index acb2b0e8..00000000 --- a/helm/interlink/README.md +++ /dev/null @@ -1,8 +0,0 @@ -# interLink Helm Chart - -::: danger ::: - -Work in progress! - -::: danger ::: - diff --git a/helm/interlink/templates/NOTES.txt b/helm/interlink/templates/NOTES.txt deleted file mode 100644 index 6eb8cbc5..00000000 --- a/helm/interlink/templates/NOTES.txt +++ /dev/null @@ -1,5 +0,0 @@ -Check node status with: - -``` -kubectl get node {{ .Values.nodeName }} -``` diff --git a/helm/interlink/templates/_helpers.tpl b/helm/interlink/templates/_helpers.tpl deleted file mode 100644 index 38ea4b10..00000000 --- a/helm/interlink/templates/_helpers.tpl +++ /dev/null @@ -1,62 +0,0 @@ -{{/* -Expand the name of the chart. -*/}} -{{- define "interlink.name" -}} -{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }} -{{- end }} - -{{/* -Create a default fully qualified app name. -We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). -If release name contains chart name it will be used as a full name. -*/}} -{{- define "interlink.fullname" -}} -{{- if .Values.fullnameOverride }} -{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }} -{{- else }} -{{- $name := default .Chart.Name .Values.nameOverride }} -{{- if contains $name .Release.Name }} -{{- .Release.Name | trunc 63 | trimSuffix "-" }} -{{- else }} -{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }} -{{- end }} -{{- end }} -{{- end }} - -{{/* -Create chart name and version as used by the chart label. -*/}} -{{- define "interlink.chart" -}} -{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} -{{- end }} - -{{/* -Common labels -*/}} -{{- define "interlink.labels" -}} -helm.sh/chart: {{ include "interlink.chart" . }} -{{ include "interlink.selectorLabels" . }} -{{- if .Chart.AppVersion }} -app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} -{{- end }} -app.kubernetes.io/managed-by: {{ .Release.Service }} -{{- end }} - -{{/* -Selector labels -*/}} -{{- define "interlink.selectorLabels" -}} -app.kubernetes.io/name: {{ include "interlink.name" . }} -app.kubernetes.io/instance: {{ .Release.Name }} -{{- end }} - -{{/* -Create the name of the service account to use -*/}} -{{- define "interlink.serviceAccountName" -}} -{{- if .Values.serviceAccount.create }} -{{- default (include "interlink.fullname" .) .Values.serviceAccount.name }} -{{- else }} -{{- default "default" .Values.serviceAccount.name }} -{{- end }} -{{- end }} diff --git a/helm/interlink/templates/service-account.yaml b/helm/interlink/templates/service-account.yaml deleted file mode 100644 index b622e723..00000000 --- a/helm/interlink/templates/service-account.yaml +++ /dev/null @@ -1,98 +0,0 @@ -apiVersion: v1 -kind: ServiceAccount -metadata: - name: {{ .Values.nodeName }} - namespace: {{ .Release.Namespace }} ---- -apiVersion: rbac.authorization.k8s.io/v1 -kind: ClusterRole -metadata: - name: "{{ .Values.nodeName }}-role" - namespace: {{ .Release.Namespace }} -rules: -- apiGroups: - - "coordination.k8s.io" - resources: - - leases - verbs: - - update - - create - - get - - list - - watch - - patch -- apiGroups: - - "" - resources: - - configmaps - - secrets - - services - - serviceaccounts - - namespaces - verbs: - - get - - list - - watch -- apiGroups: - - "" - resources: - - pods - verbs: - - delete - - get - - list - - watch - - patch -- apiGroups: - - "" - resources: - - nodes - verbs: - - create - - get -- apiGroups: - - "" - resources: - - nodes/status - verbs: - - update - - patch -- apiGroups: - - "" - resources: - - pods/status - verbs: - - update - - patch -- apiGroups: - - "" - resources: - - events - verbs: - - create - - patch ---- -apiVersion: rbac.authorization.k8s.io/v1 -kind: ClusterRoleBinding -metadata: - name: "{{ .Values.nodeName }}-rolebinding" - namespace: {{ .Release.Namespace }} -subjects: -- kind: ServiceAccount - name: {{ .Values.nodeName }} - namespace: {{ .Release.Namespace }} -roleRef: - apiGroup: rbac.authorization.k8s.io - kind: ClusterRole - name: "{{ .Values.nodeName }}-role" ---- -apiVersion: v1 -kind: Secret -metadata: - name: "{{ .Values.nodeName }}-secret" - namespace: "{{ .Release.Namespace }}" - annotations: - kubernetes.io/service-account.name: {{ .Values.nodeName }} - labels: - kubernetes.io/service-account.name: {{ .Values.nodeName }} -type: kubernetes.io/service-account-token diff --git a/helm/interlink/templates/virtual-kubelet-config.yaml b/helm/interlink/templates/virtual-kubelet-config.yaml deleted file mode 100644 index cda7870f..00000000 --- a/helm/interlink/templates/virtual-kubelet-config.yaml +++ /dev/null @@ -1,18 +0,0 @@ -apiVersion: v1 -kind: ConfigMap -metadata: - name: "virtual-kubelet-config" - namespace: {{ .Release.Namespace }} -data: - InterLinkConfig.yaml: | - InterlinkAddress: {{ .Values.interlink.URL }} - InterlinkPort: {{ .Values.interlink.port }} - ExportPodData: true - VerboseLogging: true - ErrorsOnlyLogging: false - ServiceAccount: "{{ .Values.nodeName }}" - Namespace: "" - VKTokenFile: /opt/interlink/token - CPU: "{{ .Values.virtualNode.CPUs }}" - Memory: "{{ .Values.virtualNode.MemGiB }}GiB" - Pods: "{{ .Values.virtualNode.Pods }}" diff --git a/helm/interlink/templates/virtual-kubelet.yaml b/helm/interlink/templates/virtual-kubelet.yaml deleted file mode 100644 index d4db5fb6..00000000 --- a/helm/interlink/templates/virtual-kubelet.yaml +++ /dev/null @@ -1,82 +0,0 @@ -apiVersion: apps/v1 -kind: Deployment -metadata: - name: {{ .Values.deployment.name}} - namespace: {{ .Release.Namespace}} - labels: - nodeName: {{ .Values.nodeName }} -spec: - replicas: 1 - selector: - matchLabels: - nodeName: {{ .Values.nodeName }} - template: - metadata: - labels: - nodeName: {{ .Values.nodeName }} - spec: - automountServiceAccountToken: true - serviceAccountName: {{ .Values.deployment.name }} - containers: - - name: inttw-vk - image: {{ .Values.deployment.image }} - imagePullPolicy: Always - env: - - name: NODENAME - value: {{ .Values.nodeName }} - - name: KUBELET_PORT - value: "10250" - - name: POD_IP - valueFrom: - fieldRef: - fieldPath: status.podIP - - name: CONFIGPATH - value: "/etc/interlink/InterLinkConfig.yaml" - - name: VKTOKENFILE - value: "/opt/interlink/token" - volumeMounts: - - name: config - mountPath: /etc/interlink/InterLinkConfig.yaml - subPath: InterLinkConfig.yaml - - name: token - mountPath: /opt/interlink - - name: jaeger - image: jaegertracing/all-in-one:1.51 - - name: refresh-token - image: ghcr.io/intertwin-eu/virtual-kubelet-inttw-refresh:latest - imagePullPolicy: Always - env: - - name: IAM_TOKEN_ENDPOINT - value: {{.Values.OAUTH.TokenURL}} - # TODO load env IAM client from secret - - name: IAM_CLIENT_ID - value: {{.Values.OAUTH.ClientID}} - - name: IAM_CLIENT_SECRET - value: {{.Values.OAUTH.ClientSecret}} - - name: IAM_REFRESH_TOKEN - value: {{.Values.OAUTH.RefreshToken}} - - name: IAM_VK_AUD - value: {{.Values.OAUTH.Audience}} - - name: TOKEN_PATH - value: /opt/interlink/token - command: - - python3 - - /opt/refresh.py - resources: - limits: - cpu: 200m - memory: 500Mi - requests: - cpu: 100m - memory: 300Mi - volumeMounts: - - name: token - mountPath: /opt/interlink - volumes: - - name: config - configMap: - name: virtual-kubelet-config - - name: token - hostPath: - path: /tmp - type: Directory diff --git a/helm/interlink/values.yaml b/helm/interlink/values.yaml deleted file mode 100644 index 6d53fd6c..00000000 --- a/helm/interlink/values.yaml +++ /dev/null @@ -1,26 +0,0 @@ -# Default values for interlink. -# This is a YAML-formatted file. -# Declare variables to be passed into your templates. - -nodeName: default-vk - -deployment: - image: ghcr.io/intertwin-eu/interlink/virtual-kubelet-inttw:latest - name: default-vk - -interlink: - URL: http://localhost - port: 5000 - -virtualNode: - CPUs: 100 - MemGiB: 1600 - Pods: 100 - -OAUTH: - TokenURL: DUMMY - ClientID: DUMMY - ClientSecret: DUMMY - RefreshToken: DUMMY - Audience: DUMMY - diff --git a/pkg/virtualkubelet/execute.go b/pkg/virtualkubelet/execute.go index cca1db40..95a69990 100644 --- a/pkg/virtualkubelet/execute.go +++ b/pkg/virtualkubelet/execute.go @@ -25,7 +25,9 @@ import ( func doRequest(req *http.Request, token string) (*http.Response, error) { - req.Header.Add("Authorization", "Bearer "+token) + if token != "" { + req.Header.Add("Authorization", "Bearer "+token) + } req.Header.Set("Content-Type", "application/json") return http.DefaultClient.Do(req) @@ -33,8 +35,9 @@ func doRequest(req *http.Request, token string) (*http.Response, error) { func getSidecarEndpoint(ctx context.Context, interLinkURL string, interLinkPort string) string { interLinkEndpoint := "" + log.G(ctx).Info("InterlingURL: ", interLinkURL) if strings.HasPrefix(interLinkURL, "unix://") { - interLinkEndpoint = interLinkURL + interLinkEndpoint = "http://unix" } else if strings.HasPrefix(interLinkURL, "http://") { interLinkEndpoint = interLinkURL + ":" + interLinkPort } else if strings.HasPrefix(interLinkURL, "https://") { @@ -57,12 +60,14 @@ func PingInterLink(ctx context.Context, config VirtualKubeletConfig) (bool, int, log.G(ctx).Error(err) } - token, err := os.ReadFile(config.VKTokenFile) // just pass the file name - if err != nil { - log.G(ctx).Error(err) - return false, retVal, err + if config.VKTokenFile != "" { + token, err := os.ReadFile(config.VKTokenFile) // just pass the file name + if err != nil { + log.G(ctx).Error(err) + return false, retVal, err + } + req.Header.Add("Authorization", "Bearer "+string(token)) } - req.Header.Add("Authorization", "Bearer "+string(token)) startHttpCall := time.Now().UnixMicro() _, spanHttp := tracer.Start(ctx, "PingHttpCall", trace.WithAttributes( @@ -117,7 +122,9 @@ func updateCacheRequest(ctx context.Context, config VirtualKubeletConfig, pod v1 return err } - req.Header.Add("Authorization", "Bearer "+token) + if token != "" { + req.Header.Add("Authorization", "Bearer "+token) + } req.Header.Set("Content-Type", "application/json") startHttpCall := time.Now().UnixMicro() @@ -312,11 +319,16 @@ func LogRetrieval(ctx context.Context, config VirtualKubeletConfig, logsRequest tracer := otel.Tracer("interlink-service") var returnValue io.ReadCloser interLinkEndpoint := getSidecarEndpoint(ctx, config.InterlinkURL, config.Interlinkport) - b, err := os.ReadFile(config.VKTokenFile) // just pass the file name - if err != nil { - log.G(ctx).Fatal(err) + + token := "" + + if config.VKTokenFile != "" { + b, err := os.ReadFile(config.VKTokenFile) // just pass the file name + if err != nil { + log.G(ctx).Fatal(err) + } + token = string(b) } - token := string(b) bodyBytes, err := json.Marshal(logsRequest) if err != nil { @@ -366,13 +378,15 @@ func LogRetrieval(ctx context.Context, config VirtualKubeletConfig, logsRequest // If after 5m they are not still available, the function errors out func RemoteExecution(ctx context.Context, config VirtualKubeletConfig, p *VirtualKubeletProvider, pod *v1.Pod, mode int8) error { - b, err := os.ReadFile(config.VKTokenFile) // just pass the file name - if err != nil { - log.G(ctx).Fatal(err) - return err + token := "" + if config.VKTokenFile != "" { + b, err := os.ReadFile(config.VKTokenFile) // just pass the file name + if err != nil { + log.G(ctx).Fatal(err) + return err + } + token = string(b) } - token := string(b) - switch mode { case CREATE: var req types.PodCreateRequests diff --git a/pkg/virtualkubelet/virtualkubelet.go b/pkg/virtualkubelet/virtualkubelet.go index 159ac9a7..aedb799e 100644 --- a/pkg/virtualkubelet/virtualkubelet.go +++ b/pkg/virtualkubelet/virtualkubelet.go @@ -160,6 +160,7 @@ func NewProvider(providerConfig, nodeName, nodeVersion, operatingSystem string, if err != nil { return nil, err } + log.G(ctx).Info("Init server with config:", config) return NewProviderConfig(config, nodeName, nodeVersion, operatingSystem, internalIP, daemonEndpointPort) } @@ -176,6 +177,7 @@ func LoadConfig(providerConfig, nodeName string, ctx context.Context) (config Vi err = yaml.Unmarshal(data, &config) if err != nil { + log.G(ctx).Fatal(err) return config, err } @@ -230,9 +232,11 @@ func (p *VirtualKubeletProvider) nodeUpdate(ctx context.Context) { log.G(ctx).Info("nodeLoop") - _, err := os.ReadFile(p.config.VKTokenFile) // just pass the file name - if err != nil { - log.G(context.Background()).Fatal(err) + if p.config.VKTokenFile != "" { + _, err := os.ReadFile(p.config.VKTokenFile) // just pass the file name + if err != nil { + log.G(context.Background()).Fatal(err) + } } for { @@ -703,11 +707,6 @@ func (p *VirtualKubeletProvider) statusLoop(ctx context.Context) { <-t.C } - _, err := os.ReadFile(p.config.VKTokenFile) // just pass the file name - if err != nil { - log.G(context.Background()).Fatal(err) - } - for { log.G(ctx).Info("statusLoop") t.Reset(5 * time.Second) @@ -717,16 +716,20 @@ func (p *VirtualKubeletProvider) statusLoop(ctx context.Context) { case <-t.C: } - b, err := os.ReadFile(p.config.VKTokenFile) // just pass the file name - if err != nil { - fmt.Print(err) + token := "" + if p.config.VKTokenFile != "" { + b, err := os.ReadFile(p.config.VKTokenFile) // just pass the file name + if err != nil { + fmt.Print(err) + } + token = string(b) } var podsList []*v1.Pod for _, pod := range p.pods { if pod.Status.Phase != "Initializing" { podsList = append(podsList, pod) - err = p.UpdatePod(ctx, pod) + err := p.UpdatePod(ctx, pod) if err != nil { log.G(ctx).Error(err) } @@ -734,7 +737,7 @@ func (p *VirtualKubeletProvider) statusLoop(ctx context.Context) { } if len(podsList) > 0 { - _, err = checkPodsStatus(ctx, p, podsList, string(b), p.config) + _, err := checkPodsStatus(ctx, p, podsList, token, p.config) if err != nil { log.G(ctx).Error(err) }