Skip to content

Commit

Permalink
Merge pull request #115 from jwcesign/modify-rm
Browse files Browse the repository at this point in the history
fix: fix disk configuration
  • Loading branch information
helen-frank authored Nov 11, 2024
2 parents 0e9a2cb + 3d74c21 commit ada2a7f
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ spec:
spec:
description: |-
ECSNodeClassSpec is the top level specification for the AlibabaCloud Karpenter Provider.
This will contain configuration necessary to launch instances in AliCloud.
This will contain the configuration necessary to launch instances in AlibabaCloud.
properties:
imageSelectorTerms:
description: ImageSelectorTerms is a list of or image selector terms.
Expand Down Expand Up @@ -267,16 +267,9 @@ spec:
type: boolean
categories:
description: |-
The category of the system disk (for example, cloud or cloud_ssd).
The category of the system disk (for example, cloud and cloud_ssd).
Different ECS is compatible with different disk category, using array to maximize ECS creation success.
Valid values:"cloud", "cloud_efficiency", "cloud_ssd", "cloud_essd", "cloud_auto", and "cloud_essd_entry"
enum:
- cloud
- cloud_efficiency
- cloud_ssd
- cloud_essd
- cloud_auto
- cloud_essd_entry
items:
type: string
type: array
Expand Down
6 changes: 6 additions & 0 deletions examples/nodepool/ecsnodeclass.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ spec:
securityGroupSelectorTerms:
- tags:
karpenter.sh/discovery: "cluster-demonstration" # replace with your cluster name
systemDisk:
categories:
- cloud
- cloud_ssd
- cloud_auto
size: 60
imageSelectorTerms:
# ContainerOS only support x86_64 linux nodes, and it's faster to initialize
- alias: ContainerOS
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/v1alpha1/ecsnodeclass.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,10 @@ type KubeletConfiguration struct {
}

type SystemDisk struct {
// The category of the system disk (for example, cloud or cloud_ssd).
// The category of the system disk (for example, cloud and cloud_ssd).
// Different ECS is compatible with different disk category, using array to maximize ECS creation success.
// Valid values:"cloud", "cloud_efficiency", "cloud_ssd", "cloud_essd", "cloud_auto", and "cloud_essd_entry"
// +kubebuilder:validation:Enum:={cloud,cloud_efficiency,cloud_ssd,cloud_essd,cloud_auto,cloud_essd_entry}
// +kubebuilder:validation:Items=Enum=cloud;cloud_efficiency;cloud_ssd;cloud_essd;cloud_auto;cloud_essd_entry
// +optional
Categories []string `json:"categories,omitempty"`
// The size of the system disk. Unit: GiB.
Expand Down
15 changes: 9 additions & 6 deletions pkg/providers/imagefamily/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ type InstanceTypeAvailableSystemDisk struct {
}

func newInstanceTypeAvailableSystemDisk() *InstanceTypeAvailableSystemDisk {
return &InstanceTypeAvailableSystemDisk{}
return &InstanceTypeAvailableSystemDisk{
availableSystemDisk: sets.Set[string]{},
}
}

func (s *InstanceTypeAvailableSystemDisk) AddAvailableSystemDisk(systemDisks ...string) {
Expand All @@ -78,12 +80,12 @@ func (s *InstanceTypeAvailableSystemDisk) AddAvailableSystemDisk(systemDisks ...

func (s *InstanceTypeAvailableSystemDisk) Compatible(systemDisks []string) bool {
for sdi := range systemDisks {
if !s.availableSystemDisk.Has(systemDisks[sdi]) {
return false
if s.availableSystemDisk.Has(systemDisks[sdi]) {
return true
}
}

return true
return false
}

type Resolver interface {
Expand Down Expand Up @@ -147,8 +149,9 @@ func (r *DefaultResolver) FilterInstanceTypesBySystemDisk(ctx context.Context, n
DestinationResource: tea.String("SystemDisk"),
InstanceType: tea.String(instanceType.Name),
}, func(resource *ecs.DescribeAvailableResourceResponseBodyAvailableZonesAvailableZoneAvailableResourcesAvailableResourceSupportedResourcesSupportedResource) {
if *resource.Status == "Available" && *resource.Value != "" {
availableSystemDisk.AddAvailableSystemDisk(*resource.Value)
if tea.StringValue(resource.Status) == "Available" &&
tea.StringValue(resource.Value) != "" {
availableSystemDisk.AddAvailableSystemDisk(tea.StringValue(resource.Value))
}
}); err != nil {
errs[i] = err
Expand Down
4 changes: 4 additions & 0 deletions pkg/providers/instance/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,10 @@ func (p *DefaultProvider) getProvisioningGroup(ctx context.Context, nodeClass *v
requirements := scheduling.NewNodeSelectorRequirementsWithMinValues(nodeClaim.Spec.Requirements...)

instanceTypes = p.imageFamilyResolver.FilterInstanceTypesBySystemDisk(ctx, nodeClass, instanceTypes)
if len(instanceTypes) == 0 {
return nil, errors.New("no instance types match the system disk requirements")
}

mappedImages := mapToInstanceTypes(instanceTypes, nodeClass.Status.Images)

requirements[karpv1.CapacityTypeLabelKey] = scheduling.NewRequirement(karpv1.CapacityTypeLabelKey, corev1.NodeSelectorOpIn, capacityType)
Expand Down

0 comments on commit ada2a7f

Please sign in to comment.