Skip to content

Commit 890b27c

Browse files
committed
Add overrides test cases for patch directives
Signed-off-by: Angel Misevski <[email protected]>
1 parent b18b386 commit 890b27c

8 files changed

+221
-14
lines changed

pkg/library/overrides/testdata/container-overrides/container-cannot-set-restricted-fields.yaml

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,4 @@ input:
3636

3737

3838
output:
39-
container:
40-
name: test-component
41-
image: test-image
42-
command: ["original"]
43-
args: ["original"]
44-
ports:
45-
- name: original-port
46-
containerPort: 8080
47-
volumeMounts:
48-
- name: original-volume
49-
mountPath: original-mountPath
50-
env:
51-
- name: original_env
52-
value: original_val
39+
errRegexp: "cannot use container-overrides to override container env"
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: "container overrides can override securityContext"
2+
3+
input:
4+
component:
5+
name: test-component
6+
attributes:
7+
container-overrides:
8+
securityContext:
9+
runAsUser: 1001
10+
container:
11+
image: test-image
12+
13+
container:
14+
name: test-component
15+
image: test-image
16+
securityContext:
17+
runAsUser: 1000
18+
runAsGroup: 2000
19+
20+
output:
21+
container:
22+
name: test-component
23+
image: test-image
24+
securityContext:
25+
runAsUser: 1001
26+
runAsGroup: 2000
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: "container overrides can use $patch: delete to delete fields rather than merging"
2+
3+
input:
4+
component:
5+
name: test-component
6+
attributes:
7+
container-overrides:
8+
securityContext:
9+
$patch: delete
10+
container:
11+
image: test-image
12+
13+
container:
14+
name: test-component
15+
image: test-image
16+
securityContext:
17+
runAsUser: 1000
18+
runAsGroup: 2000
19+
20+
output:
21+
container:
22+
name: test-component
23+
image: test-image
24+
securityContext: {}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: "container overrides can use $patch: replace to overwrite fields rather than merging"
2+
3+
input:
4+
component:
5+
name: test-component
6+
attributes:
7+
container-overrides:
8+
securityContext:
9+
runAsUser: 1001
10+
$patch: replace
11+
container:
12+
image: test-image
13+
14+
container:
15+
name: test-component
16+
image: test-image
17+
securityContext:
18+
runAsUser: 1000
19+
runAsGroup: 2000
20+
21+
output:
22+
container:
23+
name: test-component
24+
image: test-image
25+
securityContext:
26+
runAsUser: 1001
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: "Returns error when attempting to patch pod volumes"
2+
3+
input:
4+
workspace:
5+
attributes:
6+
pod-overrides:
7+
spec:
8+
volumes:
9+
- name: test-volume
10+
components:
11+
- name: test-component
12+
container:
13+
image: test-image
14+
15+
podTemplateSpec:
16+
metadata:
17+
labels:
18+
controller.devfile.io/devworkspace-id: test-id
19+
spec:
20+
containers:
21+
- name: test-component
22+
image: test-image
23+
24+
output:
25+
errRegexp: "cannot use pod-overrides to override pod volumes"
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: "Pod overrides can override securityContext"
2+
3+
input:
4+
workspace:
5+
attributes:
6+
pod-overrides:
7+
spec:
8+
securityContext:
9+
runAsUser: 1001
10+
components:
11+
- name: test-component
12+
container:
13+
image: test-image
14+
15+
podTemplateSpec:
16+
metadata:
17+
labels:
18+
controller.devfile.io/devworkspace-id: test-id
19+
spec:
20+
containers:
21+
- name: test-component
22+
image: test-image
23+
securityContext:
24+
fsGroup: 2000
25+
runAsGroup: 3000
26+
runAsUser: 1000
27+
28+
29+
output:
30+
podTemplateSpec:
31+
metadata:
32+
labels:
33+
controller.devfile.io/devworkspace-id: test-id
34+
spec:
35+
containers:
36+
- name: test-component
37+
image: test-image
38+
securityContext:
39+
fsGroup: 2000
40+
runAsGroup: 3000
41+
runAsUser: 1001
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: "Pod overrides can use $patch: delete to delete fields rather than merging"
2+
3+
input:
4+
workspace:
5+
attributes:
6+
pod-overrides:
7+
spec:
8+
securityContext:
9+
$patch: delete
10+
components:
11+
- name: test-component
12+
container:
13+
image: test-image
14+
15+
podTemplateSpec:
16+
metadata:
17+
labels:
18+
controller.devfile.io/devworkspace-id: test-id
19+
spec:
20+
containers:
21+
- name: test-component
22+
image: test-image
23+
securityContext:
24+
fsGroup: 2000
25+
runAsGroup: 3000
26+
runAsUser: 1000
27+
28+
29+
output:
30+
podTemplateSpec:
31+
metadata:
32+
labels:
33+
controller.devfile.io/devworkspace-id: test-id
34+
spec:
35+
containers:
36+
- name: test-component
37+
image: test-image
38+
securityContext: {}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: "Pod overrides can use $patch: replace to overwrite fields rather than merging"
2+
3+
input:
4+
workspace:
5+
attributes:
6+
pod-overrides:
7+
spec:
8+
securityContext:
9+
runAsUser: 1001
10+
$patch: replace
11+
components:
12+
- name: test-component
13+
container:
14+
image: test-image
15+
16+
podTemplateSpec:
17+
metadata:
18+
labels:
19+
controller.devfile.io/devworkspace-id: test-id
20+
spec:
21+
containers:
22+
- name: test-component
23+
image: test-image
24+
securityContext:
25+
fsGroup: 2000
26+
runAsGroup: 3000
27+
runAsUser: 1000
28+
29+
30+
output:
31+
podTemplateSpec:
32+
metadata:
33+
labels:
34+
controller.devfile.io/devworkspace-id: test-id
35+
spec:
36+
containers:
37+
- name: test-component
38+
image: test-image
39+
securityContext:
40+
runAsUser: 1001

0 commit comments

Comments
 (0)