Skip to content

Commit 99c437a

Browse files
committed
feat: further parity with AKS from AKS machine API integration/provision mode
1 parent 80faa58 commit 99c437a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+7706
-125
lines changed

Makefile-az.mk

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ else
1111
endif
1212

1313
AZURE_ACR_SUFFIX ?= azurecr.io
14-
AZURE_SIG_SUBSCRIPTION_ID ?= $(AZURE_SUBSCRIPTION_ID)
14+
AZURE_SIG_SUBSCRIPTION_ID ?= 10945678-1234-1234-1234-123456789012
1515
AZURE_CLUSTER_NAME ?= $(COMMON_NAME)
1616
AZURE_RESOURCE_GROUP_MC = MC_$(AZURE_RESOURCE_GROUP)_$(AZURE_CLUSTER_NAME)_$(AZURE_LOCATION)
1717

@@ -22,6 +22,8 @@ KARPENTER_FEDERATED_IDENTITY_CREDENTIAL_NAME ?= KARPENTER_FID
2222
CUSTOM_VNET_NAME ?= $(AZURE_CLUSTER_NAME)-vnet
2323
CUSTOM_SUBNET_NAME ?= nodesubnet
2424

25+
AKS_MACHINES_POOL_NAME ?= testmpool
26+
2527
.DEFAULT_GOAL := help # make without arguments will show help
2628

2729
az-all: az-login az-create-workload-msi az-mkaks-cilium az-create-federated-cred az-perm az-perm-acr az-configure-values az-build az-run az-run-sample ## Provision the infra (ACR,AKS); build and deploy Karpenter; deploy sample Provisioner and workload
@@ -30,6 +32,8 @@ az-all-cniv1: az-login az-create-workload-msi az-mkaks-cniv1 az-cre
3032

3133
az-all-cni-overlay: az-login az-create-workload-msi az-mkaks-overlay az-create-federated-cred az-perm az-perm-acr az-configure-values az-build az-run az-run-sample ## Provision the infra (ACR,AKS); build and deploy Karpenter; deploy sample Provisioner and workload
3234

35+
az-all-aksmachine: az-login az-create-workload-msi az-mkaks-cilium az-create-federated-cred az-perm az-perm-acr az-perm-aksmachine az-add-aksmachinespool az-configure-values-aksmachine az-build az-run az-run-sample
36+
3337
az-all-perftest: az-login az-create-workload-msi az-mkaks-perftest az-create-federated-cred az-perm az-perm-acr az-configure-values
3438
$(MAKE) az-mon-deploy
3539
$(MAKE) az-pprof-enable
@@ -135,12 +139,18 @@ az-mkaks-savm: az-mkrg ## Create experimental cluster with standalone VMs (+ ACR
135139
az aks get-credentials --resource-group $(AZURE_RESOURCE_GROUP) --name $(AZURE_CLUSTER_NAME) --overwrite-existing
136140
skaffold config set default-repo $(AZURE_ACR_NAME).$(AZURE_ACR_SUFFIX)/karpenter
137141

142+
az-add-aksmachinespool:
143+
hack/deploy/add-aks-machines-pool.sh $(AZURE_SUBSCRIPTION_ID) $(AZURE_RESOURCE_GROUP) $(AZURE_CLUSTER_NAME) $(AKS_MACHINES_POOL_NAME)
144+
138145
az-rmrg: ## Destroy test ACR and AKS cluster by deleting the resource group (use with care!)
139146
az group delete --name $(AZURE_RESOURCE_GROUP)
140147

141148
az-configure-values: ## Generate cluster-related values for Karpenter Helm chart
142149
hack/deploy/configure-values.sh $(AZURE_CLUSTER_NAME) $(AZURE_RESOURCE_GROUP) $(KARPENTER_SERVICE_ACCOUNT_NAME) $(AZURE_KARPENTER_USER_ASSIGNED_IDENTITY_NAME)
143150

