Skip to content

Commit 54ca9f1

Browse files
Merge pull request #218 from kaiiyvwu/main
support set password and key pair in ecs node class
2 parents 94b7467 + 296c3d3 commit 54ca9f1

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

charts/karpenter/crds/karpenter.k8s.alibabacloud_ecsnodeclasses.yaml

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
33
kind: CustomResourceDefinition
44
metadata:
55
annotations:
6-
controller-gen.kubebuilder.io/version: v0.16.4
6+
controller-gen.kubebuilder.io/version: v0.17.3
77
name: ecsnodeclasses.karpenter.k8s.alibabacloud
88
spec:
99
group: karpenter.k8s.alibabacloud
@@ -113,6 +113,11 @@ spec:
113113
- message: '''alias'' is mutually exclusive, cannot be set with a
114114
combination of other imageSelectorTerms'
115115
rule: '!(self.exists(x, has(x.alias)) && self.size() != 1)'
116+
keyPairName:
117+
description: KeyPairName is the key pair used when creating an ECS
118+
instance for root.
119+
pattern: ^[A-Za-z][A-Za-z\d._:-]{1,127}$
120+
type: string
116121
kubeletConfiguration:
117122
description: |-
118123
KubeletConfiguration defines args to be used when configuring kubelet on provisioned nodes.
@@ -236,6 +241,15 @@ spec:
236241
evictionSoft
237242
rule: has(self.evictionSoftGracePeriod) ? self.evictionSoftGracePeriod.all(e,
238243
(e in self.evictionSoft)):true
244+
password:
245+
description: Password is the password for ecs for root.
246+
pattern: ^[A-Za-z\d~!@#$%^&*()_+\-=\[\]{}|\\:;"'<>,.?/]{8,30}$
247+
type: string
248+
passwordInherit:
249+
default: false
250+
description: If PasswordInherit is true will use the password preset
251+
by os image.
252+
type: boolean
239253
resourceGroupId:
240254
description: ResourceGroupID is the resource group id in ECS
241255
pattern: rg-[0-9a-z]+
@@ -402,6 +416,10 @@ spec:
402416
- securityGroupSelectorTerms
403417
- vSwitchSelectorTerms
404418
type: object
419+
x-kubernetes-validations:
420+
- message: password cannot be set when passwordInherit is true
421+
rule: '!(has(self.passwordInherit) ? (self.passwordInherit ? has(self.password)
422+
: false) : false)'
405423
status:
406424
description: ECSNodeClassStatus contains the resolved state of the ECSNodeClass
407425
properties:

pkg/apis/v1alpha1/ecsnodeclass.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ const (
3131

3232
// ECSNodeClassSpec is the top level specification for the AlibabaCloud Karpenter Provider.
3333
// This will contain the configuration necessary to launch instances in AlibabaCloud.
34+
// +kubebuilder:validation:XValidation:rule="!(has(self.passwordInherit) ? (self.passwordInherit ? has(self.password) : false) : false)",message="password cannot be set when passwordInherit is true"
3435
type ECSNodeClassSpec struct {
3536
// VSwitchSelectorTerms is a list of or vSwitch selector terms. The terms are ORed.
3637
// +kubebuilder:validation:XValidation:message="vSwitchSelectorTerms cannot be empty",rule="self.size() != 0"
@@ -96,6 +97,18 @@ type ECSNodeClassSpec struct {
9697
// UserData to be applied to the provisioned nodes and executed before/after the node is registered.
9798
// +optional
9899
UserData *string `json:"userData,omitempty"`
100+
// Password is the password for ecs for root.
101+
// +kubebuilder:validation:Pattern=`^[A-Za-z\d~!@#$%^&*()_+\-=\[\]{}|\\:;"'<>,.?/]{8,30}$`
102+
//+optional
103+
Password string `json:"password,omitempty"`
104+
// KeyPairName is the key pair used when creating an ECS instance for root.
105+
// +kubebuilder:validation:Pattern=`^[A-Za-z][A-Za-z\d._:-]{1,127}$`
106+
// +optional
107+
KeyPairName string `json:"keyPairName,omitempty"`
108+
// If PasswordInherit is true will use the password preset by os image.
109+
// +kubebuilder:default:=false
110+
// +optional
111+
PasswordInherit bool `json:"passwordInherit,omitempty"`
99112
}
100113

101114
// VSwitchSelectorTerm defines selection logic for a vSwitch used by Karpenter to launch nodes.

pkg/providers/instance/instance.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,9 @@ func (p *DefaultProvider) getProvisioningGroup(ctx context.Context, nodeClass *v
581581
SecurityGroupIds: securityGroupIDs,
582582
SystemDiskSize: tea.Int32(systemDisk.GetGiBSize()),
583583
Tag: reqTags,
584+
KeyPairName: tea.String(nodeClass.Spec.KeyPairName),
585+
Password: tea.String(nodeClass.Spec.Password),
586+
PasswordInherit: tea.Bool(nodeClass.Spec.PasswordInherit),
584587
},
585588
// Add this tag to auto-provisioning-group, alibabacloud will monitor the requests and enhance the stability
586589
Tag: []*ecsclient.CreateAutoProvisioningGroupRequestTag{

0 commit comments

Comments
 (0)