kubernetes/kops · error
MockAWSCloud DefaultInstanceType does not handle %s
Error message
MockAWSCloud DefaultInstanceType does not handle %s
What it means
MockAWSCloud.DefaultInstanceType returns a canned instance type per InstanceGroup role (master, node, bastion). If the role matches none of the handled cases (an unhandled/unknown role), this error is returned. It surfaces when tests use instance groups with roles outside the mock's supported set.
Source
Thrown at upup/pkg/fi/cloudup/awsup/mock_aws_cloud.go:299
func (c *MockAWSCloud) FindVPCInfo(id string) (*fi.VPCInfo, error) {
return findVPCInfo(c, id)
}
func (c *MockAWSCloud) GetApiIngressStatus(cluster *kops.Cluster) ([]fi.ApiIngressStatus, error) {
return getApiIngressStatus(c, cluster)
}
// DefaultInstanceType determines an instance type for the specified cluster & instance group
func (c *MockAWSCloud) DefaultInstanceType(cluster *kops.Cluster, ig *kops.InstanceGroup) (string, error) {
switch {
case ig.Spec.Role.IsControlPlaneType():
return "m3.medium", nil
case ig.Spec.Role.HasNode():
return "t2.medium", nil
case ig.Spec.Role.HasBastion():
return "t2.micro", nil
default:
return "", fmt.Errorf("MockAWSCloud DefaultInstanceType does not handle %s", ig.Spec.Role)
}
}
// DescribeInstanceType calls ec2.DescribeInstanceType to get information for a particular instance type
func (c *MockAWSCloud) DescribeInstanceType(instanceType string) (*ec2types.InstanceTypeInfo, error) {
if instanceType == "t2.invalidType" {
return nil, fmt.Errorf("invalid instance type %q specified", "t2.invalidType")
}
info := &ec2types.InstanceTypeInfo{
NetworkInfo: &ec2types.NetworkInfo{
MaximumNetworkInterfaces: aws.Int32(1),
Ipv4AddressesPerInterface: aws.Int32(1),
},
MemoryInfo: &ec2types.MemoryInfo{
SizeInMiB: aws.Int64(1024),
},
VCpuInfo: &ec2types.VCpuInfo{
DefaultVCpus: aws.Int32(2),View on GitHub (pinned to 4c8573c808)
Solutions
- Set ig.Spec.Role explicitly (InstanceGroupRoleMaster/Node/Bastion) in the test before calling DefaultInstanceType.
- Add a case to the mock's switch for the new role, returning a reasonable instance type.
- Update the mock if a recently added kOps role is not covered.
Example fix
// before
ig := &api.InstanceGroup{Spec: api.InstanceGroupSpec{}} // Role unset
t, err := c.DefaultInstanceType(ig) // error
// after
ig := &api.InstanceGroup{Spec: api.InstanceGroupSpec{Role: api.InstanceGroupRoleNode}}
t, err := c.DefaultInstanceType(ig) // "t2.medium", nil Defensive patterns
Strategy: validation
Validate before calling
if ig.Spec.Role == "" {
ig.Spec.Role = api.InstanceGroupRoleNode // or fail fast in test setup
} Try / catch
t, err := c.DefaultInstanceType(ig)
if err != nil {
t.Fatalf("unhandled role %q in mock: %v", ig.Spec.Role, err)
} Prevention
- Always set Spec.Role when constructing InstanceGroups in tests
- Update MockAWSCloud.DefaultInstanceType's switch when new kOps roles are added
- Cover DefaultInstanceType in a table-driven test enumerating all roles
When it happens
Trigger: Calling DefaultInstanceType with an InstanceGroup whose Spec.Role is empty, or a role added to kOps after the mock was written (e.g. some specialized role) that lacks a case in the switch.
Common situations: Building test instance groups without setting Spec.Role; new kOps roles introduced while mock clouds kept the old switch; tests that construct InstanceGroup structs manually and forget Role.
Related errors
- expected exactly one subnet for InstanceGroup %q; subnets wa
- MockRoute53 not set
- MockAWSCloud DescribeInstance not implemented
- MockDNS not set
- DeviceName not set for volume
AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05).
Data as JSON: /api/errors/70c63341508252dc.
Report an issue: GitHub.