Skip to content

Commit f713d43

Browse files
authored
ensure path exists when adding mutations (#789)
1 parent e896eec commit f713d43

File tree

6 files changed

+10
-19
lines changed

6 files changed

+10
-19
lines changed

checks/cpuLimitsMissing.yaml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,9 @@ schema:
2626
not:
2727
const: ''
2828
mutations:
29-
- op: add
30-
path: /resources/limits
31-
value: {}
3229
- op: add
3330
path: /resources/limits/cpu
3431
value: 100m
3532
comments:
3633
- find: "cpu: 100m"
37-
comment: "TODO: Set this to the amount of CPU you want to reserve for your workload"
34+
comment: "TODO: Set this to the maximum amount of CPU you want your workload to use"

checks/cpuRequestsMissing.yaml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,9 @@ schema:
2626
not:
2727
const: ''
2828
mutations:
29-
- op: add
30-
path: /resources/requests
31-
value: {}
3229
- op: add
3330
path: /resources/requests/cpu
3431
value: 100m
3532
comments:
3633
- find: "cpu: 100m"
37-
comment: "TODO: Set this to the amount of CPU you want to reserve for your workload"
34+
comment: "TODO: Set this to the amount of CPU you want to reserve for your workload"

checks/memoryLimitsMissing.yaml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,9 @@ schema:
2626
not:
2727
const: ''
2828
mutations:
29-
- op: add
30-
path: /resources/limits
31-
value: {}
3229
- op: add
3330
path: /resources/limits/memory
3431
value: "512Mi"
3532
comments:
3633
- find: "memory: 512Mi"
37-
comment: "TODO: Set this to the amount of Memory you want to reserve for your workload"
34+
comment: "TODO: Set this to the maximum amount of memory you want your workload to use"

checks/memoryRequestsMissing.yaml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,9 @@ schema:
2626
not:
2727
const: ''
2828
mutations:
29-
- op: add
30-
path: /resources/requests
31-
value: {}
3229
- op: add
3330
path: /resources/requests/memory
3431
value: "512Mi"
3532
comments:
3633
- find: "memory: 512Mi"
37-
comment: "TODO: Set this to the amount of Memory you want to reserve for your workload"
34+
comment: "TODO: Set this to the amount of Memory you want to reserve for your workload"

checks/runAsRootAllowed.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,6 @@ schema:
5151
securityContext:
5252
$ref: "#/definitions/goodSecurityContext"
5353
mutations:
54-
- op: replace
54+
- op: add
5555
path: /securityContext/runAsNonRoot
56-
value: true
56+
value: true

pkg/mutation/mutate.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ func ApplyAllSchemaMutations(conf *config.Configuration, resourceProvider *kube.
2727
if err != nil {
2828
return resource, err
2929
}
30-
jsonByte, err = patch.Apply(resByte)
30+
jsonByte, err = patch.ApplyWithOptions(resByte, &jsonpatchV5.ApplyOptions{
31+
AllowMissingPathOnRemove: true,
32+
EnsurePathExistsOnAdd: true,
33+
})
3134
if err != nil {
3235
return resource, err
3336
}

0 commit comments

Comments
 (0)