forked from kubernetes/autoscaler
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request kubernetes#4804 from gandhipr/azure-enableDynamicI…
…nstanceList Support for dynamic SKUs for scaling from zero scenario
- cluster-autoscaler-chart-9.43.3
- cluster-autoscaler-chart-9.43.2
- cluster-autoscaler-chart-9.43.1
- cluster-autoscaler-chart-9.43.0
- cluster-autoscaler-chart-9.40.0
- cluster-autoscaler-chart-9.37.0
- cluster-autoscaler-chart-9.36.0
- cluster-autoscaler-chart-9.35.0
- cluster-autoscaler-chart-9.34.1
- cluster-autoscaler-chart-9.34.0
- cluster-autoscaler-chart-9.32.0
- cluster-autoscaler-chart-9.29.3
- cluster-autoscaler-chart-9.25.0
- cluster-autoscaler-chart-9.23.0
- cluster-autoscaler-chart-9.21.1
- cluster-autoscaler-chart-9.21.0
- cluster-autoscaler-chart-9.20.1
- cluster-autoscaler-chart-9.19.4
- cluster-autoscaler-chart-9.19.2
- cluster-autoscaler-chart-9.19.1
- cluster-autoscaler-chart-9.19.0
- cluster-autoscaler-chart-9.18.1
- cluster-autoscaler-chart-9.18.0
- cluster-autoscaler-chart-9.17.2
Showing
62 changed files
with
34,631 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
cluster-autoscaler/cloudprovider/azure/azure_instance.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
/* | ||
Copyright 2022 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package azure | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
compute20190701 "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-07-01/compute" | ||
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2020-12-01/compute" | ||
"github.com/Azure/skewer" | ||
"k8s.io/klog/v2" | ||
"regexp" | ||
"strings" | ||
) | ||
|
||
// GetVMSSTypeStatically uses static list of vmss generated at azure_instance_types.go to fetch vmss instance information. | ||
// It is declared as a variable for testing purpose. | ||
var GetVMSSTypeStatically = func(template compute.VirtualMachineScaleSet) (*InstanceType, error) { | ||
var vmssType *InstanceType | ||
|
||
for k := range InstanceTypes { | ||
if strings.EqualFold(k, *template.Sku.Name) { | ||
vmssType = InstanceTypes[k] | ||
break | ||
} | ||
} | ||
|
||
promoRe := regexp.MustCompile(`(?i)_promo`) | ||
if promoRe.MatchString(*template.Sku.Name) { | ||
if vmssType == nil { | ||
// We didn't find an exact match but this is a promo type, check for matching standard | ||
klog.V(4).Infof("No exact match found for %s, checking standard types", *template.Sku.Name) | ||
skuName := promoRe.ReplaceAllString(*template.Sku.Name, "") | ||
for k := range InstanceTypes { | ||
if strings.EqualFold(k, skuName) { | ||
vmssType = InstanceTypes[k] | ||
break | ||
} | ||
} | ||
} | ||
} | ||
if vmssType == nil { | ||
return vmssType, fmt.Errorf("instance type %q not supported", *template.Sku.Name) | ||
} | ||
return vmssType, nil | ||
} | ||
|
||
// GetVMSSTypeDynamically fetched vmss instance information using sku api calls. | ||
// It is declared as a variable for testing purpose. | ||
var GetVMSSTypeDynamically = func(template compute.VirtualMachineScaleSet, skuClient compute20190701.ResourceSkusClient) (InstanceType, error) { | ||
ctx := context.Background() | ||
var sku skewer.SKU | ||
var vmssType InstanceType | ||
|
||
cache, err := skewer.NewCache(ctx, skewer.WithLocation(*template.Location), skewer.WithResourceClient(skuClient)) | ||
if err != nil { | ||
klog.V(1).Infof("Failed to instantiate cache, err: %v", err) | ||
return vmssType, err | ||
} | ||
|
||
sku, err = cache.Get(ctx, *template.Sku.Name, skewer.VirtualMachines, *template.Location) | ||
if err != nil { | ||
// We didn't find an exact match but this is a promo type, check for matching standard | ||
klog.V(1).Infof("No exact match found for %s, checking standard types. Error %v", *template.Sku.Name, err) | ||
promoRe := regexp.MustCompile(`(?i)_promo`) | ||
skuName := promoRe.ReplaceAllString(*template.Sku.Name, "") | ||
sku, err = cache.Get(context.Background(), skuName, skewer.VirtualMachines, *template.Location) | ||
if err != nil { | ||
return vmssType, fmt.Errorf("instance type %q not supported. Error %v", *template.Sku.Name, err) | ||
} | ||
} | ||
|
||
vmssType.VCPU, err = sku.VCPU() | ||
if err != nil { | ||
klog.V(1).Infof("Failed to parse vcpu from sku %q %v", *template.Sku.Name, err) | ||
return vmssType, err | ||
} | ||
gpu, err := getGpuFromSku(sku) | ||
if err != nil { | ||
klog.V(1).Infof("Failed to parse gpu from sku %q %v", *template.Sku.Name, err) | ||
return vmssType, err | ||
} | ||
vmssType.GPU = gpu | ||
|
||
memoryGb, err := sku.Memory() | ||
if err != nil { | ||
klog.V(1).Infof("Failed to parse memoryMb from sku %q %v", *template.Sku.Name, err) | ||
return vmssType, err | ||
} | ||
vmssType.MemoryMb = int64(memoryGb) * 1024 | ||
|
||
return vmssType, nil | ||
} |
105 changes: 105 additions & 0 deletions
105
cluster-autoscaler/cloudprovider/azure/azure_instance_gpu_sku.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
/* | ||
Copyright 2022 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package azure | ||
|
||
import ( | ||
"github.com/Azure/skewer" | ||
"github.com/pkg/errors" | ||
"strings" | ||
) | ||
|
||
var ( | ||
// NvidiaEnabledSKUs represents a list of NVIDIA gpus. | ||
// If a new GPU sku becomes available, add a key to this map, but only if you have a confirmation | ||
// that we have an agreement with NVIDIA for this specific gpu. | ||
NvidiaEnabledSKUs = map[string]bool{ | ||
// K80 | ||
"standard_nc6": true, | ||
"standard_nc12": true, | ||
"standard_nc24": true, | ||
"standard_nc24r": true, | ||
// M60 | ||
"standard_nv6": true, | ||
"standard_nv12": true, | ||
"standard_nv12s_v3": true, | ||
"standard_nv24": true, | ||
"standard_nv24s_v3": true, | ||
"standard_nv24r": true, | ||
"standard_nv48s_v3": true, | ||
// P40 | ||
"standard_nd6s": true, | ||
"standard_nd12s": true, | ||
"standard_nd24s": true, | ||
"standard_nd24rs": true, | ||
// P100 | ||
"standard_nc6s_v2": true, | ||
"standard_nc12s_v2": true, | ||
"standard_nc24s_v2": true, | ||
"standard_nc24rs_v2": true, | ||
// V100 | ||
"standard_nc6s_v3": true, | ||
"standard_nc12s_v3": true, | ||
"standard_nc24s_v3": true, | ||
"standard_nc24rs_v3": true, | ||
"standard_nd40s_v3": true, | ||
"standard_nd40rs_v2": true, | ||
// T4 | ||
"standard_nc4as_t4_v3": true, | ||
"standard_nc8as_t4_v3": true, | ||
"standard_nc16as_t4_v3": true, | ||
"standard_nc64as_t4_v3": true, | ||
// A100 40GB | ||
"standard_nd96asr_v4": true, | ||
"standard_nd112asr_a100_v4": true, | ||
"standard_nd120asr_a100_v4": true, | ||
// A100 80GB | ||
"standard_nd96amsr_a100_v4": true, | ||
"standard_nd112amsr_a100_v4": true, | ||
"standard_nd120amsr_a100_v4": true, | ||
// A100 PCIE 80GB | ||
"standard_nc24ads_a100_v4": true, | ||
"standard_nc48ads_a100_v4": true, | ||
"standard_nc96ads_a100_v4": true, | ||
} | ||
) | ||
|
||
// isNvidiaEnabledSKU determines if an VM SKU has nvidia driver support. | ||
func isNvidiaEnabledSKU(vmSize string) bool { | ||
// Trim the optional _Promo suffix. | ||
vmSize = strings.ToLower(vmSize) | ||
vmSize = strings.TrimSuffix(vmSize, "_promo") | ||
return NvidiaEnabledSKUs[vmSize] | ||
} | ||
|
||
// getGpuFromSku extracts gpu information from vmss sku. | ||
func getGpuFromSku(sku skewer.SKU) (int64, error) { | ||
errCapabilityValueNil := &skewer.ErrCapabilityValueNil{} | ||
errCapabilityNotFound := &skewer.ErrCapabilityNotFound{} | ||
|
||
var value int64 | ||
value, err := sku.GetCapabilityIntegerQuantity("GPUs") | ||
if err != nil { | ||
// In case of an error, SKU api returns -1 as the value. | ||
// Updating value=0 if it's a non-gpu sku or value is nil. | ||
if errors.As(err, &errCapabilityValueNil) || errors.As(err, &errCapabilityNotFound) { | ||
value = 0 | ||
} else { | ||
return value, err | ||
} | ||
} | ||
return value, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.