151+
az-configure-values-aksmachine: ## Generate cluster-related values for Karpenter Helm chart
152+
hack/deploy/configure-values.sh $(AZURE_CLUSTER_NAME) $(AZURE_RESOURCE_GROUP) $(KARPENTER_SERVICE_ACCOUNT_NAME) $(AZURE_KARPENTER_USER_ASSIGNED_IDENTITY_NAME) aksmachineapi $(AKS_MACHINES_POOL_NAME)
153+
144154
az-mkvmssflex: ## Create VMSS Flex (optional, only if creating VMs referencing this VMSS)
145155
az vmss create --name $(AZURE_CLUSTER_NAME)-vmss --resource-group $(AZURE_RESOURCE_GROUP_MC) --location $(AZURE_LOCATION) \
146156
--instance-count 0 --orchestration-mode Flexible --platform-fault-domain-count 1 --zones 1 2 3
@@ -156,6 +166,15 @@ az-perm: ## Create role assignments to let Karpenter manage VMs and Network
156166
az role assignment create --assignee-object-id $(KARPENTER_USER_ASSIGNED_CLIENT_ID) --assignee-principal-type "ServicePrincipal" --scope /subscriptions/$(AZURE_SUBSCRIPTION_ID)/resourceGroups/$(AZURE_RESOURCE_GROUP_MC) --role "Managed Identity Operator"
157167
@echo Consider "make az-configure-values"!
158168

169+
az-perm-aksmachine: ## Create role assignments for AKS machine API operations
170+
$(eval KARPENTER_USER_ASSIGNED_CLIENT_ID=$(shell az identity show --resource-group "${AZURE_RESOURCE_GROUP}" --name "${AZURE_KARPENTER_USER_ASSIGNED_IDENTITY_NAME}" --query 'principalId' -otsv))
171+
az role assignment create --assignee-object-id $(KARPENTER_USER_ASSIGNED_CLIENT_ID) --assignee-principal-type "ServicePrincipal" --scope /subscriptions/$(AZURE_SUBSCRIPTION_ID)/resourceGroups/$(AZURE_RESOURCE_GROUP) --role "Azure Kubernetes Service Contributor Role"
172+
az role assignment create --assignee-object-id $(KARPENTER_USER_ASSIGNED_CLIENT_ID) --assignee-principal-type "ServicePrincipal" --scope /subscriptions/$(AZURE_SUBSCRIPTION_ID)/resourceGroups/$(AZURE_RESOURCE_GROUP_MC) --role "Network Contributor"
173+
$(eval CLUSTER_IDENTITY=$(shell az aks show --resource-group "${AZURE_RESOURCE_GROUP}" --name "${AZURE_CLUSTER_NAME}" --query 'identity.principalId' -otsv))
174+
az role assignment create --assignee-object-id $(CLUSTER_IDENTITY) --assignee-principal-type "ServicePrincipal" --scope /subscriptions/$(AZURE_SUBSCRIPTION_ID)/resourceGroups/$(AZURE_RESOURCE_GROUP_MC) --role "Virtual Machine Contributor"
175+
az role assignment create --assignee-object-id $(CLUSTER_IDENTITY) --assignee-principal-type "ServicePrincipal" --scope /subscriptions/$(AZURE_SUBSCRIPTION_ID)/resourceGroups/$(AZURE_RESOURCE_GROUP_MC) --role "Network Contributor"
176+
az role assignment create --assignee-object-id $(CLUSTER_IDENTITY) --assignee-principal-type "ServicePrincipal" --scope /subscriptions/$(AZURE_SUBSCRIPTION_ID)/resourceGroups/$(AZURE_RESOURCE_GROUP_MC) --role "Managed Identity Operator"
177+
159178
az-perm-sig: ## Create role assignments when testing with SIG images
160179
$(eval KARPENTER_USER_ASSIGNED_CLIENT_ID=$(shell az identity show --resource-group "${AZURE_RESOURCE_GROUP}" --name "${AZURE_KARPENTER_USER_ASSIGNED_IDENTITY_NAME}" --query 'principalId' -otsv))
161180
az role assignment create --assignee-object-id $(KARPENTER_USER_ASSIGNED_CLIENT_ID) --assignee-principal-type "ServicePrincipal" --role "Reader" --scope /subscriptions/$(AZURE_SIG_SUBSCRIPTION_ID)/resourceGroups/AKS-Ubuntu/providers/Microsoft.Compute/galleries/AKSUbuntu

hack/deploy/configure-values.sh

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ set -euo pipefail
33
# This script interrogates the AKS cluster and Azure resources to generate
44
# the karpenter-values.yaml file using the karpenter-values-template.yaml file as a template.
55

6-
if [ "$#" -ne 4 ]; then
7-
echo "Usage: $0 <cluster-name> <resource-group> <karpenter-service-account-name> <karpenter-user-assigned-identity-name>"
6+
if [ "$#" -lt 4 ] || [ "$#" -gt 6 ]; then
7+
echo "Usage: $0 <cluster-name> <resource-group> <karpenter-service-account-name> <karpenter-user-assigned-identity-name> [provision-mode] [aks-machines-pool-name]"
88
exit 1
99
fi
1010

