From 0f5de0aa612c59dccb55b6da3cc7c8e1c10de0a3 Mon Sep 17 00:00:00 2001 From: Mariano Uvalle Date: Thu, 14 Nov 2024 10:39:38 -0800 Subject: [PATCH] Hack to allow PDBs to progress (#246) This is needed because the label selector field on the [PDB spec](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.31/#poddisruptionbudgetspec-v1-policy) has a patch strategy of "replace" meaning that the computed patch will never be empty even if the objects are the same, meaning that we'll never mark the resource as reconciled. --------- Co-authored-by: Mariano Uvalle --- internal/controllers/reconciliation/controller.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/internal/controllers/reconciliation/controller.go b/internal/controllers/reconciliation/controller.go index 00c3b5c4..a9b6a28f 100644 --- a/internal/controllers/reconciliation/controller.go +++ b/internal/controllers/reconciliation/controller.go @@ -12,6 +12,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/util/jsonmergepatch" "k8s.io/apimachinery/pkg/util/strategicpatch" @@ -333,7 +334,11 @@ func (c *Controller) buildPatch(ctx context.Context, prev, next *reconstitution. if err != nil { return nil, "", fmt.Errorf("getting merge metadata: %w", err) } - if model == nil { + + // FIXME: This is a very nasty hack which should not be needed once we have + // support for semantic equality checks. + pdbGVK := schema.GroupVersionKind{Group: "policy", Version: "v1", Kind: "PodDisruptionBudget"} + if model == nil || (next != nil && next.GVK == pdbGVK) { patch, err := jsonmergepatch.CreateThreeWayJSONMergePatch(prevJS, nextJS, currentJS) if err != nil { return nil, "", reconcile.TerminalError(err)