Skip to content

Commit

Permalink
Add templated crds for karpenter-crds
Browse files Browse the repository at this point in the history
  • Loading branch information
engedaam committed Aug 3, 2024
1 parent a04be71 commit 4dc5834
Show file tree
Hide file tree
Showing 11 changed files with 3,224 additions and 13 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ verify: tidy download ## Verify code. Includes dependencies, linting, formatting
hack/validation/requirements.sh
hack/validation/labels.sh
hack/validation/kubelet.sh
cp pkg/apis/crds/* charts/karpenter-crd/templates
hack/mutation/conversion_webhook_injection.sh
hack/github/dependabot.sh
# $(foreach dir,$(MOD_DIRS),cd $(dir) && golangci-lint run $(newline))
Expand Down

This file was deleted.

1,295 changes: 1,295 additions & 0 deletions charts/karpenter-crd/templates/karpenter.k8s.aws_ec2nodeclasses.yaml

Large diffs are not rendered by default.

This file was deleted.

825 changes: 825 additions & 0 deletions charts/karpenter-crd/templates/karpenter.sh_nodeclaims.yaml

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion charts/karpenter-crd/templates/karpenter.sh_nodepools.yaml

This file was deleted.

1,035 changes: 1,035 additions & 0 deletions charts/karpenter-crd/templates/karpenter.sh_nodepools.yaml

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions charts/karpenter-crd/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
webhook:
# -- Whether to enable the webhooks and webhook permissions.
enabled: true
serviceName: karpenter
serviceNamespace: kube-system
# -- The container port to use for the webhook.
port: 8443
2 changes: 1 addition & 1 deletion charts/karpenter/templates/post-install-hook.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ spec:
{{- end }}
containers:
- name: post-install-job
image: bitnami/kubectl:latest
image: public.ecr.aws/bitnami/kubectl:1.30
command:
- /bin/sh
- -c
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.22.2

toolchain go1.22.5

replace sigs.k8s.io/karpenter => github.com/engedaam/karpenter-core v0.0.0-20240731110015-cf5df0e1765c
replace sigs.k8s.io/karpenter => github.com/engedaam/karpenter-core v0.0.0-20240803134318-11b0c1bc3e8a

require (
github.com/Pallinder/go-randomdata v1.2.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/emicklei/go-restful/v3 v3.11.0 h1:rAQeMHw1c7zTmncogyy8VvRZwtkmkZ4FxERmMY4rD+g=
github.com/emicklei/go-restful/v3 v3.11.0/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc=
github.com/engedaam/karpenter-core v0.0.0-20240731110015-cf5df0e1765c h1:Tu4vy/M2DkmB0WrYUuDD9uAc/s5t01ZloWESzFdrD7c=
github.com/engedaam/karpenter-core v0.0.0-20240731110015-cf5df0e1765c/go.mod h1:vZfbuD5UQJfNdaNwiUVgCUJ/yYOVjYbKosr8b971CAM=
github.com/engedaam/karpenter-core v0.0.0-20240803134318-11b0c1bc3e8a h1:axJFTrB5Ne3Qlvkybr8i7Mxmu14vYsevPVmf3iJacp4=
github.com/engedaam/karpenter-core v0.0.0-20240803134318-11b0c1bc3e8a/go.mod h1:vZfbuD5UQJfNdaNwiUVgCUJ/yYOVjYbKosr8b971CAM=
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
Expand Down
50 changes: 49 additions & 1 deletion hack/mutation/conversion_webhook_injection.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,52 @@
# 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
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

# Add the conversion stanza 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 }}
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 }}
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 }}
port: {{ .Values.webhook.port }}
{{- end }}
" >> charts/karpenter-crd/templates/karpenter.k8s.aws_ec2nodeclasses.yaml
11 changes: 7 additions & 4 deletions pkg/apis/crds/karpenter.sh_nodepools.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,13 @@ spec:
pattern: ^(([0-9]+(s|m|h))+)|(Never)$
type: string
consolidationPolicy:
default: WhenUnderutilized
default: WhenEmptyOrUnderutilized
description: |-
ConsolidationPolicy describes which nodes Karpenter can disrupt through its consolidation
algorithm. This policy defaults to "WhenUnderutilized" if not specified
algorithm. This policy defaults to "WhenEmptyOrUnderutilized" if not specified
enum:
- WhenEmpty
- WhenUnderutilized
- WhenEmptyOrUnderutilized
type: string
required:
- consolidateAfter
Expand Down Expand Up @@ -208,7 +208,10 @@ spec:
rule: self.all(x, x in ["karpenter.k8s.aws/instance-encryption-in-transit-supported", "karpenter.k8s.aws/instance-category", "karpenter.k8s.aws/instance-hypervisor", "karpenter.k8s.aws/instance-family", "karpenter.k8s.aws/instance-generation", "karpenter.k8s.aws/instance-local-nvme", "karpenter.k8s.aws/instance-size", "karpenter.k8s.aws/instance-cpu","karpenter.k8s.aws/instance-memory", "karpenter.k8s.aws/instance-network-bandwidth", "karpenter.k8s.aws/instance-gpu-name", "karpenter.k8s.aws/instance-gpu-manufacturer", "karpenter.k8s.aws/instance-gpu-count", "karpenter.k8s.aws/instance-gpu-memory", "karpenter.k8s.aws/instance-accelerator-name", "karpenter.k8s.aws/instance-accelerator-manufacturer", "karpenter.k8s.aws/instance-accelerator-count"] || !x.find("^([^/]+)").endsWith("karpenter.k8s.aws"))
type: object
spec:
description: NodeClaimSpec describes the desired state of the NodeClaim
description: |-
NodeClaimTemplateSpec describes the desired state of the NodeClaim in the Nodepool
NodeClaimTemplateSpec is used in the NodePool's NodeClaimTemplate, with the resource requests omitted since
users are not able to set resource requests in the NodePool.
properties:
expireAfter:
default: 720h
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/v1/nodepool_validation_cel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ var _ = Describe("CEL/Validation", func() {
ObjectMeta: metav1.ObjectMeta{Name: strings.ToLower(randomdata.SillyName())},
Spec: karpv1.NodePoolSpec{
Template: karpv1.NodeClaimTemplate{
Spec: karpv1.NodeClaimSpec{
Spec: karpv1.NodeClaimTemplateSpec{
NodeClassRef: &karpv1.NodeClassReference{
Group: "karpenter.k8s.aws",
Kind: "EC2NodeClass",
Expand Down

0 comments on commit 4dc5834

Please sign in to comment.