diff --git a/.github/workflows/build_images.yaml b/.github/workflows/build_images.yaml index 0ae56eed..058fda16 100644 --- a/.github/workflows/build_images.yaml +++ b/.github/workflows/build_images.yaml @@ -39,6 +39,8 @@ jobs: ghcr.io/${{ steps.get_repo_owner.outputs.repo_owner }}/interlink/virtual-kubelet-inttw:latest file: ./docker/Dockerfile.vk platforms: linux/amd64, linux/arm64 + build-args: + - VERSION=${{ env.RELEASE_VERSION }} - name: Build container base image interlink uses: docker/build-push-action@v5 with: diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 7667d0a1..f25ebe14 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -7,6 +7,8 @@ before: builds: - id: "virtual-kubelet" binary: virtual-kubelet + hooks: + pre: bash -c "KUBELET_VERSION={{.Version}} ./cmd/virtual-kubelet/set-version.sh" env: - CGO_ENABLED=0 goos: diff --git a/ci/k8s.go b/ci/k8s.go index fec9b2ca..a683d909 100644 --- a/ci/k8s.go +++ b/ci/k8s.go @@ -203,7 +203,7 @@ func (k *K8sInstance) waitForVirtualKubelet(ctx context.Context) (err error) { fmt.Println(fmt.Errorf("could not fetch pod: %v", err)) continue } - if strings.Contains(kubectlGetPod, "2/2") { + if strings.Contains(kubectlGetPod, "1/1") || strings.Contains(kubectlGetPod, "2/2") { return nil } fmt.Println("waiting for k8s to start:", kubectlGetPod) diff --git a/ci/main.go b/ci/main.go index ee3a3bbb..3040e2ef 100644 --- a/ci/main.go +++ b/ci/main.go @@ -5,6 +5,7 @@ import ( "context" "fmt" "html/template" + "strings" "dagger/interlink/internal/dagger" ) @@ -78,9 +79,23 @@ func (i *Interlink) BuildImages( WithWorkdir("/src"). Directory("/src") + vkVersionSplits := strings.Split(virtualKubeletRef, ":") + + vkVersion := vkVersionSplits[len(vkVersionSplits)-1] + if vkVersion == "" { + return nil, fmt.Errorf("no tag specified on the image for VK") + } + + modulesCache := dag.CacheVolume("go-mod-122") + _, err := dag.Container(). + WithMountedCache("/go/pkg/mod", modulesCache). + WithMountedCache("/go/build-cache", dag.CacheVolume("go-build-122")). Build(workspace, dagger.ContainerBuildOpts{ Dockerfile: "docker/Dockerfile.vk", + BuildArgs: []dagger.BuildArg{ + {"VERSION", vkVersion}, + }, }). Publish(ctx, virtualKubeletRef) if err != nil { @@ -88,6 +103,8 @@ func (i *Interlink) BuildImages( } _, err = dag.Container(). + WithMountedCache("/go/pkg/mod", modulesCache). + WithMountedCache("/go/build-cache", dag.CacheVolume("go-build-122")). Build(workspace, dagger.ContainerBuildOpts{ Dockerfile: "docker/Dockerfile.interlink", }). diff --git a/ci/manifests/virtual-kubelet.yaml b/ci/manifests/virtual-kubelet.yaml index 57d07b0e..51b34a88 100644 --- a/ci/manifests/virtual-kubelet.yaml +++ b/ci/manifests/virtual-kubelet.yaml @@ -36,8 +36,6 @@ spec: - name: config mountPath: /etc/interlink/InterLinkConfig.yaml subPath: InterLinkConfig.yaml - - name: jaeger - image: jaegertracing/all-in-one:1.51 volumes: - name: config configMap: diff --git a/cmd/virtual-kubelet/main.go b/cmd/virtual-kubelet/main.go index bb83c5d7..fe5919ab 100644 --- a/cmd/virtual-kubelet/main.go +++ b/cmd/virtual-kubelet/main.go @@ -75,6 +75,7 @@ func PodInformerFilter(node string) informers.SharedInformerOption { type Config struct { ConfigPath string NodeName string + NodeVersion string OperatingSystem string InternalIP string DaemonPort int32 @@ -191,20 +192,22 @@ func main() { } log.L = logruslogger.FromLogrus(logrus.NewEntry(logger)) - shutdown, err := initProvider() - if err != nil { - log.G(ctx).Fatal(err) - } - defer func() { - if err = shutdown(ctx); err != nil { - log.G(ctx).Fatal("failed to shutdown TracerProvider: %w", err) + if os.Getenv("ENABLE_TRACING") == "1" { + shutdown, err := initProvider() + if err != nil { + log.G(ctx).Fatal(err) } - }() + defer func() { + if err = shutdown(ctx); err != nil { + log.G(ctx).Fatal("failed to shutdown TracerProvider: %w", err) + } + }() - log.G(ctx).Info("Tracer setup succeeded") + log.G(ctx).Info("Tracer setup succeeded") - // TODO: disable this through options - trace.T = opentelemetry.Adapter{} + // TODO: disable this through options + trace.T = opentelemetry.Adapter{} + } // TODO: if token specified http.DefaultClient = ... // and remove reading from file @@ -219,6 +222,7 @@ func main() { cfg := Config{ ConfigPath: configpath, NodeName: nodename, + NodeVersion: commonIL.KubeletVersion, OperatingSystem: "Linux", // https://github.com/liqotech/liqo/blob/d8798732002abb7452c2ff1c99b3e5098f848c93/deployments/liqo/templates/liqo-gateway-deployment.yaml#L69 InternalIP: os.Getenv("POD_IP"), @@ -251,7 +255,14 @@ func main() { localClient := kubernetes.NewForConfigOrDie(kubecfg) - nodeProvider, err := commonIL.NewProvider(cfg.ConfigPath, cfg.NodeName, cfg.OperatingSystem, cfg.InternalIP, cfg.DaemonPort, ctx) + nodeProvider, err := commonIL.NewProvider( + cfg.ConfigPath, + cfg.NodeName, + cfg.NodeVersion, + cfg.OperatingSystem, + cfg.InternalIP, + cfg.DaemonPort, + ctx) if err != nil { log.G(ctx).Fatal(err) diff --git a/cmd/virtual-kubelet/set-version.sh b/cmd/virtual-kubelet/set-version.sh new file mode 100755 index 00000000..9af21950 --- /dev/null +++ b/cmd/virtual-kubelet/set-version.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +if [ -z ${KUBELET_VERSION} ]; then +cat << EOF > pkg/virtualkubelet/version.go +package main + +var ( + kubeletVersion = "$KUBELET_VERSION" +) +EOF +fi diff --git a/docker/Dockerfile.interlink b/docker/Dockerfile.interlink index fc6ff327..a81767ee 100644 --- a/docker/Dockerfile.interlink +++ b/docker/Dockerfile.interlink @@ -4,6 +4,14 @@ WORKDIR /app COPY .. . +ENV GOMODCACHE="/go/pkg/mod" + +ENV GOCACHE="/go/build-cache" + +RUN mkdir -p $GOMODCACHE && mkdir -p $GOCACHE + + +RUN go mod tidy RUN CGO_ENABLED=0 GOOS=linux go build -o bin/interlink # Deploy the application binary into a lean image diff --git a/docker/Dockerfile.vk b/docker/Dockerfile.vk index 722637ae..9a455a24 100644 --- a/docker/Dockerfile.vk +++ b/docker/Dockerfile.vk @@ -6,6 +6,17 @@ WORKDIR /app COPY .. . +ARG VERSION +ENV KUBELET_VERSION=${VERSION} + +ENV GOMODCACHE="/go/pkg/mod" +ENV GOCACHE="/go/build-cache" + +RUN mkdir -p $GOMODCACHE && mkdir -p $GOCACHE + + +RUN bash -c "./cmd/virtual-kubelet/set-version.sh" +RUN go mod tidy RUN CGO_ENABLED=0 GOOS=linux go build -o bin/vk cmd/virtual-kubelet/main.go # Deploy the application binary into a lean image diff --git a/pkg/virtualkubelet/version.go b/pkg/virtualkubelet/version.go new file mode 100644 index 00000000..db339a26 --- /dev/null +++ b/pkg/virtualkubelet/version.go @@ -0,0 +1,5 @@ +package virtualkubelet + +var ( + KubeletVersion = "test" +) diff --git a/pkg/virtualkubelet/virtualkubelet.go b/pkg/virtualkubelet/virtualkubelet.go index cfb838cd..f168fa68 100644 --- a/pkg/virtualkubelet/virtualkubelet.go +++ b/pkg/virtualkubelet/virtualkubelet.go @@ -72,6 +72,7 @@ type VirtualKubeletProvider struct { func NewProviderConfig( config VirtualKubeletConfig, nodeName string, + nodeVersion string, operatingSystem string, internalIP string, daemonEndpointPort int32, @@ -114,13 +115,11 @@ func NewProviderConfig( }}, }, Status: v1.NodeStatus{ - // TODO: set kubelet version! - - // NodeInfo: v1.NodeSystemInfo{ - // KubeletVersion: Version, - // Architecture: architecture, - // OperatingSystem: linuxos, - // }, + NodeInfo: v1.NodeSystemInfo{ + KubeletVersion: nodeVersion, + Architecture: "virtual-kubelet", + OperatingSystem: "linux", + }, Addresses: []v1.NodeAddress{{Type: v1.NodeInternalIP, Address: internalIP}}, DaemonEndpoints: v1.NodeDaemonEndpoints{KubeletEndpoint: v1.DaemonEndpoint{Port: int32(daemonEndpointPort)}}, Capacity: v1.ResourceList{ @@ -154,12 +153,12 @@ func NewProviderConfig( } // NewProvider creates a new Provider, which implements the PodNotifier and other virtual-kubelet interfaces -func NewProvider(providerConfig, nodeName, operatingSystem string, internalIP string, daemonEndpointPort int32, ctx context.Context) (*VirtualKubeletProvider, error) { +func NewProvider(providerConfig, nodeName, nodeVersion, operatingSystem string, internalIP string, daemonEndpointPort int32, ctx context.Context) (*VirtualKubeletProvider, error) { config, err := LoadConfig(providerConfig, nodeName, ctx) if err != nil { return nil, err } - return NewProviderConfig(config, nodeName, operatingSystem, internalIP, daemonEndpointPort) + return NewProviderConfig(config, nodeName, nodeVersion, operatingSystem, internalIP, daemonEndpointPort) } // LoadConfig loads the given json configuration files and return a VirtualKubeletConfig struct