in pkg/providers/instance/instance.go [213:259]
func (p *Provider) fromRegisteredAgentPoolToInstance(ctx context.Context, apObj *armcontainerservice.AgentPool) (*Instance, error) {
if apObj == nil {
return nil, fmt.Errorf("agent pool is nil")
}
nodes, err := p.getNodesByName(ctx, lo.FromPtr(apObj.Name))
if err != nil {
return nil, err
}
if len(nodes) == 0 || len(nodes) > 1 {
// NotFound is not considered as an error
// and AgentPool may create more than one instance, we need to wait agentPool remove
// the spare instance.
return nil, nil
}
// we only want to resolve providerID and construct instance based on AgentPool.
// there is no need to verify the node ready condition. so comment the following if condition.
// if node == nil || nodeutil.GetCondition(node, v1.NodeReady).Status != v1.ConditionTrue {
// // node is not found or not ready
// return nil, nil
// }
// It's need to wait node and providerID ready when create AgentPool,
// but there is no need to wait when termination controller lists all agentpools.
// because termination controller garbage leaked agentpools.
if len(nodes[0].Spec.ProviderID) == 0 {
// provider id is not found
return nil, nil
}
// tokens := strings.SplitAfter(node.Name, "-vmss") // remove the vm index "0000"
instanceLabels := lo.MapValues(apObj.Properties.NodeLabels, func(k *string, _ string) string {
return lo.FromPtr(k)
})
return &Instance{
Name: apObj.Name,
// ID: to.Ptr(fmt.Sprint("azure://", p.getVMSSNodeProviderID(lo.FromPtr(subID), tokens[0]))),
ID: to.Ptr(nodes[0].Spec.ProviderID),
Type: apObj.Properties.VMSize,
SubnetID: apObj.Properties.VnetSubnetID,
Tags: apObj.Properties.Tags,
State: apObj.Properties.ProvisioningState,
Labels: instanceLabels,
}, nil
}