Skip to content

Commit

Permalink
Hydrate AMIFamily with AL2 when using nil in Provisioner
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathan-innis committed Oct 12, 2023
1 parent b2b2d97 commit d366610
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 40 deletions.
7 changes: 4 additions & 3 deletions tools/karpenter-convert/pkg/convert/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,18 +162,19 @@ func processNodeTemplate(resource runtime.Object) runtime.Object {
APIVersion: v1beta1.SchemeGroupVersion.String(),
}
nodeclass.Spec.Role = "<your AWS role here>"

// If the AMIFamily wasn't specified, then we know that it should be AL2 for the conversion
if nodeclass.Spec.AMIFamily == nil {
nodeclass.Spec.AMIFamily = &v1beta1.AMIFamilyAL2
}
return nodeclass
}

func processProvisioner(resource runtime.Object) runtime.Object {
provisioner := resource.(*v1alpha5.Provisioner)

nodepool := nodepoolutil.New(provisioner)
nodepool.TypeMeta = metav1.TypeMeta{
Kind: "NodePool",
APIVersion: corev1beta1.SchemeGroupVersion.String(),
}

return nodepool
}
9 changes: 8 additions & 1 deletion tools/karpenter-convert/pkg/convert/convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ var _ = Describe("ConvertObject", func() {
bytes, _ := os.ReadFile(tc.outputFile)
content := string(bytes)

Expect(buf.String()).To(ContainSubstring(content), fmt.Sprintf("unexpected output when converting %s to %q, expected: %q, but got %q", tc.file, tc.outputFile, content, buf.String()))
Expect(buf.String()).To(Equal(content), fmt.Sprintf("unexpected output when converting %s to %q, expected: %q, but got %q", tc.file, tc.outputFile, content, buf.String()))
},

Entry("provisioner to nodepool",
Expand All @@ -87,5 +87,12 @@ var _ = Describe("ConvertObject", func() {
outputFile: "./testdata/nodeclass.yaml",
},
),
Entry("nodetemplate (empty amifamily) to nodeclass",
testcase{
name: "nodetemplate (empty amifamily) to nodeclass",
file: "./testdata/nodetemplate_no_amifamily.yaml",
outputFile: "./testdata/nodeclass_no_amifamily.yaml",
},
),
)
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
apiVersion: karpenter.k8s.aws/v1beta1
kind: EC2NodeClass
metadata:
creationTimestamp: null
name: default
spec:
amiFamily: AL2
blockDeviceMappings:
- deviceName: /dev/xvdb
ebs:
deleteOnTermination: true
volumeSize: 100Gi
volumeType: gp3
role: <your AWS role here>
securityGroupSelectorTerms:
- tags:
karpenter.sh/discovery: karpenter-demo
subnetSelectorTerms:
- tags:
karpenter.sh/discovery: karpenter-demo
tags:
MyBackupTag: "yes"
MyTag: "1234"
userData: |
[settings.kubernetes]
kube-api-qps = 30
[settings.kubernetes.eviction-hard]
"memory.available" = "10%"
status: {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
apiVersion: karpenter.k8s.aws/v1alpha1
kind: AWSNodeTemplate
metadata:
name: default
spec:
subnetSelector:
karpenter.sh/discovery: karpenter-demo
securityGroupSelector:
karpenter.sh/discovery: karpenter-demo
blockDeviceMappings:
- deviceName: /dev/xvdb
ebs:
volumeSize: 100Gi
volumeType: gp3
deleteOnTermination: true
tags:
MyTag: "1234"
MyBackupTag: "yes"
userData: |
[settings.kubernetes]
kube-api-qps = 30
[settings.kubernetes.eviction-hard]
"memory.available" = "10%"
36 changes: 0 additions & 36 deletions tools/karpenter-convert/pkg/convert/testdata/provisioner.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,18 @@ kind: Provisioner
metadata:
name: default
spec:
# References cloud provider-specific custom resource, see your cloud provider specific documentation
providerRef:
name: default

# Provisioned nodes will have these taints
# Taints may prevent pods from scheduling if they are not tolerated by the pod.
taints:
- key: example.com/special-taint
effect: NoSchedule

# Provisioned nodes will have these taints, but pods do not need to tolerate these taints to be provisioned by this
# provisioner. These taints are expected to be temporary and some other entity (e.g. a DaemonSet) is responsible for
# removing the taint after it has finished initializing the node.
startupTaints:
- key: example.com/another-taint
effect: NoSchedule

# Labels are arbitrary key-values that are applied to all nodes
labels:
billing-team: my-team

# Annotations are arbitrary key-values that are applied to all nodes
annotations:
example.com/owner: "my-team"

# Requirements that constrain the parameters of provisioned nodes.
# These requirements are combined with pod.spec.affinity.nodeAffinity rules.
# Operators { In, NotIn, Exists, DoesNotExist, Gt, and Lt } are supported.
# https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/#operators
requirements:
- key: "karpenter.k8s.aws/instance-category"
operator: In
Expand All @@ -54,9 +37,6 @@ spec:
- key: "karpenter.sh/capacity-type" # If not included, the webhook for the AWS cloud provider will default to on-demand
operator: In
values: ["spot", "on-demand"]

# Karpenter provides the ability to specify a few additional Kubelet args.
# These are all optional and provide support for additional customization and use cases.
kubeletConfiguration:
clusterDNS: ["10.0.1.100"]
containerRuntime: containerd
Expand Down Expand Up @@ -86,28 +66,12 @@ spec:
cpuCFSQuota: true
podsPerCore: 2
maxPods: 20


# Resource limits constrain the total size of the cluster.
# Limits prevent Karpenter from creating new instances once the limit is exceeded.
limits:
resources:
cpu: "1000"
memory: 1000Gi

# Enables consolidation which attempts to reduce cluster cost by both removing un-needed nodes and down-sizing those
# that can't be removed. Mutually exclusive with the ttlSecondsAfterEmpty parameter.
consolidation:
enabled: false

# If omitted, the feature is disabled and nodes will never expire. If set to less time than it requires for a node
# to become ready, the node may expire before any pods successfully start.
ttlSecondsUntilExpired: 2592000 # 30 Days = 60 * 60 * 24 * 30 Seconds;

# If omitted, the feature is disabled, nodes will never scale down due to low utilization
ttlSecondsAfterEmpty: 30

# Priority given to the provisioner when the scheduler considers which provisioner
# to select. Higher weights indicate higher priority when comparing provisioners.
# Specifying no weight is equivalent to specifying a weight of 0.
weight: 10

0 comments on commit d366610

Please sign in to comment.