Skip to content

Commit f343151

Browse files
committed
feat: Support add data disks for storing container data and images
1 parent a8e99d9 commit f343151

File tree

6 files changed

+23
-6
lines changed

6 files changed

+23
-6
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,17 @@ spec:
7070
type: string
7171
type: object
7272
type: array
73+
formatDataDisk:
74+
default: false
75+
description: FormatDataDisk specifies whether to mount data disks
76+
to an existing instance when adding it to the cluster. This allows
77+
you to add data disks for storing container data and images. If
78+
FormatDataDisk is set to true, and the Elastic Compute Service (ECS)
79+
instances already have data disks mounted, but the file system on
80+
the last data disk is not initialized, the system will automatically
81+
format the disk to ext4 and mount it to /var/lib/containerd and
82+
/var/lib/kubelet.
83+
type: boolean
7384
imageSelectorTerms:
7485
description: ImageSelectorTerms is a list of or image selector terms.
7586
The terms are ORed.

pkg/apis/v1alpha1/ecsnodeclass.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ type ECSNodeClassSpec struct {
8383
// +kubebuilder:validation:Items=Enum=cloud;cloud_efficiency;cloud_ssd;cloud_essd;cloud_auto;cloud_essd_entry
8484
// +optional
8585
DataDisksCategories []string `json:"dataDiskCategories,omitempty"`
86+
// FormatDataDisk specifies whether to mount data disks to an existing instance when adding it to the cluster. This allows you to add data disks for storing container data and images. If FormatDataDisk is set to true, and the Elastic Compute Service (ECS) instances already have data disks mounted, but the file system on the last data disk is not initialized, the system will automatically format the disk to ext4 and mount it to /var/lib/containerd and /var/lib/kubelet.
87+
// +kubebuilder:default:=false
88+
// +optional
89+
FormatDataDisk bool `json:"formatDataDisk,omitempty"`
8690
// Tags to be applied on ecs resources like instances and launch templates.
8791
// +kubebuilder:validation:XValidation:message="empty tag keys aren't supported",rule="self.all(k, k != '')"
8892
// +kubebuilder:validation:XValidation:message="tag contains a restricted tag matching ecs:ecs-cluster-name",rule="self.all(k, k !='ecs:ecs-cluster-name')"

pkg/providers/cluster/ackmanaged.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,10 @@ func (a *ACKManaged) UserData(ctx context.Context,
142142
labels map[string]string,
143143
taints []corev1.Taint,
144144
kubeletCfg *v1alpha1.KubeletConfiguration,
145-
userData *string) (string, error) {
145+
userData *string,
146+
formatDataDisk bool) (string, error) {
146147

147-
attach, err := a.getClusterAttachScripts(ctx)
148+
attach, err := a.getClusterAttachScripts(formatDataDisk, ctx)
148149
if err != nil {
149150
return "", err
150151
}
@@ -174,13 +175,14 @@ func (a *ACKManaged) FeatureFlags() FeatureFlags {
174175
}
175176
}
176177

177-
func (a *ACKManaged) getClusterAttachScripts(ctx context.Context) (string, error) {
178+
func (a *ACKManaged) getClusterAttachScripts(formatDataDisk bool, ctx context.Context) (string, error) {
178179
if cachedScript, ok := a.cache.Get(a.clusterID); ok {
179180
return cachedScript.(string), nil
180181
}
181182

182183
reqPara := &ackclient.DescribeClusterAttachScriptsRequest{
183184
KeepInstanceName: tea.Bool(true),
185+
FormatDisk: tea.Bool(formatDataDisk),
184186
}
185187
resp, err := a.ackClient.DescribeClusterAttachScripts(tea.String(a.clusterID), reqPara)
186188
if err != nil {

pkg/providers/cluster/custom.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func NewCustom() *Custom {
3434
return &Custom{}
3535
}
3636

37-
func (c *Custom) UserData(ctx context.Context, labels map[string]string, taints []corev1.Taint, configuration *v1alpha1.KubeletConfiguration, userData *string) (string, error) {
37+
func (c *Custom) UserData(ctx context.Context, labels map[string]string, taints []corev1.Taint, configuration *v1alpha1.KubeletConfiguration, userData *string, formatDataDisk bool) (string, error) {
3838
return base64.StdEncoding.EncodeToString([]byte(lo.FromPtr(userData))), nil
3939
}
4040

pkg/providers/cluster/types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ type Image struct {
5353
// Provider can be implemented to generate userdata
5454
type Provider interface {
5555
ClusterType() string
56-
UserData(context.Context, map[string]string, []corev1.Taint, *v1alpha1.KubeletConfiguration, *string) (string, error)
56+
UserData(context.Context, map[string]string, []corev1.Taint, *v1alpha1.KubeletConfiguration, *string, bool) (string, error)
5757
GetClusterCNI(context.Context) (string, error)
5858
LivenessProbe(*http.Request) error
5959
GetSupportedImages(string) ([]Image, error)

pkg/providers/instance/instance.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,7 @@ func (p *DefaultProvider) buildUserData(ctx context.Context, capacityType string
688688
}) {
689689
taints = append(taints, karpv1.UnregisteredNoExecuteTaint)
690690
}
691-
return p.clusterProvider.UserData(ctx, labels, taints, kubeletCfg, nodeClass.Spec.UserData)
691+
return p.clusterProvider.UserData(ctx, labels, taints, kubeletCfg, nodeClass.Spec.UserData, nodeClass.Spec.FormatDataDisk)
692692
}
693693

694694
func resolveKubeletConfiguration(nodeClass *v1alpha1.ECSNodeClass) *v1alpha1.KubeletConfiguration {

0 commit comments

Comments
 (0)