Skip to content

Commit

Permalink
ensure path exists when adding mutations (#789)
Browse files Browse the repository at this point in the history
  • Loading branch information
rbren authored Jul 7, 2022
1 parent e896eec commit f713d43
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 19 deletions.
5 changes: 1 addition & 4 deletions checks/cpuLimitsMissing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,9 @@ schema:
not:
const: ''
mutations:
- op: add
path: /resources/limits
value: {}
- op: add
path: /resources/limits/cpu
value: 100m
comments:
- find: "cpu: 100m"
comment: "TODO: Set this to the amount of CPU you want to reserve for your workload"
comment: "TODO: Set this to the maximum amount of CPU you want your workload to use"
5 changes: 1 addition & 4 deletions checks/cpuRequestsMissing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,9 @@ schema:
not:
const: ''
mutations:
- op: add
path: /resources/requests
value: {}
- op: add
path: /resources/requests/cpu
value: 100m
comments:
- find: "cpu: 100m"
comment: "TODO: Set this to the amount of CPU you want to reserve for your workload"
comment: "TODO: Set this to the amount of CPU you want to reserve for your workload"
5 changes: 1 addition & 4 deletions checks/memoryLimitsMissing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,9 @@ schema:
not:
const: ''
mutations:
- op: add
path: /resources/limits
value: {}
- op: add
path: /resources/limits/memory
value: "512Mi"
comments:
- find: "memory: 512Mi"
comment: "TODO: Set this to the amount of Memory you want to reserve for your workload"
comment: "TODO: Set this to the maximum amount of memory you want your workload to use"
5 changes: 1 addition & 4 deletions checks/memoryRequestsMissing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,9 @@ schema:
not:
const: ''
mutations:
- op: add
path: /resources/requests
value: {}
- op: add
path: /resources/requests/memory
value: "512Mi"
comments:
- find: "memory: 512Mi"
comment: "TODO: Set this to the amount of Memory you want to reserve for your workload"
comment: "TODO: Set this to the amount of Memory you want to reserve for your workload"
4 changes: 2 additions & 2 deletions checks/runAsRootAllowed.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@ schema:
securityContext:
$ref: "#/definitions/goodSecurityContext"
mutations:
- op: replace
- op: add
path: /securityContext/runAsNonRoot
value: true
value: true
5 changes: 4 additions & 1 deletion pkg/mutation/mutate.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ func ApplyAllSchemaMutations(conf *config.Configuration, resourceProvider *kube.
if err != nil {
return resource, err
}
jsonByte, err = patch.Apply(resByte)
jsonByte, err = patch.ApplyWithOptions(resByte, &jsonpatchV5.ApplyOptions{
AllowMissingPathOnRemove: true,
EnsurePathExistsOnAdd: true,
})
if err != nil {
return resource, err
}
Expand Down

0 comments on commit f713d43

Please sign in to comment.