@@ -14,6 +14,8 @@ CLUSTER_NAME=$1
1414
AZURE_RESOURCE_GROUP=$2
1515
KARPENTER_SERVICE_ACCOUNT_NAME=$3
1616
AZURE_KARPENTER_USER_ASSIGNED_IDENTITY_NAME=$4
17+
PROVISION_MODE=${5:-}
18+
AKS_MACHINES_POOL_NAME=${6:-testmpool}
1719

1820
# Optional values through env vars:
1921
LOG_LEVEL=${LOG_LEVEL:-"info"}
@@ -68,9 +70,15 @@ NODE_IDENTITIES=$(jq -r ".identityProfile.kubeletidentity.resourceId" <<< "$AKS_
6870
KARPENTER_USER_ASSIGNED_CLIENT_ID=$(az identity show --resource-group "${AZURE_RESOURCE_GROUP}" --name "${AZURE_KARPENTER_USER_ASSIGNED_IDENTITY_NAME}" --query 'clientId' -otsv)
6971
KUBELET_IDENTITY_CLIENT_ID=$(jq -r ".identityProfile.kubeletidentity.clientId // empty" <<< "$AKS_JSON")
7072

71-
export CLUSTER_NAME AZURE_LOCATION AZURE_RESOURCE_GROUP_MC KARPENTER_SERVICE_ACCOUNT_NAME \
73+
# For Machine API mode
74+
if [[ "${PROVISION_MODE:-}" == "aksmachineapi" ]]; then
75+
USE_SIG="true"
76+
AZURE_SIG_SUBSCRIPTION_ID=109a5e88-712a-48ae-9078-9ca8b3c81345
77+
fi
78+
79+
export CLUSTER_NAME AZURE_LOCATION AZURE_RESOURCE_GROUP AZURE_RESOURCE_GROUP_MC KARPENTER_SERVICE_ACCOUNT_NAME \
7280
CLUSTER_ENDPOINT BOOTSTRAP_TOKEN SSH_PUBLIC_KEY VNET_SUBNET_ID KARPENTER_USER_ASSIGNED_CLIENT_ID NODE_IDENTITIES AZURE_SUBSCRIPTION_ID NETWORK_PLUGIN NETWORK_PLUGIN_MODE NETWORK_POLICY \
73-
LOG_LEVEL VNET_GUID KUBELET_IDENTITY_CLIENT_ID
81+
LOG_LEVEL VNET_GUID KUBELET_IDENTITY_CLIENT_ID PROVISION_MODE USE_SIG AZURE_SIG_SUBSCRIPTION_ID AKS_MACHINES_POOL_NAME
7482

7583
# get karpenter-values-template.yaml, if not already present (e.g. outside of repo context)
7684
if [ ! -f karpenter-values-template.yaml ]; then

karpenter-values-template.yaml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,19 @@ controller:
4242

4343
# managed karpenter settings
4444
- name: USE_SIG
45-
value: "false"
45+
value: "${USE_SIG}"
4646
- name: SIG_ACCESS_TOKEN_SERVER_URL
4747
value: ""
4848
- name: SIG_ACCESS_TOKEN_SCOPE
4949
value: ""
5050
- name: SIG_SUBSCRIPTION_ID
51-
value: ""
51+
value: "${AZURE_SIG_SUBSCRIPTION_ID}"
52+
- name: PROVISION_MODE
53+
value: ${PROVISION_MODE}
54+
- name: AKS_MACHINES_POOL_NAME
55+
value: "${AKS_MACHINES_POOL_NAME}"
56+
- name: ARM_RESOURCE_GROUP
57+
value: ${AZURE_RESOURCE_GROUP}
5258
serviceAccount:
5359
name: ${KARPENTER_SERVICE_ACCOUNT_NAME}
5460
annotations:

pkg/apis/v1beta1/labels.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ var (
9999

100100
AnnotationAKSNodeClassHash = apis.Group + "/aksnodeclass-hash"
101101
AnnotationAKSNodeClassHashVersion = apis.Group + "/aksnodeclass-hash-version"
102+
AnnotationAKSMachineResourceID = apis.Group + "/aks-machine-resource-id" // resource ID of the associated AKS machine
102103
)
103104

104105
const (

pkg/cloudprovider/cloudprovider.go

Lines changed: 130 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,11 @@ import (
3838

3939
// nolint SA1019 - deprecated package
4040
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v5"
41+
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/containerservice/armcontainerservice/v7"
4142

4243
"github.com/Azure/karpenter-provider-azure/pkg/apis"
4344
"github.com/Azure/karpenter-provider-azure/pkg/apis/v1beta1"
45+
"github.com/Azure/karpenter-provider-azure/pkg/consts"
4446
"github.com/Azure/karpenter-provider-azure/pkg/controllers/nodeclaim/inplaceupdate"
4547
"github.com/Azure/karpenter-provider-azure/pkg/operator/options"
4648

@@ -74,26 +76,29 @@ const (
7476
var _ cloudprovider.CloudProvider = (*CloudProvider)(nil)
7577

7678
type CloudProvider struct {
77-
instanceTypeProvider instancetype.Provider
78-
vmInstanceProvider instance.VMProvider
79-
kubeClient client.Client
80-
imageProvider imagefamily.NodeImageProvider
81-
recorder events.Recorder
79+
instanceTypeProvider instancetype.Provider
80+
vmInstanceProvider instance.VMProvider // Note that even when provision mode does not create with VM instance provider, it is still being used to handle existing VM instances.
81+
aksMachineInstanceProvider instance.AKSMachineProvider
82+
kubeClient client.Client
83+
imageProvider imagefamily.NodeImageProvider
84+
recorder events.Recorder
8285
}
8386

8487
func New(
8588
instanceTypeProvider instancetype.Provider,
8689
vmInstanceProvider instance.VMProvider,
90+
aksMachineInstanceProvider instance.AKSMachineProvider,
8791
recorder events.Recorder,
8892
kubeClient client.Client,
8993
imageProvider imagefamily.NodeImageProvider,
9094
) *CloudProvider {
9195
return &CloudProvider{
92-
instanceTypeProvider: instanceTypeProvider,
93-
vmInstanceProvider: vmInstanceProvider,
94-
kubeClient: kubeClient,
95-
imageProvider: imageProvider,
96-
recorder: recorder,
96+
instanceTypeProvider: instanceTypeProvider,
97+
vmInstanceProvider: vmInstanceProvider,
98+
aksMachineInstanceProvider: aksMachineInstanceProvider,
99+
kubeClient: kubeClient,
100+
imageProvider: imageProvider,
101+
recorder: recorder,
97102
}
98103
}
99104

@@ -147,6 +152,11 @@ func (c *CloudProvider) Create(ctx context.Context, nodeClaim *karpv1.NodeClaim)
147152
return nil, cloudprovider.NewInsufficientCapacityError(fmt.Errorf("all requested instance types were unavailable during launch"))
148153
}
149154

155+
// Choose provider based on provision mode
156+
if options.FromContext(ctx).ProvisionMode == consts.ProvisionModeAKSMachineAPI {
157+
return c.createAKSMachineInstance(ctx, nodeClass, nodeClaim, instanceTypes)
158+
}
159+
150160
return c.createVMInstance(ctx, nodeClass, nodeClaim, instanceTypes)
151161
}
152162

@@ -175,6 +185,39 @@ func (c *CloudProvider) createVMInstance(ctx context.Context, nodeClass *v1beta1
175185
return newNodeClaim, nil
176186
}
177187

188+
func (c *CloudProvider) createAKSMachineInstance(ctx context.Context, nodeClass *v1beta1.AKSNodeClass, nodeClaim *karpv1.NodeClaim, instanceTypes []*cloudprovider.InstanceType) (*karpv1.NodeClaim, error) {
189+
// Begin the creation of the instance
190+
aksMachinePromise, err := c.aksMachineInstanceProvider.BeginCreate(ctx, nodeClass, nodeClaim, instanceTypes)
191+
if err != nil {
192+
return nil, cloudprovider.NewCreateError(fmt.Errorf("creating AKS machine failed, %w", err), CreateInstanceFailedReason, truncateMessage(err.Error()))
193+
}
194+
195+
// Handle the promise
196+
if err := c.handleInstancePromise(ctx, aksMachinePromise, nodeClaim); err != nil {
197+
return nil, err
198+
}
199+
200+
// Convert the AKS machine to a NodeClaim
201+
newNodeClaim, err := instance.BuildNodeClaimFromAKSMachineTemplate(
202+
ctx, aksMachinePromise.AKSMachineTemplate,
203+
aksMachinePromise.InstanceType,
204+
aksMachinePromise.CapacityType,
205+
lo.ToPtr(aksMachinePromise.Zone),
206+
aksMachinePromise.AKSMachineID,
207+
aksMachinePromise.VMResourceID,
208+
false,
209+
aksMachinePromise.AKSMachineNodeImageVersion)
210+
if err != nil {
211+
return nil, fmt.Errorf("failed to build NodeClaim from AKS machine template, %w", err)
212+
}
213+
214+
if err := setAdditionalAnnotationsForNewNodeClaim(ctx, newNodeClaim, nodeClass); err != nil {
215+
return nil, err
216+
}
217+
218+
return newNodeClaim, nil
219+
}
220+
178221
// handleInstancePromise handles the instance promise, primarily deciding on sync/async provisioning.
179222
func (c *CloudProvider) handleInstancePromise(ctx context.Context, instancePromise instance.InstancePromise, nodeClaim *karpv1.NodeClaim) error {
180223
if isNodeClaimStandalone(nodeClaim) {
@@ -270,12 +313,29 @@ func (c *CloudProvider) waitUntilLaunched(ctx context.Context, nodeClaim *karpv1
270313
}
271314

272315
func (c *CloudProvider) List(ctx context.Context) ([]*karpv1.NodeClaim, error) {
316+
var nodeClaims []*karpv1.NodeClaim
317+
318+
// List AKS machine-based nodes
319+
aksMachineInstances, err := c.aksMachineInstanceProvider.List(ctx)
320+
if err != nil {
321+
return nil, fmt.Errorf("listing AKS machine instances, %w", err)
322+
}
323+
324+
for _, aksMachineInstance := range aksMachineInstances {
325+
nodeClaim, err := c.resolveNodeClaimFromAKSMachine(ctx, aksMachineInstance)
326+
if err != nil {
327+
return nil, fmt.Errorf("converting AKS machine instance to node claim, %w", err)
328+
}
329+
330+
nodeClaims = append(nodeClaims, nodeClaim)
331+
}
332+
333+
// List VM-based nodes
273334
vmInstances, err := c.vmInstanceProvider.List(ctx)
274335
if err != nil {
275336
return nil, fmt.Errorf("listing VM instances, %w", err)
276337
}
277338

278-
var nodeClaims []*karpv1.NodeClaim
279339
for _, instance := range vmInstances {
280340
instanceType, err := c.resolveInstanceTypeFromVMInstance(ctx, instance)
281341
if err != nil {
@@ -297,6 +357,28 @@ func (c *CloudProvider) Get(ctx context.Context, providerID string) (*karpv1.Nod
297357
return nil, fmt.Errorf("getting vm name, %w", err)
298358
}
299359
ctx = log.IntoContext(ctx, log.FromContext(ctx).WithValues("vmName", vmName))
360+
361+
aksMachinesPoolName := options.FromContext(ctx).AKSMachinesPoolName
362+
if aksMachineName, err := instance.GetAKSMachineNameFromVMName(aksMachinesPoolName, vmName); err == nil {
363+
// This could be an AKS machine-based node; try getting the AKS machine instance
364+
ctx := log.IntoContext(ctx, log.FromContext(ctx).WithValues("aksMachineName", aksMachineName))
365+
366+
aksMachine, err := c.aksMachineInstanceProvider.Get(ctx, aksMachineName)
367+
if err == nil {
368+
nodeClaim, err := c.resolveNodeClaimFromAKSMachine(ctx, aksMachine)
369+
if err != nil {
370+
return nil, fmt.Errorf("converting AKS machine instance to node claim, %w", err)
371+
}
372+
return nodeClaim, nil
373+
} else if cloudprovider.IgnoreNodeClaimNotFoundError(err) != nil {
374+
return nil, fmt.Errorf("getting AKS machine instance, %w", err)
375+
}
376+
// Fallback to legacy VM-based node if not found
377+
// In the case that it is indeed AKS machine node, but somehow fail GET AKS machine and succeeded GET VM, ideally we want this call to fail.
378+
// However, being misrepresented only once is not fatal. "Illegal" in-place update will be reconciled back to the before, and there is no drift for VM nodes that won't happen with AKS machine nodes + DriftAction.
379+
// So, we could live with this for now.
380+
}
381+
300382
vm, err := c.vmInstanceProvider.Get(ctx, vmName)
301383
if err != nil {
302384
return nil, fmt.Errorf("getting VM instance, %w", err)
@@ -334,6 +416,13 @@ func (c *CloudProvider) GetInstanceTypes(ctx context.Context, nodePool *karpv1.N
334416

335417
func (c *CloudProvider) Delete(ctx context.Context, nodeClaim *karpv1.NodeClaim) error {
336418
ctx = log.IntoContext(ctx, log.FromContext(ctx).WithValues("NodeClaim", nodeClaim.Name))
419+
420+
// AKS machine-based node?
421+
if aksMachineName, isAKSMachine := instance.GetAKSMachineNameFromNodeClaim(nodeClaim); isAKSMachine {
422+
return c.aksMachineInstanceProvider.Delete(ctx, aksMachineName)
423+
}
424+
425+
// VM-based node
337426
vmName, err := nodeclaimutils.GetVMName(nodeClaim.Status.ProviderID)
338427
if err != nil {
339428
return fmt.Errorf("getting VM name, %w", err)
@@ -481,7 +570,7 @@ func (c *CloudProvider) vmInstanceToNodeClaim(ctx context.Context, vm *armcomput
481570
labels[karpv1.NodePoolLabelKey] = *tag
482571
}
483572

484-
nodeClaim.Name = GetNodeClaimNameFromVMName(*vm.Name)
573+
nodeClaim.Name = GenerateNodeClaimName(*vm.Name)
485574
nodeClaim.Labels = labels
486575
nodeClaim.Annotations = annotations
487576
nodeClaim.CreationTimestamp = metav1.Time{Time: *vm.Properties.TimeCreated}
@@ -496,7 +585,7 @@ func (c *CloudProvider) vmInstanceToNodeClaim(ctx context.Context, vm *armcomput
496585
return nodeClaim, nil
497586
}
498587

499-
func GetNodeClaimNameFromVMName(vmName string) string {
588+
func GenerateNodeClaimName(vmName string) string {
500589
return strings.TrimPrefix(vmName, "aks-")
501590
}
502591

@@ -519,6 +608,7 @@ func setAdditionalAnnotationsForNewNodeClaim(ctx context.Context, nodeClaim *kar
519608
// Additional annotations
520609
// ASSUMPTION: this is not needed in other places that the core also wants NodeClaim (e.g., Get, List).
521610
// As of the time of writing, AWS is doing something similar.
611+
// Suggestion: could have added this in instance.BuildNodeClaimFromAKSMachine, but might sacrifice some performance (little?), and need to consider that the calculated hash may change.
522612
inPlaceUpdateHash, err := inplaceupdate.HashFromNodeClaim(options.FromContext(ctx), nodeClaim, nodeClass)
523613
if err != nil {
524614
return fmt.Errorf("failed to calculate in place update hash, %w", err)
@@ -530,3 +620,30 @@ func setAdditionalAnnotationsForNewNodeClaim(ctx context.Context, nodeClaim *kar
530620
})
531621
return nil
532622
}
623+
624+
func (c *CloudProvider) resolveNodeClaimFromAKSMachine(ctx context.Context, aksMachine *armcontainerservice.Machine) (*karpv1.NodeClaim, error) {
625+
var instanceTypes []*cloudprovider.InstanceType
626+
nodePool, err := instance.FindNodePoolFromAKSMachine(ctx, aksMachine, c.kubeClient)
627+
if err == nil {
628+
gotInstanceTypes, err := c.GetInstanceTypes(ctx, nodePool)
629+
if err == nil {
630+
instanceTypes = gotInstanceTypes
631+
} else if client.IgnoreNotFound(err) != nil {
632+
// Unknown error
633+
return nil, fmt.Errorf("resolving node pool instance types, %w", err)
634+
}
635+
// If GetInstanceTypes returns not found, we tolerate. But, possible instance types will be empty.
636+
} else if client.IgnoreNotFound(err) != nil {
637+
// Unknown error
638+
return nil, fmt.Errorf("resolving node pool, %w", err)
639+
}
640+
// If FindNodePoolFromAKSMachine returns not found, we tolerate. But, possible instance types will be empty.
641+
642+
// ASSUMPTION: all machines are in the same location, and in the current pool.
643+
nodeClaim, err := instance.BuildNodeClaimFromAKSMachine(ctx, aksMachine, instanceTypes, c.aksMachineInstanceProvider.GetMachinesPoolLocation())
644+
if err != nil {
645+
return nil, fmt.Errorf("converting AKS machine instance to node claim, %w", err)
646+
}
647+
648+
return nodeClaim, nil
649+
}

0 commit comments

Comments
 (0)