Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion examples/test-cro1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,9 @@ spec:
env: canary
jsonPatchOverrides:
- op: add
# Note: the override will fail if there are no labels on the resource.
# To add a new label to an empty map or overwrite the existing labels, please use /metadata/labels.
# Path: /metadata/labels
# value: {"new-label": "new-value"}
path: /metadata/labels/new-label
value: "new-value"
value: "new-value"
9 changes: 6 additions & 3 deletions examples/test-ro1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ spec:
test-key: test-value2
jsonPatchOverrides:
- op: add
path: /metadata/labels
value:
new-label: new-value
# Note: the override will fail if there are no labels on the resource.
# To add a new label to an empty map or overwrite the existing labels, please use /metadata/labels.
# Path: /metadata/labels
# value: {"new-label": "new-value"}
path: /metadata/labels/new-label
value: "new-value"
63 changes: 63 additions & 0 deletions pkg/controllers/workgenerator/override_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2114,6 +2114,68 @@ func TestApplyJSONPatchOverride(t *testing.T) {
},
},
},
{
name: "reset the labels using add operation",
deployment: appsv1.Deployment{
TypeMeta: deploymentType,
ObjectMeta: metav1.ObjectMeta{
Name: "deployment-name",
Namespace: "deployment-namespace",
Labels: map[string]string{
"app": "nginx-1",
"key": "value",
},
},
},
overrides: []placementv1alpha1.JSONPatchOverride{
{
Operator: placementv1alpha1.JSONPatchOverrideOpAdd,
Path: "/metadata/labels",
Value: apiextensionsv1.JSON{Raw: []byte(`{"app": "nginx"}`)},
},
},
wantDeployment: appsv1.Deployment{
TypeMeta: deploymentType,
ObjectMeta: metav1.ObjectMeta{
Name: "deployment-name",
Namespace: "deployment-namespace",
Labels: map[string]string{
"app": "nginx",
},
},
},
},
{
name: "reset the labels using replace operation",
deployment: appsv1.Deployment{
TypeMeta: deploymentType,
ObjectMeta: metav1.ObjectMeta{
Name: "deployment-name",
Namespace: "deployment-namespace",
Labels: map[string]string{
"app": "nginx-1",
"key": "value",
},
},
},
overrides: []placementv1alpha1.JSONPatchOverride{
{
Operator: placementv1alpha1.JSONPatchOverrideOpReplace,
Path: "/metadata/labels",
Value: apiextensionsv1.JSON{Raw: []byte(`{"app": "nginx"}`)},
},
},
wantDeployment: appsv1.Deployment{
TypeMeta: deploymentType,
ObjectMeta: metav1.ObjectMeta{
Name: "deployment-name",
Namespace: "deployment-namespace",
Labels: map[string]string{
"app": "nginx",
},
},
},
},
{
name: "add the first label key value",
deployment: appsv1.Deployment{
Expand All @@ -2125,6 +2187,7 @@ func TestApplyJSONPatchOverride(t *testing.T) {
},
overrides: []placementv1alpha1.JSONPatchOverride{
{
// To add the first key, it cannot use "replace" as the path is missing.
Operator: placementv1alpha1.JSONPatchOverrideOpAdd,
Path: "/metadata/labels",
Value: apiextensionsv1.JSON{Raw: []byte(`{"app": "nginx"}`)},
Expand Down
Loading