kubernetes/kops · error

unhandled role %q

Error message

unhandled role %q

What it means

Thrown by defaultInstanceType's switch when ig.Spec.Role does not match any handled case in the flavor-selection switch. The role value is outside the set of OpenStack instance group roles kOps knows how to size, so it refuses to guess a flavor.

Source

Thrown at upup/pkg/fi/cloudup/openstack/utils.go:98

			}
		}

	case ig.Spec.Role.HasNode():
		for _, flavor := range fList {
			if flavor.RAM >= 4096 && flavor.VCPUs >= 2 {
				candidates = append(candidates, flavor)
			}
		}

	case ig.Spec.Role.HasBastion():
		for _, flavor := range fList {
			if flavor.RAM >= 1024 {
				candidates = append(candidates, flavor)
			}
		}

	default:
		return "", fmt.Errorf("unhandled role %q", ig.Spec.Role)
	}
	if len(candidates) == 0 {
		return "", fmt.Errorf("No suitable flavor for role %q", ig.Spec.Role)
	}
	return candidates[0].Name, nil
}

func GetServerFixedIP(server *servers.Server, interfaceName string) (poolAddress string, err error) {
	if localAddr, ok := server.Addresses[interfaceName]; ok {
		if localAddresses, ok := localAddr.([]interface{}); ok {
			for _, addr := range localAddresses {
				addrMap := addr.(map[string]interface{})
				if addrType, ok := addrMap[openstackExternalIPType]; ok && addrType == openstackAddressFixed {
					if fixedIP, ok := addrMap[openstackAddress]; ok {
						if fixedIPStr, ok := fixedIP.(string); ok {
							poolAddress = fixedIPStr
						} else {
							err = fmt.Errorf("Fixed IP was not a string: %v", fixedIP)

View on GitHub (pinned to 4c8573c808)

Solutions

  1. Check the instance group's spec.role value and correct it (valid values: control-plane/master, node, bastion).
  2. Regenerate/inspect the instance group with `kops get ig -o yaml` using a matching kOps version.
  3. Upgrade kOps if the role was introduced in a newer release than the binary in use.

Example fix

// before
csvD.spec.Role = "Node" // invalid casing/string
// after
ig.Spec.Role = kopsapi.InstanceGroupRoleNode
Defensive patterns

Strategy: validation

Validate before calling

switch ig.Spec.Role {
case kopsapi.InstanceGroupRoleControlPlane, kopsapi.InstanceGroupRoleNode, kopsapi.InstanceGroupRoleBastion:
    // ok
default:
    return fmt.Errorf("unsupported role %q", ig.Spec.Role)
}

Type guard

func isValidRole(r kopsapi.InstanceGroupRole) bool {
    switch r {
    case kopsapi.InstanceGroupRoleControlPlane, kopsapi.InstanceGroupRoleNode, kopsapi.InstanceGroupRoleBastion:
        return true
    }
    return false
}

Prevention

When it happens

Trigger: Calling DefaultInstanceType with an InstanceGroup whose Spec.Role falls into the switch's default branch — e.g. a role type added in a newer kOps, an invalid role string in hand-edited YAML, or the bare 'node' role not matching the HasControlPlane()/specific-case predicates handled above.

Common situations: Cluster specs created by newer kOps versions with roles this build doesn't recognize; typos in instance group YAML role fields; applying a spec produced for another cloud provider's role naming.

Related errors


AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05). Data as JSON: /api/errors/53f6f6ffaf097857. Report an issue: GitHub.