Skip to content

Commit

Permalink
fix: add topology.disk.csi.azure.com/zone to normalized labels (#173)
Browse files Browse the repository at this point in the history
* fix: adding topology label to normalized labels
  • Loading branch information
Bryce-Soghigian authored Mar 4, 2024
1 parent 0445060 commit c32dbc1
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 26 deletions.
12 changes: 0 additions & 12 deletions pkg/apis/v1alpha2/labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ func init() {
LabelSKUMemory,
LabelSKUAccelerator,

LabelSKUConfidential,
LabelSKUIsolatedSize,

LabelSKUAcceleratedNetworking,

LabelSKUStoragePremiumCapable,
Expand Down Expand Up @@ -88,10 +85,6 @@ var (
LabelSKUAccelerator = Group + "/sku-accelerator"

// selected capabilities (from additive features in VM size name, or from SKU capabilities)
// https://learn.microsoft.com/en-us/azure/virtual-machines/vm-naming-conventions
LabelSKUConfidential = Group + "/sku-confidential" // c
LabelSKUIsolatedSize = Group + "/sku-isolated-size" // i

LabelSKUAcceleratedNetworking = Group + "/sku-networking-accelerated" // sku.AcceleratedNetworkingEnabled

LabelSKUStoragePremiumCapable = Group + "/sku-storage-premium-capable" // sku.IsPremiumIO
Expand All @@ -113,11 +106,6 @@ var (
AKSLabelDomain = "kubernetes.azure.com"

AKSLabelCluster = AKSLabelDomain + "/cluster"

SkuFeatureToLabel = map[rune]string{
'c': LabelSKUConfidential,
'i': LabelSKUIsolatedSize,
}
)

const (
Expand Down
3 changes: 3 additions & 0 deletions pkg/operator/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ import (

"github.com/patrickmn/go-cache"
"github.com/samber/lo"
corev1 "k8s.io/api/core/v1"
"k8s.io/client-go/rest"
"k8s.io/client-go/transport"
"knative.dev/pkg/ptr"
corev1beta1 "sigs.k8s.io/karpenter/pkg/apis/v1beta1"
"sigs.k8s.io/karpenter/pkg/operator/scheme"

"github.com/Azure/karpenter-provider-azure/pkg/apis"
Expand All @@ -43,6 +45,7 @@ import (

func init() {
lo.Must0(apis.AddToScheme(scheme.Scheme))
corev1beta1.NormalizedLabels = lo.Assign(corev1beta1.NormalizedLabels, map[string]string{"topology.disk.csi.azure.com/zone": corev1.LabelTopologyZone})
}

type Operator struct {
Expand Down
14 changes: 0 additions & 14 deletions pkg/providers/instancetype/instancetype.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,6 @@ func computeRequirements(sku *skewer.SKU, vmsize *skewer.VMSizeType, architectur
// size parts
requirements[v1alpha2.LabelSKUFamily].Insert(vmsize.Family)

// everything from additive features
for _, featureLabel := range v1alpha2.SkuFeatureToLabel {
requirements.Add(scheduling.NewRequirement(featureLabel, v1.NodeSelectorOpDoesNotExist))
}

setRequirementsAdditiveFeatures(requirements, vmsize)
setRequirementsStoragePremiumCapable(requirements, sku)
setRequirementsEncryptionAtHostSupported(requirements, sku)
setRequirementsEphemeralOSDiskSupported(requirements, sku, vmsize)
Expand All @@ -201,14 +195,6 @@ func computeRequirements(sku *skewer.SKU, vmsize *skewer.VMSizeType, architectur
return requirements
}

func setRequirementsAdditiveFeatures(requirements scheduling.Requirements, vmsize *skewer.VMSizeType) {
for _, feature := range vmsize.AdditiveFeatures {
if featureLabel, ok := v1alpha2.SkuFeatureToLabel[feature]; ok {
requirements[featureLabel].Insert("true")
}
}
}

func setRequirementsStoragePremiumCapable(requirements scheduling.Requirements, sku *skewer.SKU) {
if sku.IsPremiumIO() {
requirements[v1alpha2.LabelSKUStoragePremiumCapable].Insert("true")
Expand Down
52 changes: 52 additions & 0 deletions pkg/providers/instancetype/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -813,6 +813,58 @@ var _ = Describe("InstanceType Provider", func() {
}
})

It("should support individual instance type labels", func() {
ExpectApplied(ctx, env.Client, nodePool, nodeClass)

nodeSelector := map[string]string{
// Well known
v1.LabelTopologyRegion: fake.Region,
corev1beta1.NodePoolLabelKey: nodePool.Name,
v1.LabelTopologyZone: fmt.Sprintf("%s-1", fake.Region),
v1.LabelInstanceTypeStable: "Standard_NC24ads_A100_v4",
v1.LabelOSStable: "linux",
v1.LabelArchStable: "amd64",
corev1beta1.CapacityTypeLabelKey: "on-demand",
// Well Known to AKS
v1alpha2.LabelSKUName: "Standard_NC24ads_A100_v4",
v1alpha2.LabelSKUFamily: "N",
v1alpha2.LabelSKUVersion: "4",
v1alpha2.LabelSKUStorageCacheSize: "0", // Either Temp disk or cache disk can be empty :)
v1alpha2.LabelSKUStorageTempMaxSize: "0",
v1alpha2.LabelSKUStorageEphemeralOSMaxSize: "53.6870912",
v1alpha2.LabelSKUAcceleratedNetworking: "true",
v1alpha2.LabelSKUEncryptionAtHostSupported: "true",
v1alpha2.LabelSKUStoragePremiumCapable: "true",
v1alpha2.LabelSKUGPUName: "A100",
v1alpha2.LabelSKUGPUManufacturer: "nvidia",
v1alpha2.LabelSKUGPUCount: "1",
v1alpha2.LabelSKUCPU: "24",
v1alpha2.LabelSKUMemory: "8192",
v1alpha2.LabelSKUAccelerator: "A100",
// Deprecated Labels
v1.LabelFailureDomainBetaRegion: fake.Region,
v1.LabelFailureDomainBetaZone: fmt.Sprintf("%s-1", fake.Region),
"beta.kubernetes.io/arch": "amd64",
"beta.kubernetes.io/os": "linux",
v1.LabelInstanceType: "Standard_NC24ads_A100_v4",
"topology.disk.csi.azure.com/zone": fmt.Sprintf("%s-1", fake.Region),
v1.LabelWindowsBuild: "window",
// Cluster Label
v1alpha2.AKSLabelCluster: "test-cluster",
}

// Ensure that we're exercising all well known labels
Expect(lo.Keys(nodeSelector)).To(ContainElements(append(corev1beta1.WellKnownLabels.UnsortedList(), lo.Keys(corev1beta1.NormalizedLabels)...)))

var pods []*v1.Pod
for key, value := range nodeSelector {
pods = append(pods, coretest.UnschedulablePod(coretest.PodOptions{NodeSelector: map[string]string{key: value}}))
}
ExpectProvisioned(ctx, env.Client, cluster, cloudProvider, coreProvisioner, pods...)
for _, pod := range pods {
ExpectScheduled(ctx, env.Client, pod)
}
})
It("should propagate all values to requirements from skewer", func() {
var gpuNode *corecloudprovider.InstanceType
var normalNode *corecloudprovider.InstanceType
Expand Down
8 changes: 8 additions & 0 deletions pkg/test/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ package test
import (
"context"

"github.com/samber/lo"

azurecache "github.com/Azure/karpenter-provider-azure/pkg/cache"
"github.com/Azure/karpenter-provider-azure/pkg/fake"
"github.com/Azure/karpenter-provider-azure/pkg/providers/imagefamily"
Expand All @@ -28,11 +30,17 @@ import (
"github.com/Azure/karpenter-provider-azure/pkg/providers/loadbalancer"
"github.com/Azure/karpenter-provider-azure/pkg/providers/pricing"
"github.com/patrickmn/go-cache"
corev1 "k8s.io/api/core/v1"
"knative.dev/pkg/ptr"

corev1beta1 "sigs.k8s.io/karpenter/pkg/apis/v1beta1"
coretest "sigs.k8s.io/karpenter/pkg/test"
)

func init() {
corev1beta1.NormalizedLabels = lo.Assign(corev1beta1.NormalizedLabels, map[string]string{"topology.disk.csi.azure.com/zone": corev1.LabelTopologyZone})
}

var resourceGroup = "test-resourceGroup"

type Environment struct {
Expand Down

0 comments on commit c32dbc1

Please sign in to comment.