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

Adds deprecated resources for showing the deprecation validation with the schema validator #13

Merged
merged 20 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion bundles/simple.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ spec:
ports:
- name: http-web
protocol: TCP
port: "this-should-be-a-number"
port: 81
targetPort: 8080
32 changes: 32 additions & 0 deletions crd-validation-rules/crd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: mycustomresources.example.com
spec:
group: example.com
names:
kind: MyCustomResource
plural: mycustomresources
singular: mycustomresource
shortNames:
- mcr
scope: Namespaced
versions:
- name: v1
schema:
openAPIV3Schema:
type: object
properties:
spec:
type: object
x-kubernetes-validation:
- rule: "self.replicas <= self.maxReplicas"
message: "replicas must be less than or equal to maxReplicas"
properties:
replicas:
type: integer
maxReplicas:
type: integer
required:
- replicas
- maxReplicas
7 changes: 7 additions & 0 deletions crd-validation-rules/custom-resource.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: example.com/v1
kind: MyCustomResource
metadata:
name: example-demo
spec:
replicas: 10
maxReplicas: 20
2 changes: 1 addition & 1 deletion kustomize-happy-cms/base/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ metadata:
labels:
monokle.io/demo: kustomize-happy-cms
spec:
replicas: 1
replicas: 6
selector:
matchLabels:
app: happy-cms
Expand Down
16 changes: 8 additions & 8 deletions standalone/deployment.yaml
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: panda-blog
name: bear-blog
namespace: third-branch
labels:
monokle.io/demo: vanilla-panda-blog
monokle.io/demo: vanilla-bear-blog
spec:
replicas: 1
selector:
matchLabels:
app: panda-blog
app: bear-blog
template:
metadata:
labels:
app: panda-blog
app: bear-blog
spec:
securityContext:
runAsUser: 12000
runAsGroup: 11000
containers:
- name: panda-blog
image: panda-blog:latest
- name: bear-blog
image: bear-blog:latest
ports:
- name: http-web
containerPort: 8080
- name: panda-sidecar
image: panda-sidecar:latest
- name: bear-sidecar
image: bear-sidecar:latest
securityContext:
runAsUser: 650
ports:
Expand Down
100 changes: 100 additions & 0 deletions standalone/deprecated.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: job-1
labels:
app: cj
spec:
schedule: "* * * * *"
jobTemplate:
spec:
template:
spec:
containers:
- name: hello
image: busybox:1.28
imagePullPolicy: IfNotPresent
command:
- /bin/sh
- -c
- date; echo Hello from the Kubernetes cluster
restartPolicy: OnFailure
---
apiVersion: apps/v1beta2
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
replicas: 5
rollbackTo:
revision: 0
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80
---
apiVersion: v1
kind: FlowSchema
metadata:
name: health-for-strangers
spec:
matchingPrecedence: 1000
priorityLevelConfiguration:
name: exempt
rules:
- nonResourceRules:
- nonResourceURLs:
- "/healthz"
- "/livez"
- "/readyz"
verbs:
- "*"
subjects:
- kind: Group
group:
name: "system:unauthenticated"
---
apiVersion: apps/v1beta1
kind: ReplicaSet
metadata:
name: frontend
labels:
app: guestbook
tier: frontend
spec:
replicas: 3
selector:
matchLabels:
tier: frontend
template:
metadata:
labels:
tier: frontend
spec:
containers:
- name: php-redis
image: gcr.io/google_samples/gb-frontend:v3
---
apiVersion: storage.k8s.io/v1beta1
kind: StorageClass
metadata:
name: standard
provisioner: kubernetes.io/aws-ebs
parameters:
type: gp2
reclaimPolicy: Retain
allowVolumeExpansion: true
mountOptions:
- debug
volumeBindingMode: Immediate
30 changes: 30 additions & 0 deletions validating-admission-policies/demo.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
apiVersion: v1
kind: Namespace
metadata:
name: demo
labels:
env: production
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
namespace: demo
labels:
app: nginx
env: production
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80
42 changes: 42 additions & 0 deletions validating-admission-policies/ha-params.policy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
apiVersion: admissionregistration.k8s.io/v1beta1
kind: ValidatingAdmissionPolicy
metadata:
name: high-available-params
spec:
failurePolicy: Fail
paramKind:
apiVersion: v1
kind: ConfigMap
matchConstraints:
resourceRules:
- apiGroups: [ "apps" ]
apiVersions: [ "v1" ]
operations: [ "CREATE", "UPDATE" ]
resources: [ "deployments" ]
validations:
- expression: "object.spec.replicas <= params.data.maxReplicas"
message: "replicas must be less or equal to than maxReplicas"
---
apiVersion: v1
kind: ConfigMap
metadata:
name: rule-config
namespace: demo
data:
maxReplicas: 4
---
apiVersion: admissionregistration.k8s.io/v1beta1
kind: ValidatingAdmissionPolicyBinding
metadata:
name: high-available-params
spec:
policyName: high-available-params
validationActions:
- Deny
paramRef:
name: rule-config
namespace: demo
matchResources:
namespaceSelector:
matchLabels:
env: production
23 changes: 23 additions & 0 deletions validating-admission-policies/ha.policy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
apiVersion: admissionregistration.k8s.io/v1beta1
kind: ValidatingAdmissionPolicy
metadata:
name: high-available
spec:
failurePolicy: Fail
matchConstraints:
resourceRules:
- apiGroups: [ "apps" ]
apiVersions: [ "v1" ]
operations: [ "CREATE", "UPDATE" ]
resources: [ "deployments" ]
validations:
- expression: "object.spec.replicas > 2"
message: "replicas must be greater than 2"
---
apiVersion: admissionregistration.k8s.io/v1beta1
kind: ValidatingAdmissionPolicyBinding
metadata:
name: high-available
spec:
policyName: high-available
validationActions: [Deny]
24 changes: 24 additions & 0 deletions validating-admission-policies/labels.policy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: admissionregistration.k8s.io/v1beta1
kind: ValidatingAdmissionPolicy
metadata:
name: env-label
spec:
failurePolicy: Fail
matchConstraints:
resourceRules:
- apiGroups: [ "apps" ]
apiVersions: [ "v1" ]
operations: [ "CREATE", "UPDATE" ]
resources: [ "deployments" ]
validations:
- expression: "has(object.metadata.labels) && has(object.metadata.labels.env) &&
object.metadata.labels.env in ['production', 'staging']"
message: Missing expected env label
---
apiVersion: admissionregistration.k8s.io/v1beta1
kind: ValidatingAdmissionPolicyBinding
metadata:
name: env-label
spec:
policyName: env-label
validationActions: [ Deny ]
2 changes: 1 addition & 1 deletion vanilla-panda-blog/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ metadata:
labels:
monokle.io/demo: vanilla-panda-blog
spec:
replicas: 1
replicas: 5
selector:
matchLabels:
app: panda-blog
Expand Down