Skip to content

Commit

Permalink
fix: change deployment image reconciling
Browse files Browse the repository at this point in the history
  • Loading branch information
ultram4rine committed Feb 16, 2024
1 parent 807a318 commit 4114316
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions controllers/k8sgpt_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,14 +169,17 @@ func (r *K8sGPTReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr
imageURI := deployment.Spec.Template.Spec.Containers[0].Image

image := strings.Split(imageURI, ":")
imageRepository := image[0]
imageVersion := image[1]
imageRepository := strings.Join(image[0:len(image)-1], ":")
imageVersion := image[len(image)-1]

// if one of repository or tag is changed, we need to update the deployment
if imageRepository != k8sgptConfig.Spec.Repository || imageVersion != k8sgptConfig.Spec.Version {
// Update the deployment image
deployment.Spec.Template.Spec.Containers[0].Image = fmt.Sprintf("%s:%s",
imageRepository, k8sgptConfig.Spec.Version)
deployment.Spec.Template.Spec.Containers[0].Image = fmt.Sprintf(
"%s:%s",
k8sgptConfig.Spec.Repository,
k8sgptConfig.Spec.Version,
)
err = r.Update(ctx, &deployment)
if err != nil {
k8sgptReconcileErrorCount.Inc()
Expand Down

0 comments on commit 4114316

Please sign in to comment.