Skip to content

Commit 94b7467

Browse files
Merge pull request #216 from jwcesign/vs
fix: fix volumesize modification
2 parents ba78454 + 6914b8a commit 94b7467

File tree

8 files changed

+65
-55
lines changed

8 files changed

+65
-55
lines changed

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

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,13 @@ spec:
6161
device:
6262
description: Mount point of the data disk.
6363
type: string
64-
size:
64+
volumeSize:
65+
default: 20Gi
6566
description: |-
66-
The size of the data disk. Unit: GiB.
67-
Valid values:
68-
* If you set Category to cloud: 20 to 500.
69-
* If you set Category to other disk categories: 20 to 2048.
70-
format: int32
71-
type: integer
72-
x-kubernetes-validations:
73-
- message: size invalid
74-
rule: self >= 20
67+
Size in `Gi`, `G`, `Ti`, or `T`. You must specify either a snapshot ID or
68+
a volume size.
69+
pattern: ^((?:[1-9][0-9]{0,3}|[1-4][0-9]{4}|[5][0-8][0-9]{3}|59000)Gi|(?:[1-9][0-9]{0,3}|[1-5][0-9]{4}|[6][0-3][0-9]{3}|64000)G|([1-9]||[1-5][0-7]|58)Ti|([1-9]||[1-5][0-9]|6[0-3]|64)T)$
70+
type: string
7571
type: object
7672
type: array
7773
imageSelectorTerms:
@@ -321,7 +317,6 @@ spec:
321317
- PL3
322318
type: string
323319
size:
324-
default: 20
325320
description: |-
326321
The size of the system disk. Unit: GiB.
327322
Valid values:
@@ -335,16 +330,7 @@ spec:
335330
volumeSize:
336331
description: |-
337332
Size in `Gi`, `G`, `Ti`, or `T`. You must specify either a snapshot ID or
338-
a volume size. The following are the supported volumes sizes for each volume
339-
type:
340-
341-
* gp2 and gp3: 1-16,384
342-
343-
* io1 and io2: 4-16,384
344-
345-
* st1 and sc1: 125-16,384
346-
347-
* standard: 1-1,024
333+
a volume size.
348334
pattern: ^((?:[1-9][0-9]{0,3}|[1-4][0-9]{4}|[5][0-8][0-9]{3}|59000)Gi|(?:[1-9][0-9]{0,3}|[1-5][0-9]{4}|[6][0-3][0-9]{3}|64000)G|([1-9]||[1-5][0-7]|58)Ti|([1-9]||[1-5][0-9]|6[0-3]|64)T)$
349335
type: string
350336
type: object

examples/nodepool/ecsnodeclass.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,12 @@ spec:
1212
systemDisk:
1313
categories:
1414
- cloud
15+
- cloud_efficiency
1516
- cloud_ssd
17+
- cloud_essd
1618
- cloud_auto
17-
size: 60
19+
- cloud_essd_entry
20+
volumeSize: 60Gi
1821
imageSelectorTerms:
1922
# ContainerOS only support x86_64 linux nodes, and it's faster to initialize
2023
- alias: ContainerOS

