Skip to content

Commit

Permalink
Hack to allow PDBs to progress (#246)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
AYM1607 and Mariano Uvalle authored Nov 14, 2024
1 parent 7546c62 commit 0f5de0a
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion internal/controllers/reconciliation/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 0f5de0a

Please sign in to comment.