Skip to content

Commit

Permalink
Add separate handling for test operator with test
Browse files Browse the repository at this point in the history
Signed-off-by: Anshul Ahuja <anshulahuja@microsoft.com>
  • Loading branch information
Anshul Ahuja committed Jul 13, 2023
1 parent 16ec2db commit 7396e64
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
6 changes: 5 additions & 1 deletion internal/resourcemodifiers/resource_modifiers.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,11 @@ func ApplyPatch(patch []byte, obj *unstructured.Unstructured, log logrus.FieldLo
}
modifiedObjBytes, err := jsonPatch.Apply(objBytes)
if err != nil {
return fmt.Errorf("error in applying JSON Patch, could be due to test operator failing %s", err.Error())
if errors.Is(err, jsonpatch.ErrTestFailed) {
log.Infof("Test operation failed for JSON Patch %s", err.Error())
return nil
}
return fmt.Errorf("error in applying JSON Patch %s", err.Error())
}
err = obj.UnmarshalJSON(modifiedObjBytes)
if err != nil {
Expand Down
33 changes: 33 additions & 0 deletions internal/resourcemodifiers/resource_modifiers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,39 @@ func TestResourceModifiers_ApplyResourceModifierRules(t *testing.T) {
wantErr: false,
wantObj: deployNginxTwoReplica.DeepCopy(),
},
{
name: "nginx deployment: test operator fails, skips substitution, no error",
fields: fields{
Version: "v1",
ResourceModifierRules: []ResourceModifierRule{
{
Conditions: Conditions{
GroupKind: "deployments.apps",
ResourceNameRegex: "^test-.*$",
Namespaces: []string{"foo"},
},
Patches: []JSONPatch{
{
Operation: "test",
Path: "/spec/replicas",
Value: "5",
},
{
Operation: "replace",
Path: "/spec/replicas",
Value: "2",
},
},
},
},
},
args: args{
obj: deployNginxOneReplica.DeepCopy(),
groupResource: "deployments.apps",
},
wantErr: false,
wantObj: deployNginxOneReplica.DeepCopy(),
},
{
name: "nginx deployment: Empty Resource Regex",
fields: fields{
Expand Down

0 comments on commit 7396e64

Please sign in to comment.