diff --git a/controllers/client/openstackclient_controller.go b/controllers/client/openstackclient_controller.go index d8d2eafc1..5a009cef2 100644 --- a/controllers/client/openstackclient_controller.go +++ b/controllers/client/openstackclient_controller.go @@ -45,6 +45,7 @@ import ( "github.com/openstack-k8s-operators/lib-common/modules/common/configmap" "github.com/openstack-k8s-operators/lib-common/modules/common/env" helper "github.com/openstack-k8s-operators/lib-common/modules/common/helper" + "github.com/openstack-k8s-operators/lib-common/modules/common/labels" common_rbac "github.com/openstack-k8s-operators/lib-common/modules/common/rbac" "github.com/openstack-k8s-operators/lib-common/modules/common/tls" telemetryv1 "github.com/openstack-k8s-operators/telemetry-operator/api/v1beta1" @@ -307,17 +308,23 @@ func (r *OpenStackClientReconciler) Reconcile(ctx context.Context, req ctrl.Requ spec := openstackclient.ClientPodSpec(ctx, instance, helper, configVarsHash) + podSpecHash, err := util.ObjectHash(spec) + if err != nil { + return ctrl.Result{}, err + } + + podSpecAnnotation := labels.GetGroupLabel("openstackclient") + "/pod-spec-hash" + op, err := controllerutil.CreateOrPatch(ctx, r.Client, osclient, func() error { isPodUpdate := !osclient.ObjectMeta.CreationTimestamp.IsZero() - if !isPodUpdate { + currentPodSpecHash, hasPodSpecHash := osclient.Annotations[podSpecAnnotation] + if !isPodUpdate || (hasPodSpecHash && currentPodSpecHash != podSpecHash) { osclient.Spec = spec - } else { - osclient.Spec.Containers[0].Env = spec.Containers[0].Env - osclient.Spec.NodeSelector = spec.NodeSelector - osclient.Spec.Containers[0].Image = instance.Spec.ContainerImage } - osclient.Labels = util.MergeStringMaps(osclient.Labels, clientLabels) + osclient.Annotations = util.MergeStringMaps(map[string]string{ + podSpecAnnotation: podSpecHash, + }, osclient.Annotations) err = controllerutil.SetControllerReference(instance, osclient, r.Scheme) if err != nil {