Merge pull request #7410 from seanblong/main

Ignore missing path error in conditional match
This commit is contained in:
Xun Jiang/Bruce Jiang
2024-07-04 10:10:53 +08:00
committed by GitHub
3 changed files with 31 additions and 1 deletions

View File

@@ -181,7 +181,7 @@ func matchConditions(u *unstructured.Unstructured, rules []MatchRule, _ logrus.F
p := &JSONPatcher{patches: fixed}
_, err := p.applyPatch(u)
if err != nil {
if errors.Is(err, jsonpatch.ErrTestFailed) {
if errors.Is(err, jsonpatch.ErrTestFailed) || errors.Is(err, jsonpatch.ErrMissing) {
return false, nil
}
return false, err

View File

@@ -1767,6 +1767,35 @@ func TestResourceModifiers_conditional_patches(t *testing.T) {
wantErr: false,
wantObj: cmWithLabelAToB.DeepCopy(),
},
{
name: "missing condition path and skip patches",
rm: &ResourceModifiers{
Version: "v1",
ResourceModifierRules: []ResourceModifierRule{
{
Conditions: Conditions{
GroupResource: "*",
Namespaces: []string{"fake"},
Matches: []MatchRule{
{
Path: "/metadata/labels/a/b",
Value: "c",
},
},
},
MergePatches: []JSONMergePatch{
{
PatchData: `{"metadata":{"labels":{"a":"c"}}}`,
},
},
},
},
},
obj: cmWithLabelAToB.DeepCopy(),
groupResource: "configmaps",
wantErr: false,
wantObj: cmWithLabelAToB.DeepCopy(),
},
}
for _, tt := range tests {