func ParseAgentPoolNameFromID()

in pkg/utils/utils.go [27:46]


func ParseAgentPoolNameFromID(id string) (string, error) {
	///subscriptions/%s/resourceGroups/%s/providers/Microsoft.Compute/virtualMachineScaleSets/<VMSSName>/virtualMachines/0
	r := regexp.MustCompile(`azure:///subscriptions/.*/resourceGroups/.*/providers/Microsoft.Compute/virtualMachineScaleSets/(?P<VMSSName>.*)/virtualMachines/.*`)
	matches := r.FindStringSubmatch(id)
	if matches == nil {
		return "", fmt.Errorf("id does not match the regxp for ParseAgentPoolNameFromID %s", id)
	}

	for i, name := range r.SubexpNames() {
		if name == "VMSSName" {
			nodeName := matches[i]
			agentPoolName := strings.Split(nodeName, "-") // agentpool name is the second substring
			if len(agentPoolName) == 0 {
				return "", fmt.Errorf("cannot parse agentpool name for ParseAgentPoolNameFromID %s", id)
			}
			return agentPoolName[1], nil
		}
	}
	return "", fmt.Errorf("error while parsing id %s", id)
}