From c6cc769e46d7191a228fab79b25e1614c041fe0a Mon Sep 17 00:00:00 2001 From: Reed Schalo Date: Tue, 29 Oct 2024 00:20:40 -0700 Subject: [PATCH] fix: Cherry pick chart change v0.36.x (#7294) --- .../karpenter.k8s.aws_ec2nodeclasses.yaml | 2 + .../templates/karpenter.sh_nodeclaims.yaml | 2 + .../templates/karpenter.sh_nodepools.yaml | 2 + hack/mutation/conversion_webhook_injection.sh | 52 ++----------------- hack/mutation/ec2nodeclasses.sh | 26 ++++++++++ hack/mutation/nodeclaims.sh | 26 ++++++++++ hack/mutation/nodepools.sh | 26 ++++++++++ test/hack/e2e_scripts/install_karpenter.sh | 10 +++- 8 files changed, 97 insertions(+), 49 deletions(-) create mode 100755 hack/mutation/ec2nodeclasses.sh create mode 100755 hack/mutation/nodeclaims.sh create mode 100755 hack/mutation/nodepools.sh diff --git a/charts/karpenter-crd/templates/karpenter.k8s.aws_ec2nodeclasses.yaml b/charts/karpenter-crd/templates/karpenter.k8s.aws_ec2nodeclasses.yaml index 196008df8d4e..1549b7af2b86 100644 --- a/charts/karpenter-crd/templates/karpenter.k8s.aws_ec2nodeclasses.yaml +++ b/charts/karpenter-crd/templates/karpenter.k8s.aws_ec2nodeclasses.yaml @@ -19,6 +19,7 @@ spec: singular: ec2nodeclass scope: Cluster versions: +{{- if .Values.webhook.enabled }} - additionalPrinterColumns: - jsonPath: .status.conditions[?(@.type=="Ready")].status name: Ready @@ -735,6 +736,7 @@ spec: storage: false subresources: status: {} +{{- end }} - name: v1beta1 schema: openAPIV3Schema: diff --git a/charts/karpenter-crd/templates/karpenter.sh_nodeclaims.yaml b/charts/karpenter-crd/templates/karpenter.sh_nodeclaims.yaml index 30e69b7b05b0..c2d23c5582fc 100644 --- a/charts/karpenter-crd/templates/karpenter.sh_nodeclaims.yaml +++ b/charts/karpenter-crd/templates/karpenter.sh_nodeclaims.yaml @@ -16,6 +16,7 @@ spec: singular: nodeclaim scope: Cluster versions: +{{- if .Values.webhook.enabled }} - additionalPrinterColumns: - jsonPath: .metadata.labels.node\.kubernetes\.io/instance-type name: Type @@ -379,6 +380,7 @@ spec: storage: false subresources: status: {} +{{- end }} - additionalPrinterColumns: - jsonPath: .metadata.labels.node\.kubernetes\.io/instance-type name: Type diff --git a/charts/karpenter-crd/templates/karpenter.sh_nodepools.yaml b/charts/karpenter-crd/templates/karpenter.sh_nodepools.yaml index 4c0da732df93..62b1461e05f7 100644 --- a/charts/karpenter-crd/templates/karpenter.sh_nodepools.yaml +++ b/charts/karpenter-crd/templates/karpenter.sh_nodepools.yaml @@ -16,6 +16,7 @@ spec: singular: nodepool scope: Cluster versions: +{{- if .Values.webhook.enabled }} - additionalPrinterColumns: - jsonPath: .spec.template.spec.nodeClassRef.name name: NodeClass @@ -502,6 +503,7 @@ spec: storage: false subresources: status: {} +{{- end }} - additionalPrinterColumns: - jsonPath: .spec.template.spec.nodeClassRef.name name: NodeClass diff --git a/hack/mutation/conversion_webhook_injection.sh b/hack/mutation/conversion_webhook_injection.sh index ef57c2e6fd12..ec878cfdcbbc 100755 --- a/hack/mutation/conversion_webhook_injection.sh +++ b/hack/mutation/conversion_webhook_injection.sh @@ -6,54 +6,12 @@ yq eval '.spec.conversion = {"strategy": "Webhook", "webhook": {"conversionRevie yq eval '.spec.conversion = {"strategy": "Webhook", "webhook": {"conversionReviewVersions": ["v1beta1", "v1"], "clientConfig": {"service": {"name": "karpenter", "namespace": "kube-system", "port": 8443}}}}' -i pkg/apis/crds/karpenter.sh_nodepools.yaml # Update to the karpenter-crd charts - -# Remove the copied over conversion stanzas from CRD spec +# Remove the copied conversion stanzas from CRD specs yq eval 'del(.spec.conversion)' -i charts/karpenter-crd/templates/karpenter.k8s.aws_ec2nodeclasses.yaml yq eval 'del(.spec.conversion)' -i charts/karpenter-crd/templates/karpenter.sh_nodeclaims.yaml yq eval 'del(.spec.conversion)' -i charts/karpenter-crd/templates/karpenter.sh_nodepools.yaml -# Add the conversion stanza template to the CRD spec to enable conversion via webhook -echo "{{- if .Values.webhook.enabled }} - conversion: - strategy: Webhook - webhook: - conversionReviewVersions: - - v1beta1 - - v1 - clientConfig: - service: - name: {{ .Values.webhook.serviceName }} - namespace: {{ .Values.webhook.serviceNamespace | default .Release.Namespace }} - port: {{ .Values.webhook.port }} -{{- end }} -" >> charts/karpenter-crd/templates/karpenter.sh_nodepools.yaml - -echo "{{- if .Values.webhook.enabled }} - conversion: - strategy: Webhook - webhook: - conversionReviewVersions: - - v1beta1 - - v1 - clientConfig: - service: - name: {{ .Values.webhook.serviceName }} - namespace: {{ .Values.webhook.serviceNamespace | default .Release.Namespace }} - port: {{ .Values.webhook.port }} -{{- end }} -" >> charts/karpenter-crd/templates/karpenter.sh_nodeclaims.yaml - -echo "{{- if .Values.webhook.enabled }} - conversion: - strategy: Webhook - webhook: - conversionReviewVersions: - - v1beta1 - - v1 - clientConfig: - service: - name: {{ .Values.webhook.serviceName }} - namespace: {{ .Values.webhook.serviceNamespace | default .Release.Namespace }} - port: {{ .Values.webhook.port }} -{{- end }} -" >> charts/karpenter-crd/templates/karpenter.k8s.aws_ec2nodeclasses.yaml \ No newline at end of file +# Template the v1 version and the conversion strategy of the spec +hack/mutation/ec2nodeclasses.sh +hack/mutation/nodepools.sh +hack/mutation/nodeclaims.sh diff --git a/hack/mutation/ec2nodeclasses.sh b/hack/mutation/ec2nodeclasses.sh new file mode 100755 index 000000000000..5d442b182b67 --- /dev/null +++ b/hack/mutation/ec2nodeclasses.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env bash + +VERSION_START="$(cat charts/karpenter-crd/templates/karpenter.k8s.aws_ec2nodeclasses.yaml | yq '.spec.versions.[0] | line')" +VERSION_END="$(cat charts/karpenter-crd/templates/karpenter.k8s.aws_ec2nodeclasses.yaml | yq '.spec.versions.[1] | line')" +VERSION_END=$(($VERSION_END+1)) +TEMP=$(mktemp) + +cat charts/karpenter-crd/templates/karpenter.k8s.aws_ec2nodeclasses.yaml | awk -v n=$VERSION_START 'NR==n {sub(/$/,"\n{{- if .Values.webhook.enabled }}")} 1' \ +| awk -v n=$VERSION_END 'NR==n {sub(/$/,"\n{{- end }}")} 1' > $TEMP + +cat $TEMP > charts/karpenter-crd/templates/karpenter.k8s.aws_ec2nodeclasses.yaml + +echo "{{- if .Values.webhook.enabled }} + conversion: + strategy: Webhook + webhook: + conversionReviewVersions: + - v1beta1 + - v1 + clientConfig: + service: + name: {{ .Values.webhook.serviceName }} + namespace: {{ .Values.webhook.serviceNamespace | default .Release.Namespace }} + port: {{ .Values.webhook.port }} +{{- end }} +" >> charts/karpenter-crd/templates/karpenter.k8s.aws_ec2nodeclasses.yaml \ No newline at end of file diff --git a/hack/mutation/nodeclaims.sh b/hack/mutation/nodeclaims.sh new file mode 100755 index 000000000000..77afccdf8a47 --- /dev/null +++ b/hack/mutation/nodeclaims.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env bash + +VERSION_START="$(cat charts/karpenter-crd/templates/karpenter.sh_nodeclaims.yaml | yq '.spec.versions.[0] | line')" +VERSION_END="$(cat charts/karpenter-crd/templates/karpenter.sh_nodeclaims.yaml | yq '.spec.versions.[1] | line')" +VERSION_END=$(($VERSION_END+1)) +TEMP=$(mktemp) + +cat charts/karpenter-crd/templates/karpenter.sh_nodeclaims.yaml | awk -v n=$VERSION_START 'NR==n {sub(/$/,"\n{{- if .Values.webhook.enabled }}")} 1' \ +| awk -v n=$VERSION_END 'NR==n {sub(/$/,"\n{{- end }}")} 1' > $TEMP + +cat $TEMP > charts/karpenter-crd/templates/karpenter.sh_nodeclaims.yaml + +echo "{{- if .Values.webhook.enabled }} + conversion: + strategy: Webhook + webhook: + conversionReviewVersions: + - v1beta1 + - v1 + clientConfig: + service: + name: {{ .Values.webhook.serviceName }} + namespace: {{ .Values.webhook.serviceNamespace | default .Release.Namespace }} + port: {{ .Values.webhook.port }} +{{- end }} +" >> charts/karpenter-crd/templates/karpenter.sh_nodeclaims.yaml \ No newline at end of file diff --git a/hack/mutation/nodepools.sh b/hack/mutation/nodepools.sh new file mode 100755 index 000000000000..9ad1a6d279fa --- /dev/null +++ b/hack/mutation/nodepools.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env bash + +VERSION_START="$(cat charts/karpenter-crd/templates/karpenter.sh_nodepools.yaml | yq '.spec.versions.[0] | line')" +VERSION_END="$(cat charts/karpenter-crd/templates/karpenter.sh_nodepools.yaml | yq '.spec.versions.[1] | line')" +VERSION_END=$(($VERSION_END+1)) +TEMP=$(mktemp) + +cat charts/karpenter-crd/templates/karpenter.sh_nodepools.yaml | awk -v n=$VERSION_START 'NR==n {sub(/$/,"\n{{- if .Values.webhook.enabled }}")} 1' \ +| awk -v n=$VERSION_END 'NR==n {sub(/$/,"\n{{- end }}")} 1' > $TEMP + +cat $TEMP > charts/karpenter-crd/templates/karpenter.sh_nodepools.yaml + +echo "{{- if .Values.webhook.enabled }} + conversion: + strategy: Webhook + webhook: + conversionReviewVersions: + - v1beta1 + - v1 + clientConfig: + service: + name: {{ .Values.webhook.serviceName }} + namespace: {{ .Values.webhook.serviceNamespace | default .Release.Namespace }} + port: {{ .Values.webhook.port }} +{{- end }} +" >> charts/karpenter-crd/templates/karpenter.sh_nodepools.yaml \ No newline at end of file diff --git a/test/hack/e2e_scripts/install_karpenter.sh b/test/hack/e2e_scripts/install_karpenter.sh index da9a71266708..b70d37a7ad25 100755 --- a/test/hack/e2e_scripts/install_karpenter.sh +++ b/test/hack/e2e_scripts/install_karpenter.sh @@ -1,7 +1,13 @@ aws eks update-kubeconfig --name "$CLUSTER_NAME" -# Parse minor version to determine whether to enable the webhooks -K8S_VERSION_MINOR="${K8S_VERSION#*.}" +# First, conditionally install the webhook stanza and CRDs +if (( "$WEBHOOKS_ENABLED" == false )); then +helm upgrade --install karpenter-crd oci://$ECR_ACCOUNT_ID.dkr.ecr.$ECR_REGION.amazonaws.com/karpenter/snapshot/karpenter-crd \ + --namespace kube-system \ + --version "0-$(git rev-parse HEAD)" \ + --set webhook.enabled=${WEBHOOKS_ENABLED} \ + --wait +fi CHART="oci://$ECR_ACCOUNT_ID.dkr.ecr.$ECR_REGION.amazonaws.com/karpenter/snapshot/karpenter" ADDITIONAL_FLAGS=""