Skip to content

Commit

Permalink
feat(rules/kubernetes): add rule to prevent latest tag, rule to ensur…
Browse files Browse the repository at this point in the history
…e pull policy is set
  • Loading branch information
ssube committed Nov 16, 2019
1 parent 26eda4c commit 8254848
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 1 deletion.
42 changes: 41 additions & 1 deletion rules/kubernetes.yml
Expand Up @@ -106,6 +106,7 @@ rules:
level: info
tags:
- kubernetes
- important
- labels

check:
Expand All @@ -121,4 +122,43 @@ rules:
additionalProperties: false
patternProperties:
"^[-.a-z0-9]{1,63}$":
type: string
type: string

- name: kubernetes-container-pull-policy
desc: all containers should have a pull policy
level: info
tags:
- kubernetes
- image
- optional

select: '$..containers.*'
check:
type: object
required: [image, imagePullPolicy]
properties:
imagePullPolicy:
type: string
enum:
- Always
- IfNotPresent
- Never


- name: kubernetes-image-latest
desc: images should never use :latest tag
level: info
tags:
- kubernetes
- image
- important

select: '$..containers.*'
check:
type: object
required: [image]
properties:
image:
type: string
not:
pattern: ':latest$'
2 changes: 2 additions & 0 deletions test/examples/kubernetes-resources-high.yml
Expand Up @@ -10,6 +10,8 @@ spec:
spec:
containers:
- name: test
image: foo
imagePullPolicy: Always
resources:
limits:
cpu: 4000m
Expand Down
2 changes: 2 additions & 0 deletions test/examples/kubernetes-resources-low.yml
Expand Up @@ -10,6 +10,8 @@ spec:
spec:
containers:
- name: test
image: foo
imagePullPolicy: Always
resources:
limits:
memory: 5Mi
Expand Down
2 changes: 2 additions & 0 deletions test/examples/kubernetes-resources-med.yml
Expand Up @@ -10,6 +10,8 @@ spec:
spec:
containers:
- name: test
image: foo
imagePullPolicy: Always
resources:
limits:
cpu: 200m
Expand Down
4 changes: 4 additions & 0 deletions test/examples/kubernetes-resources-multi.yml
Expand Up @@ -10,6 +10,8 @@ spec:
spec:
containers:
- name: test
image: foo
imagePullPolicy: Always
resources:
limits:
cpu: 4000m
Expand All @@ -19,6 +21,8 @@ spec:
memory: 5Gi

- name: other
image: foo
imagePullPolicy: Always
resources:
limits:
cpu: 2000m
Expand Down
2 changes: 2 additions & 0 deletions test/examples/kubernetes-resources-none.yml
Expand Up @@ -10,4 +10,6 @@ spec:
spec:
containers:
- name: test
image: foo
imagePullPolicy: Always
# missing resources
6 changes: 6 additions & 0 deletions test/examples/kubernetes-resources-some.yml
Expand Up @@ -10,6 +10,8 @@ spec:
spec:
containers:
- name: test
image: foo
imagePullPolicy: Always
resources:
limits:
cpu: 4000m
Expand All @@ -28,6 +30,8 @@ spec:
spec:
containers:
- name: test
image: foo
imagePullPolicy: Always
resources:
limits:
cpu: 200m
Expand All @@ -46,6 +50,8 @@ spec:
spec:
containers:
- name: test
image: foo
imagePullPolicy: Always
resources:
limits:
cpu: 4000m
Expand Down

0 comments on commit 8254848

Please sign in to comment.