Skip to content

Commit

Permalink
Regenerate documentation artifacts
Browse files Browse the repository at this point in the history
Signed-off-by: Paul Krizak <paul.krizak@gmail.com>
  • Loading branch information
skaven81 committed Oct 26, 2023
1 parent 6f6bde2 commit f93ad9b
Show file tree
Hide file tree
Showing 12 changed files with 295 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: k8sreplicalimits
displayName: Replica Limits
createdAt: "2023-03-31T20:34:16Z"
description: Requires that objects with the field `spec.replicas` (Deployments, ReplicaSets, etc.) specify a number of replicas within defined ranges.
digest: a8dc0e94f30cdf1f4aff2e69551744b6eaee3f4e60dba3393705f81363a249e5
digest: 506ffc47aff782cfb7b239eb545c8181717b1ae9ca3646d2b3a3224d9dc52981
license: Apache-2.0
homeURL: https://open-policy-agent.github.io/gatekeeper-library/website/replicalimits
keywords:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ spec:
kinds:
- apiGroups: ["apps"]
kinds: ["Deployment"]
- apiGroups: ["autoscaling"]
kinds: ["Scale"]
parameters:
ranges:
- min_replicas: 3
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: autoscaling/v1
kind: Scale
metadata:
name: allowed-deployment
spec:
replicas: 3
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: autoscaling/v1
kind: Scale
metadata:
name: allowed-deployment
spec:
replicas: 100
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: constraints.gatekeeper.sh/v1beta1
kind: K8sReplicaLimits
metadata:
name: replica-limits
spec:
match:
kinds:
- apiGroups: ["apps"]
kinds: ["Deployment"]
- apiGroups: ["autoscaling"]
kinds: ["Scale"]
parameters:
ranges:
- min_replicas: 0
max_replicas: 50
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: allowed-deployment
spec:
selector:
matchLabels:
app: nginx
replicas: 0
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: disallowed-deployment
spec:
selector:
matchLabels:
app: nginx
replicas: 100
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: autoscaling/v1
kind: Scale
metadata:
name: allowed-deployment
# kubectl scale deploy <name> --replicas=0 creates a Scale
# resource with an empty spec, not replicas:0
spec: {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: autoscaling/v1
kind: Scale
metadata:
name: allowed-deployment
spec:
replicas: 100
28 changes: 28 additions & 0 deletions artifacthub/library/general/replicalimits/1.0.1/suite.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,35 @@ tests:
object: samples/replicalimits/example_allowed.yaml
assertions:
- violations: no
- name: example-scale-allowed
object: samples/replicalimits/example_scale_allowed.yaml
assertions:
- violations: no
- name: example-disallowed
object: samples/replicalimits/example_disallowed.yaml
assertions:
- violations: yes
- name: example-scale-disallowed
object: samples/replicalimits/example_scale_disallowed.yaml
assertions:
- violations: yes
- name: replica-limit-zero
template: template.yaml
constraint: samples/replicalimits_zero/constraint.yaml
cases:
- name: example-allowed
object: samples/replicalimits_zero/example_allowed.yaml
assertions:
- violations: no
- name: example-scale-allowed
object: samples/replicalimits_zero/example_scale_allowed.yaml
assertions:
- violations: no
- name: example-disallowed
object: samples/replicalimits_zero/example_disallowed.yaml
assertions:
- violations: yes
- name: example-scale-disallowed
object: samples/replicalimits_zero/example_scale_disallowed.yaml
assertions:
- violations: yes
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ spec:
}
input_replica_limit(spec) {
provided := input.review.object.spec.replicas
provided := object.get(spec, "replicas", 0)
count(input.parameters.ranges) > 0
range := input.parameters.ranges[_]
value_within_range(range, provided)
Expand Down
186 changes: 185 additions & 1 deletion website/docs/validation/replicalimits.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ spec:
}
input_replica_limit(spec) {
provided := input.review.object.spec.replicas
provided := object.get(spec, "replicas", 0)
count(input.parameters.ranges) > 0
range := input.parameters.ranges[_]
value_within_range(range, provided)
Expand Down Expand Up @@ -92,6 +92,8 @@ spec:
kinds:
- apiGroups: ["apps"]
kinds: ["Deployment"]
- apiGroups: ["autoscaling"]
kinds: ["Scale"]
parameters:
ranges:
- min_replicas: 3
Expand Down Expand Up @@ -139,6 +141,26 @@ Usage
kubectl apply -f https://raw.githubusercontent.com/open-policy-agent/gatekeeper-library/master/library/general/replicalimits/samples/replicalimits/example_allowed.yaml
```

</details>
<details>
<summary>example-scale-allowed</summary>

```yaml
apiVersion: autoscaling/v1
kind: Scale
metadata:
name: allowed-deployment
spec:
replicas: 3

```

Usage

```shell
kubectl apply -f https://raw.githubusercontent.com/open-policy-agent/gatekeeper-library/master/library/general/replicalimits/samples/replicalimits/example_scale_allowed.yaml
```

</details>
<details>
<summary>example-disallowed</summary>
Expand Down Expand Up @@ -172,6 +194,168 @@ Usage
kubectl apply -f https://raw.githubusercontent.com/open-policy-agent/gatekeeper-library/master/library/general/replicalimits/samples/replicalimits/example_disallowed.yaml
```

</details>
<details>
<summary>example-scale-disallowed</summary>

```yaml
apiVersion: autoscaling/v1
kind: Scale
metadata:
name: allowed-deployment
spec:
replicas: 100

```

Usage

```shell
kubectl apply -f https://raw.githubusercontent.com/open-policy-agent/gatekeeper-library/master/library/general/replicalimits/samples/replicalimits/example_scale_disallowed.yaml
```

</details>


</blockquote></details><details>
<summary>replica-limit-zero</summary><blockquote>

<details>
<summary>constraint</summary>

```yaml
apiVersion: constraints.gatekeeper.sh/v1beta1
kind: K8sReplicaLimits
metadata:
name: replica-limits
spec:
match:
kinds:
- apiGroups: ["apps"]
kinds: ["Deployment"]
- apiGroups: ["autoscaling"]
kinds: ["Scale"]
parameters:
ranges:
- min_replicas: 0
max_replicas: 50

```

Usage

```shell
kubectl apply -f https://raw.githubusercontent.com/open-policy-agent/gatekeeper-library/master/library/general/replicalimits/samples/replicalimits_zero/constraint.yaml
```

</details>

<details>
<summary>example-allowed</summary>

```yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: allowed-deployment
spec:
selector:
matchLabels:
app: nginx
replicas: 0
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80

```

Usage

```shell
kubectl apply -f https://raw.githubusercontent.com/open-policy-agent/gatekeeper-library/master/library/general/replicalimits/samples/replicalimits_zero/example_allowed.yaml
```

</details>
<details>
<summary>example-scale-allowed</summary>

```yaml
apiVersion: autoscaling/v1
kind: Scale
metadata:
name: allowed-deployment
# kubectl scale deploy <name> --replicas=0 creates a Scale
# resource with an empty spec, not replicas:0
spec: {}

```
Usage
```shell
kubectl apply -f https://raw.githubusercontent.com/open-policy-agent/gatekeeper-library/master/library/general/replicalimits/samples/replicalimits_zero/example_scale_allowed.yaml
```

</details>
<details>
<summary>example-disallowed</summary>

```yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: disallowed-deployment
spec:
selector:
matchLabels:
app: nginx
replicas: 100
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80

```

Usage

```shell
kubectl apply -f https://raw.githubusercontent.com/open-policy-agent/gatekeeper-library/master/library/general/replicalimits/samples/replicalimits_zero/example_disallowed.yaml
```

</details>
<details>
<summary>example-scale-disallowed</summary>

```yaml
apiVersion: autoscaling/v1
kind: Scale
metadata:
name: allowed-deployment
spec:
replicas: 100

```

Usage

```shell
kubectl apply -f https://raw.githubusercontent.com/open-policy-agent/gatekeeper-library/master/library/general/replicalimits/samples/replicalimits_zero/example_scale_disallowed.yaml
```

</details>


Expand Down

0 comments on commit f93ad9b

Please sign in to comment.