Skip to content

Commit

Permalink
Merge pull request #410 from kubeslice/hotfix-gw-deploy
Browse files Browse the repository at this point in the history
fix(): update gw deploy if gateway sidecar image changed
  • Loading branch information
mridulgain authored Nov 6, 2024
2 parents 7015e35 + b64baf1 commit 83e5ade
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
##########################################################

# Build the manager binary
FROM golang:1.22.1 as builder
FROM golang:1.23.2 AS builder

WORKDIR /workspace
# Copy the Go Modules manifests
Expand Down
32 changes: 31 additions & 1 deletion controllers/slicegateway/slicegateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ import (
webhook "github.com/kubeslice/worker-operator/pkg/webhook/pod"
)

const (
DEFAULT_SIDECAR_IMG = "nexus.dev.aveshalabs.io/kubeslice/gw-sidecar:1.0.0"
)

var (
vpnClientFileName = "openvpn_client.ovpn"
gwSidecarImage = os.Getenv("AVESHA_GW_SIDECAR_IMAGE")
Expand Down Expand Up @@ -110,7 +114,7 @@ func (r *SliceGwReconciler) deploymentForGatewayServer(g *kubeslicev1beta1.Slice

var privileged = true

sidecarImg := "nexus.dev.aveshalabs.io/kubeslice/gw-sidecar:1.0.0"
sidecarImg := DEFAULT_SIDECAR_IMG
sidecarPullPolicy := corev1.PullAlways
vpnImg := "nexus.dev.aveshalabs.io/kubeslice/openvpn-server.ubuntu.18.04:1.0.0"
vpnPullPolicy := corev1.PullAlways
Expand Down Expand Up @@ -1376,6 +1380,11 @@ func (r *SliceGwReconciler) ReconcileGatewayDeployments(ctx context.Context, sli
}
}

sidecarImg := DEFAULT_SIDECAR_IMG
if len(gwSidecarImage) != 0 {
sidecarImg = gwSidecarImage
}

for gwInstance := 0; gwInstance < numGwInstances; gwInstance++ {
if !gwDeploymentIsPresent(sliceGwName, gwInstance, deployments) {
dep := r.deploymentForGateway(sliceGw, sliceGwName+"-"+fmt.Sprint(gwInstance)+"-"+"0", gwConfigKey)
Expand All @@ -1386,6 +1395,27 @@ func (r *SliceGwReconciler) ReconcileGatewayDeployments(ctx context.Context, sli
return ctrl.Result{}, err, true
}
return ctrl.Result{Requeue: true}, nil, true
} else {
// update logic for gateways
for i := range deployments.Items {
deployment := &deployments.Items[i]
if deployment.Name == sliceGwName+"-"+fmt.Sprint(gwInstance)+"-"+"0" {
// update if gateway sidecar image has been changed in worker env vars
for j := range deployment.Spec.Template.Spec.Containers {
container := &deployment.Spec.Template.Spec.Containers[j]
if container.Name == "kubeslice-sidecar" && container.Image != sidecarImg {
container.Image = sidecarImg
log.Info("updating gw Deployment sidecar", "Name", deployment.Name, "image", gwSidecarImage)
err = r.Update(ctx, deployment)
if err != nil {
log.Error(err, "Failed to update Deployment", "Name", deployment.Name)
return ctrl.Result{}, err, true
}
return ctrl.Result{Requeue: true}, nil, true
}
}
}
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/kubeslice/worker-operator

go 1.22.1
go 1.23.2

// replace github.com/kubeslice/apis => ../../misc/apis

Expand Down
2 changes: 1 addition & 1 deletion test.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.22.3 as builder
FROM golang:1.23.2 AS builder

WORKDIR /workspace
# Copy the Go Modules manifests
Expand Down

0 comments on commit 83e5ade

Please sign in to comment.