Skip to content

Commit

Permalink
chore: drop validation webhooks and enable conversion webhooks (#6488)
Browse files Browse the repository at this point in the history
Co-authored-by: Amanuel Engeda <[email protected]>
  • Loading branch information
jmdeal and engedaam authored Jul 11, 2024
1 parent 092e0ae commit 9a54e8e
Show file tree
Hide file tree
Showing 22 changed files with 51 additions and 1,894 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ verify: tidy download ## Verify code. Includes dependencies, linting, formatting
hack/validation/kubelet.sh
hack/validation/requirements.sh
hack/validation/labels.sh
hack/mutation/conversion_webhooks_injection.sh
hack/github/dependabot.sh
$(foreach dir,$(MOD_DIRS),cd $(dir) && golangci-lint run $(newline))
@git diff --quiet ||\
Expand Down
1 change: 0 additions & 1 deletion charts/karpenter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ cosign verify public.ecr.aws/karpenter/karpenter:0.37.0 \
| terminationGracePeriodSeconds | string | `nil` | Override the default termination grace period for the pod. |
| tolerations | list | `[{"key":"CriticalAddonsOnly","operator":"Exists"}]` | Tolerations to allow the pod to be scheduled to nodes with taints. |
| topologySpreadConstraints | list | `[{"maxSkew":1,"topologyKey":"topology.kubernetes.io/zone","whenUnsatisfiable":"DoNotSchedule"}]` | Topology spread constraints to increase the controller resilience by distributing pods across the cluster zones. If an explicit label selector is not provided one will be created from the pod selector labels. |
| webhook.enabled | bool | `false` | Whether to enable the webhooks and webhook permissions. |
| webhook.metrics.port | int | `8001` | The container port to use for webhook metrics. |
| webhook.port | int | `8443` | The container port to use for the webhook. |

Expand Down
17 changes: 6 additions & 11 deletions charts/karpenter/templates/clusterrole-core.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,9 @@ rules:
- apiGroups: ["apps"]
resources: ["daemonsets", "deployments", "replicasets", "statefulsets"]
verbs: ["list", "watch"]
{{- if .Values.webhook.enabled }}
- apiGroups: ["admissionregistration.k8s.io"]
resources: ["validatingwebhookconfigurations", "mutatingwebhookconfigurations"]
verbs: ["get", "watch", "list"]
{{- end }}
- apiGroups: ["apiextensions.k8s.io"]
resources: ["customresourcedefinitions"]
verbs: ["watch", "list"]
- apiGroups: ["policy"]
resources: ["poddisruptionbudgets"]
verbs: ["get", "list", "watch"]
Expand All @@ -65,12 +63,9 @@ rules:
- apiGroups: [""]
resources: ["pods/eviction"]
verbs: ["create"]
{{- if .Values.webhook.enabled }}
- apiGroups: ["admissionregistration.k8s.io"]
resources: ["validatingwebhookconfigurations"]
- apiGroups: ["apiextensions.k8s.io"]
resources: ["customresourcedefinitions"]
verbs: ["update"]
resourceNames: ["validation.webhook.karpenter.sh", "validation.webhook.config.karpenter.sh"]
{{- end }}
{{- with .Values.additionalClusterRoleRules -}}
{{ toYaml . | nindent 2 }}
{{- end -}}
{{- end -}}
10 changes: 0 additions & 10 deletions charts/karpenter/templates/clusterrole.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,3 @@ rules:
- apiGroups: ["karpenter.k8s.aws"]
resources: ["ec2nodeclasses", "ec2nodeclasses/status"]
verbs: ["patch", "update"]
{{- if .Values.webhook.enabled }}
- apiGroups: ["admissionregistration.k8s.io"]
resources: ["validatingwebhookconfigurations"]
verbs: ["update"]
resourceNames: ["validation.webhook.karpenter.k8s.aws"]
- apiGroups: ["admissionregistration.k8s.io"]
resources: ["mutatingwebhookconfigurations"]
verbs: ["update"]
resourceNames: ["defaulting.webhook.karpenter.k8s.aws"]
{{- end }}
6 changes: 0 additions & 6 deletions charts/karpenter/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,10 @@ spec:
value: "1.19.0-0"
- name: KARPENTER_SERVICE
value: {{ include "karpenter.fullname" . }}
{{- if .Values.webhook.enabled }}
- name: WEBHOOK_PORT
value: "{{ .Values.webhook.port }}"
- name: WEBHOOK_METRICS_PORT
value: "{{ .Values.webhook.metrics.port }}"
- name: DISABLE_WEBHOOK
value: "false"
{{- end }}
{{- with .Values.logLevel }}
- name: LOG_LEVEL
value: "{{ . }}"
Expand Down Expand Up @@ -159,14 +155,12 @@ spec:
- name: http-metrics
containerPort: {{ .Values.controller.metrics.port }}
protocol: TCP
{{- if .Values.webhook.enabled }}
- name: webhook-metrics
containerPort: {{ .Values.webhook.metrics.port }}
protocol: TCP
- name: https-webhook
containerPort: {{ .Values.webhook.port }}
protocol: TCP
{{- end }}
- name: http
containerPort: {{ .Values.controller.healthProbe.port }}
protocol: TCP
Expand Down
6 changes: 1 addition & 5 deletions charts/karpenter/templates/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,15 @@ rules:
- apiGroups: ["coordination.k8s.io"]
resources: ["leases"]
verbs: ["get", "watch"]
{{- if .Values.webhook.enabled }}
- apiGroups: [""]
resources: ["configmaps", "secrets"]
verbs: ["get", "list", "watch"]
{{- end }}
# Write
{{- if .Values.webhook.enabled }}
- apiGroups: [""]
resources: ["secrets"]
verbs: ["update"]
resourceNames:
- "{{ include "karpenter.fullname" . }}-cert"
{{- end }}
- apiGroups: ["coordination.k8s.io"]
resources: ["leases"]
verbs: ["patch", "update"]
Expand Down Expand Up @@ -75,4 +71,4 @@ rules:
# Write
- apiGroups: ["coordination.k8s.io"]
resources: ["leases"]
verbs: ["delete"]
verbs: ["delete"]
2 changes: 0 additions & 2 deletions charts/karpenter/templates/secret-webhook-cert.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{{- if .Values.webhook.enabled }}
apiVersion: v1
kind: Secret
metadata:
Expand All @@ -11,4 +10,3 @@ metadata:
{{- toYaml . | nindent 4 }}
{{- end }}
# data: {} # Injected by karpenter-webhook
{{- end }}
2 changes: 0 additions & 2 deletions charts/karpenter/templates/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ spec:
port: {{ .Values.controller.metrics.port }}
targetPort: http-metrics
protocol: TCP
{{- if .Values.webhook.enabled }}
- name: webhook-metrics
port: {{ .Values.webhook.metrics.port }}
targetPort: webhook-metrics
Expand All @@ -25,6 +24,5 @@ spec:
port: {{ .Values.webhook.port }}
targetPort: https-webhook
protocol: TCP
{{- end }}
selector:
{{- include "karpenter.selectorLabels" . | nindent 4 }}
69 changes: 0 additions & 69 deletions charts/karpenter/templates/webhooks-core.yaml

This file was deleted.

67 changes: 0 additions & 67 deletions charts/karpenter/templates/webhooks.yaml

This file was deleted.

6 changes: 2 additions & 4 deletions charts/karpenter/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ serviceMonitor:
enabled: false
# -- Additional labels for the ServiceMonitor.
additionalLabels: {}
# -- Configuration on `http-metrics` endpoint for the ServiceMonitor.
# Not to be used to add additional endpoints.
# -- Configuration on `http-metrics` endpoint for the ServiceMonitor.
# Not to be used to add additional endpoints.
# See the Prometheus operator documentation for configurable fields https://github.com/prometheus-operator/prometheus-operator/blob/main/Documentation/api.md#endpoint
endpointConfig: {}
# -- Number of replicas.
Expand Down Expand Up @@ -138,8 +138,6 @@ controller:
# -- The container port to use for http health probe.
port: 8081
webhook:
# -- Whether to enable the webhooks and webhook permissions.
enabled: false
# -- The container port to use for the webhook.
port: 8443
metrics:
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ require (
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/swag v0.22.4 // indirect
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
github.com/gobuffalo/flect v1.0.2 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.4 // indirect
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,6 @@ github.com/go-openapi/swag v0.22.4/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/go-task/slim-sprig/v3 v3.0.0 h1:sUs3vkvUymDpBKi3qH1YSqBQk9+9D/8M2mN1vB6EwHI=
github.com/go-task/slim-sprig/v3 v3.0.0/go.mod h1:W848ghGpv3Qj3dhTPRyJypKRiqCdHZiAzKg9hl15HA8=
github.com/gobuffalo/flect v1.0.2 h1:eqjPGSo2WmjgY2XlpGwo2NXgL3RucAKo4k4qQMNA5sA=
github.com/gobuffalo/flect v1.0.2/go.mod h1:A5msMlrHtLqh9umBSnvabjsMrCcCpAyzglnDvkbYKHs=
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
Expand Down
6 changes: 6 additions & 0 deletions hack/mutation/conversion_webhooks_injection.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash

# Add the conversion stanza to the CRD spec to enable conversion via webhook
yq eval '.spec.conversion = {"strategy": "Webhook", "webhook": {"conversionReviewVersions": ["v1beta1", "v1"], "clientConfig": {"service": {"name": "karpenter", "namespace": "kube-system", "port": 8443}}}}' -i pkg/apis/crds/karpenter.k8s.aws_ec2nodeclasses.yaml
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_nodeclaims.yaml
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
11 changes: 11 additions & 0 deletions pkg/apis/crds/karpenter.k8s.aws_ec2nodeclasses.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1296,3 +1296,14 @@ spec:
storage: true
subresources:
status: {}
conversion:
strategy: Webhook
webhook:
conversionReviewVersions:
- v1beta1
- v1
clientConfig:
service:
name: karpenter
namespace: kube-system
port: 8443
11 changes: 11 additions & 0 deletions pkg/apis/crds/karpenter.sh_nodeclaims.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -793,3 +793,14 @@ spec:
storage: true
subresources:
status: {}
conversion:
strategy: Webhook
webhook:
conversionReviewVersions:
- v1beta1
- v1
clientConfig:
service:
name: karpenter
namespace: kube-system
port: 8443
11 changes: 11 additions & 0 deletions pkg/apis/crds/karpenter.sh_nodepools.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1071,3 +1071,14 @@ spec:
storage: true
subresources:
status: {}
conversion:
strategy: Webhook
webhook:
conversionReviewVersions:
- v1beta1
- v1
clientConfig:
service:
name: karpenter
namespace: kube-system
port: 8443
Loading

0 comments on commit 9a54e8e

Please sign in to comment.