From fba9c3ac5482510dc2779cd5b06f78ee5a978821 Mon Sep 17 00:00:00 2001 From: Oliver Walsh Date: Thu, 28 Nov 2024 18:42:01 +0000 Subject: [PATCH] Only update osc pod when pod spec changes --- controllers/client/openstackclient_controller.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/controllers/client/openstackclient_controller.go b/controllers/client/openstackclient_controller.go index d8d2eafc1..961ba661b 100644 --- a/controllers/client/openstackclient_controller.go +++ b/controllers/client/openstackclient_controller.go @@ -307,17 +307,23 @@ func (r *OpenStackClientReconciler) Reconcile(ctx context.Context, req ctrl.Requ spec := openstackclient.ClientPodSpec(ctx, instance, helper, configVarsHash) + podTemplateHash, err := util.ObjectHash(spec) + if err != nil { + return ctrl.Result{}, err + } + op, err := controllerutil.CreateOrPatch(ctx, r.Client, osclient, func() error { isPodUpdate := !osclient.ObjectMeta.CreationTimestamp.IsZero() if !isPodUpdate { osclient.Spec = spec - } else { + } else if osclient.Annotations["pod-spec-hash"] != podTemplateHash { 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{"pod-spec-hash": podTemplateHash}, osclient.Annotations) err = controllerutil.SetControllerReference(instance, osclient, r.Scheme) if err != nil {