Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding policy for CPU Limits for all container types #1067

Merged
merged 7 commits into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
name: require-cpu-limits
status:
ready: true
38 changes: 38 additions & 0 deletions other/require-cpu-limits/.chainsaw-test/chainsaw-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/kyverno/chainsaw/main/.schemas/json/test-chainsaw-v1alpha1.json
apiVersion: chainsaw.kyverno.io/v1alpha1
kind: Test
metadata:
creationTimestamp: null
name: require-cpu-limits
spec:
steps:
- name: step-01
try:
- apply:
file: ../require-cpu-limits.yaml
- patch:
resource:
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
name: require-cpu-limits
spec:
validationFailureAction: Enforce
- assert:
file: chainsaw-step-01-assert-1.yaml
- name: step-02
try:
- apply:
file: pod-good.yaml
- apply:
expect:
- check:
($error != null): true
file: pod-bad.yaml
- apply:
file: podcontroller-good.yaml
- apply:
expect:
- check:
($error != null): true
file: podcontroller-bad.yaml
80 changes: 80 additions & 0 deletions other/require-cpu-limits/.chainsaw-test/pod-bad.yaml
nsagark marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
apiVersion: v1
kind: Pod
metadata:
name: badpod01
spec:
containers:
- name: container01
image: busybox:1.35
---
apiVersion: v1
kind: Pod
metadata:
name: badpod02
spec:
containers:
- name: container01
image: busybox:1.35
nsagark marked this conversation as resolved.
Show resolved Hide resolved
securityContext:
allowPrivilegeEscalation: true
---
apiVersion: v1
kind: Pod
metadata:
name: badpod03
spec:
containers:
- name: container01
image: busybox:1.35
- name: container02
image: busybox:1.35
securityContext:
allowPrivilegeEscalation: false
---
apiVersion: v1
kind: Pod
metadata:
name: badpod04
spec:
containers:
- name: container01
image: busybox:1.35
securityContext:
allowPrivilegeEscalation: true
- name: container02
image: busybox:1.35
securityContext:
allowPrivilegeEscalation: false
---
apiVersion: v1
kind: Pod
metadata:
name: badpod05
spec:
initContainers:
- name: initcontainer01
image: busybox:1.35
containers:
- name: container01
image: busybox:1.35
securityContext:
allowPrivilegeEscalation: false
---
apiVersion: v1
kind: Pod
metadata:
name: badpod06
spec:
initContainers:
- name: initcontainer01
image: busybox:1.35
- name: initcontainer02
image: busybox:1.35
nsagark marked this conversation as resolved.
Show resolved Hide resolved
securityContext:
allowPrivilegeEscalation: true
containers:
- name: container01
image: busybox:1.35
securityContext:
allowPrivilegeEscalation: false
---
121 changes: 121 additions & 0 deletions other/require-cpu-limits/.chainsaw-test/pod-good.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
apiVersion: v1
kind: Pod
metadata:
name: goodpod01
spec:
containers:
- name: container01
image: busybox:1.35@sha256:5b6e7aeda43f426b6423f60da863e2e6015c9983c957cf1b068120aea609261d
securityContext:
allowPrivilegeEscalation: false
resources:
limits:
cpu: "50m"
---
apiVersion: v1
kind: Pod
metadata:
name: goodpod02
spec:
containers:
- name: container01
image: busybox:1.35@sha256:5b6e7aeda43f426b6423f60da863e2e6015c9983c957cf1b068120aea609261d
securityContext:
allowPrivilegeEscalation: false
resources:
limits:
cpu: "50m"
- name: container02
image: busybox:1.35@sha256:5b6e7aeda43f426b6423f60da863e2e6015c9983c957cf1b068120aea609261d
securityContext:
allowPrivilegeEscalation: false
resources:
limits:
cpu: "50m"
---
apiVersion: v1
kind: Pod
metadata:
name: goodpod03
spec:
initContainers:
- name: initcontainer01
image: busybox:1.35@sha256:5b6e7aeda43f426b6423f60da863e2e6015c9983c957cf1b068120aea609261d
securityContext:
allowPrivilegeEscalation: false
resources:
limits:
cpu: "50m"
containers:
- name: container01
image: busybox:1.35@sha256:5b6e7aeda43f426b6423f60da863e2e6015c9983c957cf1b068120aea609261d
securityContext:
allowPrivilegeEscalation: false
resources:
limits:
cpu: "50m"
---
apiVersion: v1
kind: Pod
metadata:
name: goodpod04
spec:
initContainers:
- name: initcontainer01
image: busybox:1.35@sha256:5b6e7aeda43f426b6423f60da863e2e6015c9983c957cf1b068120aea609261d
securityContext:
allowPrivilegeEscalation: false
resources:
limits:
cpu: "50m"
- name: initcontainer02
image: busybox:1.35@sha256:5b6e7aeda43f426b6423f60da863e2e6015c9983c957cf1b068120aea609261d
securityContext:
allowPrivilegeEscalation: false
resources:
limits:
cpu: "50m"
containers:
- name: container01
image: busybox:1.35@sha256:5b6e7aeda43f426b6423f60da863e2e6015c9983c957cf1b068120aea609261d
securityContext:
allowPrivilegeEscalation: false
resources:
limits:
cpu: "50m"
---
apiVersion: v1
kind: Pod
metadata:
name: goodpod05
spec:
initContainers:
- name: initcontainer01
image: busybox:1.35@sha256:5b6e7aeda43f426b6423f60da863e2e6015c9983c957cf1b068120aea609261d
securityContext:
allowPrivilegeEscalation: false
resources:
limits:
cpu: "50m"
- name: initcontainer02
image: busybox:1.35@sha256:5b6e7aeda43f426b6423f60da863e2e6015c9983c957cf1b068120aea609261d
securityContext:
allowPrivilegeEscalation: false
resources:
limits:
cpu: "50m"
containers:
- name: container01
image: busybox:1.35@sha256:5b6e7aeda43f426b6423f60da863e2e6015c9983c957cf1b068120aea609261d
securityContext:
allowPrivilegeEscalation: false
resources:
limits:
cpu: "50m"
- name: container02
image: busybox:1.35@sha256:5b6e7aeda43f426b6423f60da863e2e6015c9983c957cf1b068120aea609261d
securityContext:
allowPrivilegeEscalation: false
resources:
limits:
cpu: "50m"
Loading