-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: CEL validation for provider-specific labels/requirements (#274)
* chore: use vmname-nic for network interface names * chore: add CEL validation for provider labels/requirements * chore: make presubmit * chore: makefile herlper for deleting CRDs * Revert "chore: use vmname-nic for network interface names" This reverts commit 3ebebe1. * doc: add regex comment as requested * fix: remove topology.kubernetes.io/zone from allowed labels and requirements (until the continuous drift it causes is fixed) * chore: add better error handling
- Loading branch information
Showing
7 changed files
with
96 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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,7 @@ | ||
#!/usr/bin/env bash | ||
set -euo pipefail | ||
|
||
# remove topology.kubernetes.io/zone from allowed labels and requirements | ||
# until the continuous drift it causes is fixed | ||
sed -e 's|"topology.kubernetes.io/zone", ||g' -i pkg/apis/crds/karpenter.sh_nodeclaims.yaml | ||
sed -e 's|"topology.kubernetes.io/zone", ||g' -i pkg/apis/crds/karpenter.sh_nodepools.yaml |
This file contains 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,35 @@ | ||
#!/bin/bash | ||
set -euo pipefail | ||
|
||
# labels validation for nodepool | ||
# checking for restricted labels while filtering out well known labels | ||
|
||
rule=$'self.all(x, x in | ||
[ | ||
"karpenter.azure.com/sku-name", | ||
"karpenter.azure.com/sku-family", | ||
"karpenter.azure.com/sku-version", | ||
"karpenter.azure.com/sku-cpu", | ||
"karpenter.azure.com/sku-memory", | ||
"karpenter.azure.com/sku-accelerator", | ||
"karpenter.azure.com/sku-networking-accelerated", | ||
"karpenter.azure.com/sku-storage-premium-capable", | ||
"karpenter.azure.com/sku-storage-ephemeralos-maxsize", | ||
"karpenter.azure.com/sku-encryptionathost-capable", | ||
"karpenter.azure.com/sku-gpu-name", | ||
"karpenter.azure.com/sku-gpu-manufacturer", | ||
"karpenter.azure.com/sku-gpu-count" | ||
] | ||
|| !x.find("^([^/]+)").endsWith("karpenter.azure.com") | ||
) | ||
' | ||
# above regex: everything before the first '/' (any characters except '/' at the beginning of the string) | ||
|
||
rule=${rule//\"/\\\"} # escape double quotes | ||
rule=${rule//$'\n'/} # remove newlines | ||
rule=$(echo "$rule" | tr -s ' ') # remove extra spaces | ||
|
||
# nodepool | ||
printf -v expr '.spec.versions[0].schema.openAPIV3Schema.properties.spec.properties.template.properties.metadata.properties.labels.x-kubernetes-validations += | ||
[{"message": "label domain \\"karpenter.azure.com\\" is restricted", "rule": "%s"}]' "$rule" | ||
yq eval "${expr}" -i pkg/apis/crds/karpenter.sh_nodepools.yaml |
This file contains 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,39 @@ | ||
#!/bin/bash | ||
set -euo pipefail | ||
|
||
# requirements validation for nodeclaim and nodepool | ||
# checking for restricted labels while filtering out well known labels | ||
|
||
rule=$'self in | ||
[ | ||
"karpenter.azure.com/sku-name", | ||
"karpenter.azure.com/sku-family", | ||
"karpenter.azure.com/sku-version", | ||
"karpenter.azure.com/sku-cpu", | ||
"karpenter.azure.com/sku-memory", | ||
"karpenter.azure.com/sku-accelerator", | ||
"karpenter.azure.com/sku-networking-accelerated", | ||
"karpenter.azure.com/sku-storage-premium-capable", | ||
"karpenter.azure.com/sku-storage-ephemeralos-maxsize", | ||
"karpenter.azure.com/sku-encryptionathost-capable", | ||
"karpenter.azure.com/sku-gpu-name", | ||
"karpenter.azure.com/sku-gpu-manufacturer", | ||
"karpenter.azure.com/sku-gpu-count" | ||
] | ||
|| !self.find("^([^/]+)").endsWith("karpenter.azure.com") | ||
' | ||
# above regex: everything before the first '/' (any characters except '/' at the beginning of the string) | ||
|
||
rule=${rule//\"/\\\"} # escape double quotes | ||
rule=${rule//$'\n'/} # remove newlines | ||
rule=$(echo "$rule" | tr -s ' ') # remove extra spaces | ||
|
||
# nodeclaim | ||
printf -v expr '.spec.versions[0].schema.openAPIV3Schema.properties.spec.properties.requirements.items.properties.key.x-kubernetes-validations += | ||
[{"message": "label domain \\"karpenter.azure.com\\" is restricted", "rule": "%s"}]' "$rule" | ||
yq eval "${expr}" -i pkg/apis/crds/karpenter.sh_nodeclaims.yaml | ||
|
||
# nodepool | ||
printf -v expr '.spec.versions[0].schema.openAPIV3Schema.properties.spec.properties.template.properties.spec.properties.requirements.items.properties.key.x-kubernetes-validations += | ||
[{"message": "label domain \\"karpenter.azure.com\\" is restricted", "rule": "%s"}]' "$rule" | ||
yq eval "${expr}" -i pkg/apis/crds/karpenter.sh_nodepools.yaml |
This file contains 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
This file contains 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