Skip to content

Commit

Permalink
Merge pull request #237 from dciangot/version
Browse files Browse the repository at this point in the history
Versioning virtual node and disable jaeger
  • Loading branch information
dciangot authored Jun 22, 2024
2 parents 4156437 + a123cf0 commit ab9ba24
Show file tree
Hide file tree
Showing 11 changed files with 88 additions and 24 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/build_images.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion ci/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
17 changes: 17 additions & 0 deletions ci/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"context"
"fmt"
"html/template"
"strings"

"dagger/interlink/internal/dagger"
)
Expand Down Expand Up @@ -78,16 +79,32 @@ 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 {
return nil, err
}

_, 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",
}).
Expand Down
2 changes: 0 additions & 2 deletions ci/manifests/virtual-kubelet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
35 changes: 23 additions & 12 deletions cmd/virtual-kubelet/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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"),
Expand Down Expand Up @@ -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)
Expand Down
11 changes: 11 additions & 0 deletions cmd/virtual-kubelet/set-version.sh
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions docker/Dockerfile.interlink
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions docker/Dockerfile.vk
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions pkg/virtualkubelet/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package virtualkubelet

var (
KubeletVersion = "test"
)
17 changes: 8 additions & 9 deletions pkg/virtualkubelet/virtualkubelet.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ type VirtualKubeletProvider struct {
func NewProviderConfig(
config VirtualKubeletConfig,
nodeName string,
nodeVersion string,
operatingSystem string,
internalIP string,
daemonEndpointPort int32,
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit ab9ba24

Please sign in to comment.