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

  1. Check ig.Spec.Image for the named instance group and correct the image value
  2. Use a supported image alias or a full AMI ID / valid selector term
  3. Compare with buildKarpenterAMITerms implementation for accepted formats
  4. 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

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


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