diff --git a/changelogs/unreleased/7410-seanblong b/changelogs/unreleased/7410-seanblong new file mode 100644 index 0000000000..ffc340d2bc --- /dev/null +++ b/changelogs/unreleased/7410-seanblong @@ -0,0 +1 @@ +Ignore missing path error in conditional match diff --git a/internal/resourcemodifiers/resource_modifiers.go b/internal/resourcemodifiers/resource_modifiers.go index d4ae93e717..2546e0d664 100644 --- a/internal/resourcemodifiers/resource_modifiers.go +++ b/internal/resourcemodifiers/resource_modifiers.go @@ -172,7 +172,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 diff --git a/internal/resourcemodifiers/resource_modifiers_test.go b/internal/resourcemodifiers/resource_modifiers_test.go index 648d827be9..c6563c2e6f 100644 --- a/internal/resourcemodifiers/resource_modifiers_test.go +++ b/internal/resourcemodifiers/resource_modifiers_test.go @@ -1650,6 +1650,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 {