Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: change deployment image reconciling #348

Merged
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions controllers/k8sgpt_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,18 +179,21 @@ func (r *K8sGPTReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr

if deployment.Status.ReadyReplicas > 0 {

// Check the version of the deployment image matches the version set in the K8sGPT CR
// Check the repo and version of the deployment image matches the repo and version set in the K8sGPT CR
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], ":")
arbreezy marked this conversation as resolved.
Show resolved Hide resolved
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,
arbreezy marked this conversation as resolved.
Show resolved Hide resolved
k8sgptConfig.Spec.Version,
)
err = r.Update(ctx, &deployment)
if err != nil {
k8sgptReconcileErrorCount.With(prometheus.Labels{
Expand Down