kubernetes/kops · error

building tags for %q: %w

Error message

building tags for %q: %w

What it means

Returned by buildKarpenterEC2NodeClass when tf.CloudTagsForInstanceGroup(ig) fails to compute cloud tags for the instance group. Tags feed the EC2NodeClass tags (after karpenterEC2NodeClassTags filtering), so tag computation failures block rendering.

Source

Thrown at upup/pkg/fi/cloudup/template_functions_karpenter.go:227

		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 {
		return nil, fmt.Errorf("reading userData for %q: %w", ig.Name, err)
	}
	rootDeviceName, err := tf.karpenterRootDeviceName(ig.Spec.Image)
	if err != nil {
		return nil, fmt.Errorf("resolving root device for %q: %w", ig.Name, err)
	}
	blockDeviceMappings, err := buildKarpenterBlockDeviceMappings(ig, rootDeviceName)
	if err != nil {
		return nil, fmt.Errorf("building blockDeviceMappings for %q: %w", ig.Name, err)
	}

View on GitHub (pinned to 4c8573c808)

Solutions

  1. Check the wrapped error from CloudTagsForInstanceGroup for the failing field
  2. Ensure the cluster spec and instance group spec are complete and validated
  3. Verify the TemplateFunctions was built with the correct cluster context
  4. Simplify custom tag configuration (cloudLabels/hooks) if it errors

Example fix

// before: invalid hook-derived label
cloudLabels:
  dynamic-tag: "{{ .BadTemplate }}"
// after
cloudLabels:
  environment: production
Defensive patterns

Strategy: validation

Validate before calling

// sanity-check tag sources before rendering
if tf.ClusterName() == "" {
	return errors.New("cluster name unset; cloud tags cannot be computed")
}
if ig == nil || ig.Name == "" {
	return errors.New("instance group missing; cloud tags cannot be computed")
}

Try / catch

nc, err := tf.KarpenterEC2NodeClass(ig)
if err != nil {
	return fmt.Errorf("tag building for %q failed: %w", ig.Name, err)
}

Prevention

When it happens

Trigger: CloudTagsForInstanceGroup returns an error, e.g. cluster or instance-group metadata required for tag generation is unavailable or invalid (nil cluster, missing spec fields).

Common situations: Rendering templates with a TemplateFunctions whose cluster context is not fully initialized; instance group with invalid spec causing tag building to fail; custom hook-based tag configuration erroring.

Related errors


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