pkg/apis/v1alpha1/ecsnodeclass.go

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -226,16 +226,7 @@ type SystemDisk struct {
226226
// +optional
227227
Categories []string `json:"categories,omitempty"`
228228
// Size in `Gi`, `G`, `Ti`, or `T`. You must specify either a snapshot ID or
229-
// a volume size. The following are the supported volumes sizes for each volume
230-
// type:
231-
//
232-
// * gp2 and gp3: 1-16,384
233-
//
234-
// * io1 and io2: 4-16,384
235-
//
236-
// * st1 and sc1: 125-16,384
237-
//
238-
// * standard: 1-1,024
229+
// a volume size.
239230
// + TODO: Add the CEL resources.quantity type after k8s 1.29
240231
// + https://github.com/kubernetes/apiserver/commit/b137c256373aec1c5d5810afbabb8932a19ecd2a#diff-838176caa5882465c9d6061febd456397a3e2b40fb423ed36f0cabb1847ecb4dR190
241232
// +kubebuilder:validation:Pattern:="^((?:[1-9][0-9]{0,3}|[1-4][0-9]{4}|[5][0-8][0-9]{3}|59000)Gi|(?:[1-9][0-9]{0,3}|[1-5][0-9]{4}|[6][0-3][0-9]{3}|64000)G|([1-9]||[1-5][0-7]|58)Ti|([1-9]||[1-5][0-9]|6[0-3]|64)T)$"
@@ -249,7 +240,6 @@ type SystemDisk struct {
249240
// * If you set Category to other disk categories: 20 to 2048.
250241
//
251242
// +kubebuilder:validation:XValidation:message="size invalid",rule="self >= 20"
252-
// +kubebuilder:default:=20
253243
// +optional
254244
Size *int32 `json:"size,omitempty"`
255245
// The performance level of the ESSD to use as the system disk. Default value: PL0.
@@ -265,13 +255,16 @@ type SystemDisk struct {
265255
}
266256

267257
type DataDisk struct {
268-
// The size of the data disk. Unit: GiB.
269-
// Valid values:
270-
// * If you set Category to cloud: 20 to 500.
271-
// * If you set Category to other disk categories: 20 to 2048.
272-
//
273-
// +kubebuilder:validation:XValidation:message="size invalid",rule="self >= 20"
274-
Size *int32 `json:"size,omitempty"`
258+
// Size in `Gi`, `G`, `Ti`, or `T`. You must specify either a snapshot ID or
259+
// a volume size.
260+
// + TODO: Add the CEL resources.quantity type after k8s 1.29
261+
// + https://github.com/kubernetes/apiserver/commit/b137c256373aec1c5d5810afbabb8932a19ecd2a#diff-838176caa5882465c9d6061febd456397a3e2b40fb423ed36f0cabb1847ecb4dR190
262+
// +kubebuilder:validation:Pattern:="^((?:[1-9][0-9]{0,3}|[1-4][0-9]{4}|[5][0-8][0-9]{3}|59000)Gi|(?:[1-9][0-9]{0,3}|[1-5][0-9]{4}|[6][0-3][0-9]{3}|64000)G|([1-9]||[1-5][0-7]|58)Ti|([1-9]||[1-5][0-9]|6[0-3]|64)T)$"
263+
// +kubebuilder:validation:Schemaless
264+
// +kubebuilder:validation:Type:=string
265+
// +kubebuilder:default:="20Gi"
266+
// +optional
267+
VolumeSize *resource.Quantity `json:"volumeSize,omitempty" hash:"string"`
275268
// Mount point of the data disk.
276269
// +optional
277270
Device *string `json:"device,omitempty"`
@@ -331,3 +324,20 @@ type ECSNodeClassList struct {
331324
func ImageFamilyFromAlias(alias string) string {
332325
return alias
333326
}
327+
328+
func (sd *SystemDisk) GetGiBSize() int32 {
329+
if sd.VolumeSize != nil {
330+
return int32(sd.VolumeSize.Value() / (1024 * 1024 * 1024)) // #nosec G115
331+
}
332+
if sd.Size != nil {
333+
return *sd.Size
334+
}
335+
return 0
336+
}
337+
338+
func (dd *DataDisk) GetGiBSize() int32 {
339+
if dd.VolumeSize != nil {
340+
return int32(dd.VolumeSize.Value() / (1024 * 1024 * 1024)) // #nosec G115
341+
}
342+
return 0
343+
}

pkg/apis/v1alpha1/zz_generated.deepcopy.go

Lines changed: 9 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/controllers/nodeclass/volumesize/controller.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ func (c *Controller) Reconcile(ctx context.Context, nodeClass *v1alpha1.ECSNodeC
4949
stored := nodeClass.DeepCopy()
5050

5151
if nodeClass.Spec.SystemDisk != nil &&
52-
nodeClass.Spec.SystemDisk.Size != nil {
53-
nodeClass.Spec.SystemDisk.VolumeSize = resources.Quantity(fmt.Sprintf("%dG", *nodeClass.Spec.SystemDisk.Size))
52+
nodeClass.Spec.SystemDisk.Size != nil && nodeClass.Spec.SystemDisk.VolumeSize == nil {
53+
nodeClass.Spec.SystemDisk.VolumeSize = resources.Quantity(fmt.Sprintf("%dGi", *nodeClass.Spec.SystemDisk.Size))
5454
}
5555
if !equality.Semantic.DeepEqual(stored, nodeClass) {
5656
if err := c.kubeClient.Patch(ctx, nodeClass, client.MergeFrom(stored)); err != nil {

pkg/providers/imagefamily/resolver.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
"k8s.io/client-go/util/workqueue"
3131
"sigs.k8s.io/controller-runtime/pkg/log"
3232
"sigs.k8s.io/karpenter/pkg/cloudprovider"
33+
"sigs.k8s.io/karpenter/pkg/utils/resources"
3334

3435
"github.com/cloudpilot-ai/karpenter-provider-alibabacloud/pkg/apis/v1alpha1"
3536
"github.com/cloudpilot-ai/karpenter-provider-alibabacloud/pkg/utils/alierrors"
@@ -38,7 +39,7 @@ import (
3839
var DefaultSystemDisk = v1alpha1.SystemDisk{
3940
// TODO: Change me, comprehensive ranking based on the pricing
4041
Categories: []string{"cloud", "cloud_ssd", "cloud_efficiency", "cloud_essd", "cloud_auto", "cloud_essd_entry"},
41-
Size: tea.Int32(20),
42+
VolumeSize: resources.Quantity("20Gi"),
4243
}
4344

4445
// Options define the static launch template parameters

pkg/providers/instance/instance.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,10 @@ import (
5353

5454
const (
5555
// TODO: After that open up the configuration options
56-
instanceTypeFlexibilityThreshold = 5 // falling back to on-demand without flexibility risks insufficient capacity errors
57-
maxInstanceTypes = 20
58-
instanceCacheExpiration = 15 * time.Second
56+
instanceTypeFlexibilityThreshold = 5 // falling back to on-demand without flexibility risks insufficient capacity errors
57+
maxInstanceTypes = 20
58+
instanceCacheExpiration = 15 * time.Second
59+
defaultDataDiskSize int32 = 20
5960
)
6061

6162
type Provider interface {
@@ -554,12 +555,16 @@ func (p *DefaultProvider) getProvisioningGroup(ctx context.Context, nodeClass *v
554555
if systemDisk == nil {
555556
systemDisk = imagefamily.DefaultSystemDisk.DeepCopy()
556557
}
558+
if systemDisk.VolumeSize == nil {
559+
systemDisk.VolumeSize = imagefamily.DefaultSystemDisk.VolumeSize
560+
}
557561

558562
imageID, ok := mappedImages[instanceTypes[0].Name]
559563
if !ok {
560564
return nil, errors.New("matching image not found")
561565
}
562566

567+
// Convert bytes to GiB
563568
createAutoProvisioningGroupRequest := &ecsclient.CreateAutoProvisioningGroupRequest{
564569
RegionId: tea.String(p.region),
565570
TotalTargetCapacity: tea.String("1"),
@@ -574,7 +579,7 @@ func (p *DefaultProvider) getProvisioningGroup(ctx context.Context, nodeClass *v
574579
UserData: tea.String(userData),
575580
ResourceGroupId: tea.String(nodeClass.Spec.ResourceGroupID),
576581
SecurityGroupIds: securityGroupIDs,
577-
SystemDiskSize: systemDisk.Size,
582+
SystemDiskSize: tea.Int32(systemDisk.GetGiBSize()),
578583
Tag: reqTags,
579584
},
580585
// Add this tag to auto-provisioning-group, alibabacloud will monitor the requests and enhance the stability
@@ -592,7 +597,7 @@ func (p *DefaultProvider) getProvisioningGroup(ctx context.Context, nodeClass *v
592597
if nodeClass.Spec.DataDisks != nil && nodeClass.Spec.DataDisksCategories != nil {
593598
createAutoProvisioningGroupRequest.LaunchConfiguration.DataDisk = lo.Map(nodeClass.Spec.DataDisks, func(dataDisk v1alpha1.DataDisk, index int) *ecsclient.CreateAutoProvisioningGroupRequestLaunchConfigurationDataDisk {
594599
return &ecsclient.CreateAutoProvisioningGroupRequestLaunchConfigurationDataDisk{
595-
Size: dataDisk.Size,
600+
Size: tea.Int32(max(defaultDataDiskSize, dataDisk.GetGiBSize())),
596601
Device: dataDisk.Device,
597602
}
598603
})

pkg/providers/instancetype/types.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -334,11 +334,11 @@ func getCPUModel(cpuName string) string {
334334
}
335335

336336
func ephemeralStorage(systemDisk *v1alpha1.SystemDisk) *resource.Quantity {
337-
if systemDisk == nil {
338-
return resources.Quantity(fmt.Sprintf("%dG", *imagefamily.DefaultSystemDisk.Size))
337+
if systemDisk == nil || systemDisk.VolumeSize == nil {
338+
return imagefamily.DefaultSystemDisk.VolumeSize
339339
}
340340

341-
return resources.Quantity(fmt.Sprintf("%dG", *systemDisk.Size))
341+
return systemDisk.VolumeSize
342342
}
343343

344344
func privateIPv4Address(info *ecsclient.DescribeInstanceTypesResponseBodyInstanceTypesInstanceType) *resource.Quantity {

0 commit comments

Comments
 (0)