Repository navigation
feat(kyverno): register the catalog auto-vpa GeneratingPolicy #5134
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
Merged
+665
−7
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
118eb08
feat(kyverno): unregister the classic auto-vpa ClusterPolicy
devantler 1992b50
feat(kyverno): register the catalog's auto-vpa GeneratingPolicy
devantler bd9418f
fix(kyverno): split the auto-vpa GeneratingPolicy copy and approve it…
devantler 2dbd41d
Merge remote-tracking branch 'origin/main' into claude/kyverno-auto-v…
devantler af7e35f
docs(kyverno): correct the catalog header's VPA-name claim for this r…
devantler File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
k8s/bases/infrastructure/cluster-policies/best-practices/auto-vpa-daemonset.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| --- | ||
| # ADOPTED from devantler-tech/kyverno-policies | ||
| # policies/best-practices/auto-vpa-generating-policy.yaml at 44ed118 (#5130), which | ||
| # registers three GeneratingPolicy objects in one file. The platform keeps one | ||
| # resource per file, so it is split into auto-vpa-deployment.yaml (which also | ||
| # carries the catalog's own header), auto-vpa-statefulset.yaml and | ||
| # auto-vpa-daemonset.yaml. Each policy is copied verbatim except for one marked | ||
| # PLATFORM ADDITION: a namespaceSelector that keeps it out of the system | ||
| # namespaces, as the classic best-practices/auto-vpa.yaml did. The generate | ||
| # expressions must stay byte-for-byte the catalog's (whitespace aside): both static | ||
| # producer guards pin them (scripts/guard-consumer-discovery-conservation.sh and | ||
| # scripts/tests/crossplane-egress-policy-rules.yaml). The classic VPAs are named | ||
| # <name>, these are <name>-<kind>, so running both forms at once would put two VPAs | ||
| # on every workload: register these only after the classic policy's VPAs are gone. | ||
| apiVersion: policies.kyverno.io/v1 | ||
| kind: GeneratingPolicy | ||
| metadata: | ||
| name: auto-vpa-daemonset | ||
| annotations: | ||
| policies.kyverno.io/title: Auto VPA for DaemonSets (GeneratingPolicy) | ||
| policies.kyverno.io/category: Autoscaling | ||
| policies.kyverno.io/severity: low | ||
| policies.kyverno.io/subject: DaemonSet | ||
| policies.kyverno.io/minversion: 1.19.0 | ||
| policies.kyverno.io/description: >- | ||
| Generates a CPU-only recommendation-bounded VerticalPodAutoscaler for each | ||
| DaemonSet. GeneratingPolicy form of the classic auto-vpa rule of the same name. | ||
| spec: | ||
| # Parity with the classic rules' `synchronize: true` + `generateExisting: true`: | ||
| # on GeneratingPolicy both live under spec.evaluation and default to false, so | ||
| # omitting them would silently drop behavior the classic policy guarantees. | ||
| evaluation: | ||
| generateExisting: | ||
| enabled: true | ||
| synchronize: | ||
| enabled: true | ||
| matchConstraints: | ||
| resourceRules: | ||
| - apiGroups: ["apps"] | ||
| apiVersions: ["v1"] | ||
| operations: ["CREATE", "UPDATE"] | ||
| resources: ["daemonsets"] | ||
| # PLATFORM ADDITION (the only change from the catalog file): prod ships | ||
| # static VPAs for the controllers in these namespaces | ||
| # (k8s/providers/hetzner/infrastructure/vertical-pod-autoscalers/), so a | ||
| # generated one would put a second VPA on each of those pods. | ||
| namespaceSelector: | ||
| matchExpressions: | ||
| - key: kubernetes.io/metadata.name | ||
| operator: NotIn | ||
| values: | ||
| - kube-system | ||
| - kube-public | ||
| - kube-node-lease | ||
| - kyverno | ||
| generate: | ||
| - expression: >- | ||
| generator.Apply( | ||
| string(object.metadata.namespace), | ||
| [ | ||
| { | ||
| "apiVersion": dyn("autoscaling.k8s.io/v1"), | ||
| "kind": dyn("VerticalPodAutoscaler"), | ||
| "metadata": dyn({ | ||
| "name": string(object.metadata.name) + "-daemonset", | ||
| "namespace": string(object.metadata.namespace) | ||
| }), | ||
| "spec": dyn({ | ||
| "targetRef": dyn({ | ||
| "apiVersion": "apps/v1", | ||
| "kind": "DaemonSet", | ||
| "name": string(object.metadata.name) | ||
| }), | ||
| "updatePolicy": dyn({"updateMode": "InPlaceOrRecreate"}), | ||
| "resourcePolicy": dyn({ | ||
| "containerPolicies": [ | ||
| { | ||
| "containerName": dyn("*"), | ||
| "controlledResources": dyn(["cpu"]), | ||
| "controlledValues": dyn("RequestsAndLimits"), | ||
| "minAllowed": dyn({"cpu": "50m"}), | ||
| "maxAllowed": dyn({"cpu": "1"}) | ||
| } | ||
| ] | ||
| }) | ||
| }) | ||
| } | ||
| ] | ||
| ) |
117 changes: 117 additions & 0 deletions
117
k8s/bases/infrastructure/cluster-policies/best-practices/auto-vpa-deployment.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| --- | ||
| # ADOPTED from devantler-tech/kyverno-policies | ||
| # policies/best-practices/auto-vpa-generating-policy.yaml at 44ed118 (#5130), which | ||
| # registers three GeneratingPolicy objects in one file. The platform keeps one | ||
| # resource per file, so it is split into auto-vpa-deployment.yaml (which also | ||
| # carries the catalog's own header), auto-vpa-statefulset.yaml and | ||
| # auto-vpa-daemonset.yaml. Each policy is copied verbatim except for one marked | ||
| # PLATFORM ADDITION: a namespaceSelector that keeps it out of the system | ||
| # namespaces, as the classic best-practices/auto-vpa.yaml did. The generate | ||
| # expressions must stay byte-for-byte the catalog's (whitespace aside): both static | ||
| # producer guards pin them (scripts/guard-consumer-discovery-conservation.sh and | ||
| # scripts/tests/crossplane-egress-policy-rules.yaml). The classic VPAs are named | ||
| # <name>, these are <name>-<kind>, so running both forms at once would put two VPAs | ||
| # on every workload: register these only after the classic policy's VPAs are gone. | ||
| # | ||
| # The catalog's header follows. In this repository the classic file is the rollback | ||
| # form, and "the root kustomization.yaml" means this folder's kustomization.yaml. | ||
| # "Under the same name" below is not true here: the classic VPA is <name> and this | ||
| # one is <name>-deployment, so running both forms gives every workload two VPAs. | ||
| # | ||
| # The catalog's auto-vpa: a port of the classic policies/best-practices/auto-vpa.yaml | ||
| # ClusterPolicy rules to the GeneratingPolicy API, which Kyverno keeps after classic | ||
| # ClusterPolicy generate rules are retired. The classic ClusterPolicy is a separate file. | ||
| # | ||
| # THIS IS THE REGISTERED FORM in the root kustomization.yaml. The classic file stays in the | ||
| # repository, unregistered, as the rollback form until every consumer has migrated: never | ||
| # apply both to one cluster, because both generate a VerticalPodAutoscaler for the same | ||
| # workload under the same name. The README's "Migrating to the GeneratingPolicy form" | ||
| # section is the consumer rollout and rollback procedure. | ||
| # | ||
| # Split into one policy per workload kind, mirroring the classic policy's three rules: | ||
| # GeneratingPolicy applies spec.matchConstraints to the whole policy, so three kinds with | ||
| # three different VPA bodies cannot share one policy without branching inside CEL. | ||
| # | ||
| # FLOOR: Kyverno 1.19.0. On 1.18.x spec.evaluation.generateExisting is schema-accepted but | ||
| # does not fire for PRE-EXISTING workloads (kyverno/kyverno#15722, a regression against the | ||
| # classic rule; fixed by kyverno/kyverno#16041 for 1.19.0 and never backported), so an | ||
| # existing workload would get its VPA only on its next CREATE/UPDATE admission. The | ||
| # minversion annotations below declare that floor. | ||
| apiVersion: policies.kyverno.io/v1 | ||
| kind: GeneratingPolicy | ||
| metadata: | ||
| name: auto-vpa-deployment | ||
| annotations: | ||
| policies.kyverno.io/title: Auto VPA for Deployments (GeneratingPolicy) | ||
| policies.kyverno.io/category: Autoscaling | ||
| policies.kyverno.io/severity: low | ||
| policies.kyverno.io/subject: Deployment | ||
| policies.kyverno.io/minversion: 1.19.0 | ||
| policies.kyverno.io/description: >- | ||
| Generates a recommendation-bounded VerticalPodAutoscaler for each Deployment. | ||
| GeneratingPolicy form of the classic auto-vpa rule of the same name. | ||
| spec: | ||
| # Parity with the classic rules' `synchronize: true` + `generateExisting: true`: | ||
| # on GeneratingPolicy both live under spec.evaluation and default to false, so | ||
| # omitting them would silently drop behavior the classic policy guarantees. | ||
| evaluation: | ||
| generateExisting: | ||
| enabled: true | ||
| synchronize: | ||
| enabled: true | ||
| matchConstraints: | ||
| resourceRules: | ||
| - apiGroups: ["apps"] | ||
| apiVersions: ["v1"] | ||
| operations: ["CREATE", "UPDATE"] | ||
| resources: ["deployments"] | ||
| # PLATFORM ADDITION (the only change from the catalog file): prod ships | ||
| # static VPAs for the controllers in these namespaces | ||
| # (k8s/providers/hetzner/infrastructure/vertical-pod-autoscalers/), so a | ||
| # generated one would put a second VPA on each of those pods. | ||
| namespaceSelector: | ||
| matchExpressions: | ||
| - key: kubernetes.io/metadata.name | ||
| operator: NotIn | ||
| values: | ||
| - kube-system | ||
| - kube-public | ||
| - kube-node-lease | ||
| - kyverno | ||
| generate: | ||
| # Every value is dyn(): CEL infers a map's value type from its first entry, so a | ||
| # resource literal mixing strings with nested maps fails to compile without it. | ||
| # Fields read off `object` are dyn and need string() before concatenation. | ||
| - expression: >- | ||
| generator.Apply( | ||
| string(object.metadata.namespace), | ||
| [ | ||
| { | ||
| "apiVersion": dyn("autoscaling.k8s.io/v1"), | ||
| "kind": dyn("VerticalPodAutoscaler"), | ||
| "metadata": dyn({ | ||
| "name": string(object.metadata.name) + "-deployment", | ||
|
devantler marked this conversation as resolved.
|
||
| "namespace": string(object.metadata.namespace) | ||
| }), | ||
|
devantler marked this conversation as resolved.
|
||
| "spec": dyn({ | ||
| "targetRef": dyn({ | ||
| "apiVersion": "apps/v1", | ||
| "kind": "Deployment", | ||
| "name": string(object.metadata.name) | ||
| }), | ||
| "updatePolicy": dyn({"updateMode": "InPlaceOrRecreate"}), | ||
|
devantler marked this conversation as resolved.
|
||
| "resourcePolicy": dyn({ | ||
| "containerPolicies": [ | ||
| { | ||
| "containerName": dyn("*"), | ||
| "controlledResources": dyn(["cpu", "memory"]), | ||
| "controlledValues": dyn("RequestsAndLimits"), | ||
| "minAllowed": dyn({"cpu": "50m", "memory": "64Mi"}), | ||
| "maxAllowed": dyn({"cpu": "3", "memory": "6Gi"}) | ||
| } | ||
| ] | ||
| }) | ||
| }) | ||
| } | ||
| ] | ||
| ) | ||
89 changes: 89 additions & 0 deletions
89
k8s/bases/infrastructure/cluster-policies/best-practices/auto-vpa-statefulset.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| --- | ||
| # ADOPTED from devantler-tech/kyverno-policies | ||
| # policies/best-practices/auto-vpa-generating-policy.yaml at 44ed118 (#5130), which | ||
| # registers three GeneratingPolicy objects in one file. The platform keeps one | ||
| # resource per file, so it is split into auto-vpa-deployment.yaml (which also | ||
| # carries the catalog's own header), auto-vpa-statefulset.yaml and | ||
| # auto-vpa-daemonset.yaml. Each policy is copied verbatim except for one marked | ||
| # PLATFORM ADDITION: a namespaceSelector that keeps it out of the system | ||
| # namespaces, as the classic best-practices/auto-vpa.yaml did. The generate | ||
| # expressions must stay byte-for-byte the catalog's (whitespace aside): both static | ||
| # producer guards pin them (scripts/guard-consumer-discovery-conservation.sh and | ||
| # scripts/tests/crossplane-egress-policy-rules.yaml). The classic VPAs are named | ||
| # <name>, these are <name>-<kind>, so running both forms at once would put two VPAs | ||
| # on every workload: register these only after the classic policy's VPAs are gone. | ||
| apiVersion: policies.kyverno.io/v1 | ||
| kind: GeneratingPolicy | ||
| metadata: | ||
| name: auto-vpa-statefulset | ||
| annotations: | ||
| policies.kyverno.io/title: Auto VPA for StatefulSets (GeneratingPolicy) | ||
| policies.kyverno.io/category: Autoscaling | ||
| policies.kyverno.io/severity: low | ||
| policies.kyverno.io/subject: StatefulSet | ||
| policies.kyverno.io/minversion: 1.19.0 | ||
| policies.kyverno.io/description: >- | ||
| Generates a recommendation-bounded VerticalPodAutoscaler for each StatefulSet. | ||
| GeneratingPolicy form of the classic auto-vpa rule of the same name. | ||
| spec: | ||
| # Parity with the classic rules' `synchronize: true` + `generateExisting: true`: | ||
| # on GeneratingPolicy both live under spec.evaluation and default to false, so | ||
| # omitting them would silently drop behavior the classic policy guarantees. | ||
| evaluation: | ||
| generateExisting: | ||
| enabled: true | ||
| synchronize: | ||
| enabled: true | ||
| matchConstraints: | ||
| resourceRules: | ||
| - apiGroups: ["apps"] | ||
| apiVersions: ["v1"] | ||
| operations: ["CREATE", "UPDATE"] | ||
| resources: ["statefulsets"] | ||
| # PLATFORM ADDITION (the only change from the catalog file): prod ships | ||
| # static VPAs for the controllers in these namespaces | ||
| # (k8s/providers/hetzner/infrastructure/vertical-pod-autoscalers/), so a | ||
| # generated one would put a second VPA on each of those pods. | ||
| namespaceSelector: | ||
| matchExpressions: | ||
| - key: kubernetes.io/metadata.name | ||
| operator: NotIn | ||
| values: | ||
| - kube-system | ||
| - kube-public | ||
| - kube-node-lease | ||
| - kyverno | ||
| generate: | ||
| - expression: >- | ||
| generator.Apply( | ||
| string(object.metadata.namespace), | ||
| [ | ||
| { | ||
| "apiVersion": dyn("autoscaling.k8s.io/v1"), | ||
| "kind": dyn("VerticalPodAutoscaler"), | ||
| "metadata": dyn({ | ||
| "name": string(object.metadata.name) + "-statefulset", | ||
| "namespace": string(object.metadata.namespace) | ||
| }), | ||
| "spec": dyn({ | ||
| "targetRef": dyn({ | ||
| "apiVersion": "apps/v1", | ||
| "kind": "StatefulSet", | ||
| "name": string(object.metadata.name) | ||
| }), | ||
| "updatePolicy": dyn({"updateMode": "Initial"}), | ||
| "resourcePolicy": dyn({ | ||
| "containerPolicies": [ | ||
| { | ||
| "containerName": dyn("*"), | ||
| "controlledResources": dyn(["cpu", "memory"]), | ||
| "controlledValues": dyn("RequestsAndLimits"), | ||
| "minAllowed": dyn({"cpu": "50m", "memory": "64Mi"}), | ||
| "maxAllowed": dyn({"cpu": "3", "memory": "6Gi"}) | ||
| } | ||
| ] | ||
| }) | ||
| }) | ||
| } | ||
| ] | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.