Skip to content

Commit

Permalink
Send empty type to AKS API when deleting
Browse files Browse the repository at this point in the history
- CAPZ will send out the below return types to AKS API so that the AKS API clears-out `NodeLabels` and `NodeTaints` respectively.
  - an empty Map when the `NodeLabels` are deleted.
  - an empty pointer array when the `NodeTaints` are deleted.
  • Loading branch information
nawazkh committed Oct 12, 2023
1 parent 85c23aa commit 9c3eba1
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions azure/services/agentpools/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -388,40 +388,43 @@ func (s *AgentPoolSpec) Parameters(ctx context.Context, existing interface{}) (p

// mergeSystemNodeLabels appends any kubernetes.azure.com-prefixed labels from the AKS label set
// into the local capz label set.
func mergeSystemNodeLabels(capz, aks map[string]*string) map[string]*string {
ret := capz
if ret == nil {
ret = make(map[string]*string)
func mergeSystemNodeLabels(capzLabels, aksLabels map[string]*string) map[string]*string {
if capzLabels == nil && aksLabels == nil {
return nil
}
ret := capzLabels

// Look for labels returned from the AKS node pool API that begin with kubernetes.azure.com
for aksNodeLabelKey := range aks {
for aksNodeLabelKey := range aksLabels {
if azureutil.IsAzureSystemNodeLabelKey(aksNodeLabelKey) {
ret[aksNodeLabelKey] = aks[aksNodeLabelKey]
ret[aksNodeLabelKey] = aksLabels[aksNodeLabelKey]
}
}
// Preserve nil-ness of capz
if capz == nil && len(ret) == 0 {
ret = nil
// Preserve nil-ness of capz.
// If there are no labels, we return an empty map so that AKS API will delete any existing labels.
if ret == nil && len(ret) == 0 {
ret = make(map[string]*string)
}
return ret
}

// mergeSystemNodeTaints appends any kubernetes.azure.com-prefixed taints from the AKS taint set
// into the local capz taint set.
func mergeSystemNodeTaints(capz, aks []*string) []*string {
ret := capz
if ret == nil {
ret = make([]*string, 0)
func mergeSystemNodeTaints(capzNodeTaints, aksNodeTaints []*string) []*string {
if capzNodeTaints == nil && aksNodeTaints == nil {
return nil
}
ret := capzNodeTaints

// Look for taints returned from the AKS node pool API that begin with kubernetes.azure.com
for _, aksNodeTaint := range aks {
for _, aksNodeTaint := range aksNodeTaints {
if azureutil.IsAzureSystemNodeLabelKey(*aksNodeTaint) {
ret = append(ret, aksNodeTaint)
}
}
// Preserve nil-ness of capz
if capz == nil && len(ret) == 0 {
ret = nil
if ret == nil && len(ret) == 0 {
ret = make([]*string, 0)
}
return ret
}

0 comments on commit 9c3eba1

Please sign in to comment.