{"record":{"id":"70c63341508252dc","repo":"kubernetes/kops","slug":"mockawscloud-defaultinstancetype-does-not-handle","errorCode":null,"errorMessage":"MockAWSCloud DefaultInstanceType does not handle %s","messagePattern":"MockAWSCloud DefaultInstanceType does not handle (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"upup/pkg/fi/cloudup/awsup/mock_aws_cloud.go","lineNumber":299,"sourceCode":"func (c *MockAWSCloud) FindVPCInfo(id string) (*fi.VPCInfo, error) {\n\treturn findVPCInfo(c, id)\n}\n\nfunc (c *MockAWSCloud) GetApiIngressStatus(cluster *kops.Cluster) ([]fi.ApiIngressStatus, error) {\n\treturn getApiIngressStatus(c, cluster)\n}\n\n// DefaultInstanceType determines an instance type for the specified cluster & instance group\nfunc (c *MockAWSCloud) DefaultInstanceType(cluster *kops.Cluster, ig *kops.InstanceGroup) (string, error) {\n\tswitch {\n\tcase ig.Spec.Role.IsControlPlaneType():\n\t\treturn \"m3.medium\", nil\n\tcase ig.Spec.Role.HasNode():\n\t\treturn \"t2.medium\", nil\n\tcase ig.Spec.Role.HasBastion():\n\t\treturn \"t2.micro\", nil\n\tdefault:\n\t\treturn \"\", fmt.Errorf(\"MockAWSCloud DefaultInstanceType does not handle %s\", ig.Spec.Role)\n\t}\n}\n\n// DescribeInstanceType calls ec2.DescribeInstanceType to get information for a particular instance type\nfunc (c *MockAWSCloud) DescribeInstanceType(instanceType string) (*ec2types.InstanceTypeInfo, error) {\n\tif instanceType == \"t2.invalidType\" {\n\t\treturn nil, fmt.Errorf(\"invalid instance type %q specified\", \"t2.invalidType\")\n\t}\n\tinfo := &ec2types.InstanceTypeInfo{\n\t\tNetworkInfo: &ec2types.NetworkInfo{\n\t\t\tMaximumNetworkInterfaces:  aws.Int32(1),\n\t\t\tIpv4AddressesPerInterface: aws.Int32(1),\n\t\t},\n\t\tMemoryInfo: &ec2types.MemoryInfo{\n\t\t\tSizeInMiB: aws.Int64(1024),\n\t\t},\n\t\tVCpuInfo: &ec2types.VCpuInfo{\n\t\t\tDefaultVCpus: aws.Int32(2),","sourceCodeStart":281,"sourceCodeEnd":317,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/upup/pkg/fi/cloudup/awsup/mock_aws_cloud.go#L281-L317","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nig := &api.InstanceGroup{Spec: api.InstanceGroupSpec{}} // Role unset\nt, err := c.DefaultInstanceType(ig) // error\n// after\nig := &api.InstanceGroup{Spec: api.InstanceGroupSpec{Role: api.InstanceGroupRoleNode}}\nt, err := c.DefaultInstanceType(ig) // \"t2.medium\", nil","handlingStrategy":"validation","validationCode":"if ig.Spec.Role == \"\" {\n\tig.Spec.Role = api.InstanceGroupRoleNode // or fail fast in test setup\n}","typeGuard":null,"tryCatchPattern":"t, err := c.DefaultInstanceType(ig)\nif err != nil {\n\tt.Fatalf(\"unhandled role %q in mock: %v\", ig.Spec.Role, err)\n}","preventionTips":["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"],"tags":["testing","mock","instancegroup","configuration"],"backgroundTag":"mock-not-implemented","analyzedSha":"4c8573c808a73d578c5eadc86d410646ea0b0d73","analyzedAt":"2026-09-05T04:13:19.212Z","contentChangedAt":"2026-09-05T04:13:19.212Z","schemaVersion":2},"datasetVersion":"2026-09-12T12:17:11.808Z"}