Skip to content

Commit

Permalink
Only update osc pod when pod spec changes
Browse files Browse the repository at this point in the history
  • Loading branch information
olliewalsh committed Nov 28, 2024
1 parent 1e3929e commit fba9c3a
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion controllers/client/openstackclient_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit fba9c3a

Please sign in to comment.