Skip to content

Commit

Permalink
Use mergepatch for PDB (#584)
Browse files Browse the repository at this point in the history
Signed-off-by: Tamal Saha <[email protected]>
  • Loading branch information
tamalsaha authored May 7, 2024
1 parent b23cf43 commit d7b7b9e
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions policy/v1/pdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ package v1
import (
"context"

jsonpatch "github.com/evanphx/json-patch"
"github.com/pkg/errors"
policy "k8s.io/api/policy/v1"
kerr "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/strategicpatch"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/kubernetes"
"k8s.io/klog/v2"
Expand Down Expand Up @@ -67,15 +67,15 @@ func PatchPodDisruptionBudgetObject(ctx context.Context, c kubernetes.Interface,
return nil, kutil.VerbUnchanged, err
}

patch, err := strategicpatch.CreateTwoWayMergePatch(curJson, modJson, policy.PodDisruptionBudget{})
patch, err := jsonpatch.CreateMergePatch(curJson, modJson)
if err != nil {
return nil, kutil.VerbUnchanged, err
}
if len(patch) == 0 || string(patch) == "{}" {
return cur, kutil.VerbUnchanged, nil
}
klog.V(3).Infof("Patching PodDisruptionBudget %s with %s.", cur.Name, string(patch))
out, err := c.PolicyV1().PodDisruptionBudgets(cur.Namespace).Patch(ctx, cur.Name, types.StrategicMergePatchType, patch, opts)
out, err := c.PolicyV1().PodDisruptionBudgets(cur.Namespace).Patch(ctx, cur.Name, types.MergePatchType, patch, opts)
return out, kutil.VerbPatched, err
}

Expand Down

0 comments on commit d7b7b9e

Please sign in to comment.