kubernetes/kops · error
building amiSelectorTerms for %q: %w
Error message
building amiSelectorTerms for %q: %w
What it means
Returned by buildKarpenterEC2NodeClass when buildKarpenterAMITerms(ig.Spec.Image) fails to translate the instance group's image setting into valid Karpenter amiSelectorTerms. The error names the instance group so the broken image spec can be located.
Source
Thrown at upup/pkg/fi/cloudup/template_functions_karpenter.go:217
nodePool, err := tf.buildKarpenterNodePool(ig)
if err != nil {
return "", err
}
return marshalKarpenterResource(ig, nodePool)
}
func marshalKarpenterResource(ig *kops.InstanceGroup, object interface{}) (string, error) {
data, err := yaml.Marshal(object)
if err != nil {
return "", fmt.Errorf("marshaling Karpenter resource for %q: %w", ig.Name, err)
}
return strings.TrimSpace(string(data)), nil
}
func (tf *TemplateFunctions) buildKarpenterEC2NodeClass(ig *kops.InstanceGroup) (*karpenterEC2NodeClass, error) {
amiSelectorTerms, err := buildKarpenterAMITerms(ig.Spec.Image)
if err != nil {
return nil, fmt.Errorf("building amiSelectorTerms for %q: %w", ig.Name, err)
}
instanceProfile, err := tf.LinkToIAMInstanceProfile(ig)
if err != nil {
return nil, fmt.Errorf("building instance profile for %q: %w", ig.Name, err)
}
tags, err := tf.CloudTagsForInstanceGroup(ig)
if err != nil {
return nil, fmt.Errorf("building tags for %q: %w", ig.Name, err)
}
tags = karpenterEC2NodeClassTags(tags)
associatePublicIP, err := tf.karpenterAssociatePublicIP(ig)
if err != nil {
return nil, err
}
userData, err := tf.managedFileContents("nodeupscript-" + ig.Name)
if err != nil {View on GitHub (pinned to 4c8573c808)
Solutions
- Check ig.Spec.Image for the named instance group and correct the image value
- Use a supported image alias or a full AMI ID / valid selector term
- Compare with buildKarpenterAMITerms implementation for accepted formats
- Run kops cluster spec validation before rendering
Example fix
// before image: my-custom-thing // after image: 099720109477/ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-20240215 # or a supported alias
Defensive patterns
Strategy: validation
Validate before calling
// pre-validate the image before rendering Karpenter resources
if ig.Spec.Image == "" || !isValidKarpenterImageSelector(ig.Spec.Image) {
return fmt.Errorf("instance group %q has unsupported image %q", ig.Name, ig.Spec.Image)
} Try / catch
nc, err := tf.KarpenterEC2NodeClass(ig)
if err != nil {
return fmt.Errorf("EC2NodeClass for %q: %w", ig.Name, err)
} Prevention
- Validate ig.Spec.Image against supported aliases/selectors before cluster creation
- Use kops-supported image identifiers (aliases or known AMI IDs)
- Add spec validation tests for image values on Karpenter instance groups
- Re-validate specs after kops upgrades where image handling changes
When it happens
Trigger: ig.Spec.Image is set to a value buildKarpenterAMITerms cannot parse — an unrecognized alias, an invalid AMI selector expression, or an empty/invalid image string where a concrete selector is required.
Common situations: Instance group image set to an unsupported alias (e.g. a distro name not handled), typo in a selector string, image field left at an older format after upgrading kops, cross-account/private AMI IDs unsupported.
Related errors
- building tags for %q: %w
- resolving root device for %q: %w
- error parsing Kubernetes version %q: %v
- cannot find subnet %q (declared in instance group %q, not fo
- InstanceGroup #%d did not have a Name
AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05).
Data as JSON: /api/errors/9443da13cf6dba33.
Report an issue: GitHub.