Skip to content

Commit 8e42356

Browse files
authored
docs: add comment to the override examples (#1058)
1 parent 5f71e98 commit 8e42356

File tree

3 files changed

+74
-4
lines changed

3 files changed

+74
-4
lines changed

examples/test-cro1.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,9 @@ spec:
1919
env: canary
2020
jsonPatchOverrides:
2121
- op: add
22+
# Note: the override will fail if there are no labels on the resource.
23+
# To add a new label to an empty map or overwrite the existing labels, please use /metadata/labels.
24+
# Path: /metadata/labels
25+
# value: {"new-label": "new-value"}
2226
path: /metadata/labels/new-label
23-
value: "new-value"
27+
value: "new-value"

examples/test-ro1.yaml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ spec:
2424
test-key: test-value2
2525
jsonPatchOverrides:
2626
- op: add
27-
path: /metadata/labels
28-
value:
29-
new-label: new-value
27+
# Note: the override will fail if there are no labels on the resource.
28+
# To add a new label to an empty map or overwrite the existing labels, please use /metadata/labels.
29+
# Path: /metadata/labels
30+
# value: {"new-label": "new-value"}
31+
path: /metadata/labels/new-label
32+
value: "new-value"

pkg/controllers/workgenerator/override_test.go

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2114,6 +2114,68 @@ func TestApplyJSONPatchOverride(t *testing.T) {
21142114
},
21152115
},
21162116
},
2117+
{
2118+
name: "reset the labels using add operation",
2119+
deployment: appsv1.Deployment{
2120+
TypeMeta: deploymentType,
2121+
ObjectMeta: metav1.ObjectMeta{
2122+
Name: "deployment-name",
2123+
Namespace: "deployment-namespace",
2124+
Labels: map[string]string{
2125+
"app": "nginx-1",
2126+
"key": "value",
2127+
},
2128+
},
2129+
},
2130+
overrides: []placementv1alpha1.JSONPatchOverride{
2131+
{
2132+
Operator: placementv1alpha1.JSONPatchOverrideOpAdd,
2133+
Path: "/metadata/labels",
2134+
Value: apiextensionsv1.JSON{Raw: []byte(`{"app": "nginx"}`)},
2135+
},
2136+
},
2137+
wantDeployment: appsv1.Deployment{
2138+
TypeMeta: deploymentType,
2139+
ObjectMeta: metav1.ObjectMeta{
2140+
Name: "deployment-name",
2141+
Namespace: "deployment-namespace",
2142+
Labels: map[string]string{
2143+
"app": "nginx",
2144+
},
2145+
},
2146+
},
2147+
},
2148+
{
2149+
name: "reset the labels using replace operation",
2150+
deployment: appsv1.Deployment{
2151+
TypeMeta: deploymentType,
2152+
ObjectMeta: metav1.ObjectMeta{
2153+
Name: "deployment-name",
2154+
Namespace: "deployment-namespace",
2155+
Labels: map[string]string{
2156+
"app": "nginx-1",
2157+
"key": "value",
2158+
},
2159+
},
2160+
},
2161+
overrides: []placementv1alpha1.JSONPatchOverride{
2162+
{
2163+
Operator: placementv1alpha1.JSONPatchOverrideOpReplace,
2164+
Path: "/metadata/labels",
2165+
Value: apiextensionsv1.JSON{Raw: []byte(`{"app": "nginx"}`)},
2166+
},
2167+
},
2168+
wantDeployment: appsv1.Deployment{
2169+
TypeMeta: deploymentType,
2170+
ObjectMeta: metav1.ObjectMeta{
2171+
Name: "deployment-name",
2172+
Namespace: "deployment-namespace",
2173+
Labels: map[string]string{
2174+
"app": "nginx",
2175+
},
2176+
},
2177+
},
2178+
},
21172179
{
21182180
name: "add the first label key value",
21192181
deployment: appsv1.Deployment{
@@ -2125,6 +2187,7 @@ func TestApplyJSONPatchOverride(t *testing.T) {
21252187
},
21262188
overrides: []placementv1alpha1.JSONPatchOverride{
21272189
{
2190+
// To add the first key, it cannot use "replace" as the path is missing.
21282191
Operator: placementv1alpha1.JSONPatchOverrideOpAdd,
21292192
Path: "/metadata/labels",
21302193
Value: apiextensionsv1.JSON{Raw: []byte(`{"app": "nginx"}`)},

0 commit comments

Comments
 (0)