kubernetes/kops · error

error rendering LaunchTemplate UserData: %v

Error message

error rendering LaunchTemplate UserData: %v

What it means

RenderAWS renders the task's UserData resource into bytes via fi.ResourceAsBytes(t.UserData) before base64-encoding it into the EC2 launch template. If the resource cannot be rendered (I/O error reading a file resource, template expansion failure), kOps wraps the failure as 'error rendering LaunchTemplate UserData'.

Source

Thrown at upup/pkg/fi/cloudup/awstasks/launchtemplate_target_api.go:133

		}
		data.TagSpecifications = append(data.TagSpecifications, ec2types.LaunchTemplateTagSpecificationRequest{
			ResourceType: ec2types.ResourceTypeInstance,
			Tags:         tags,
		})
		data.TagSpecifications = append(data.TagSpecifications, ec2types.LaunchTemplateTagSpecificationRequest{
			ResourceType: ec2types.ResourceTypeVolume,
			Tags:         tags,
		})
		data.TagSpecifications = append(data.TagSpecifications, ec2types.LaunchTemplateTagSpecificationRequest{
			ResourceType: ec2types.ResourceTypeNetworkInterface,
			Tags:         tags,
		})
	}
	// @step: add the userdata
	if t.UserData != nil {
		d, err := fi.ResourceAsBytes(t.UserData)
		if err != nil {
			return fmt.Errorf("error rendering LaunchTemplate UserData: %v", err)
		}
		data.UserData = aws.String(base64.StdEncoding.EncodeToString(d))
	}
	// @step: add market options
	if fi.ValueOf(t.SpotPrice) != "" {
		s := &ec2types.LaunchTemplateSpotMarketOptionsRequest{
			BlockDurationMinutes: t.SpotDurationInMinutes,
			MaxPrice:             t.SpotPrice,
		}
		if t.InstanceInterruptionBehavior != nil {
			s.InstanceInterruptionBehavior = fi.ValueOf(t.InstanceInterruptionBehavior)
		}
		data.InstanceMarketOptions = &ec2types.LaunchTemplateInstanceMarketOptionsRequest{
			MarketType:  ec2types.MarketTypeSpot,
			SpotOptions: s,
		}
	}
	if fi.ValueOf(t.CPUCredits) != "" {

View on GitHub (pinned to 4c8573c808)

Solutions

  1. Read the wrapped error to find which resource failed to render.
  2. Verify any file-based userdata (hooks, file assets, custom nodeup script) exists and is readable on the machine running kops.
  3. Re-run kops update to regenerate assets; if using templates, fix the template errors.

Example fix

// before
userData: file:///etc/kops/missing-bootstrap.sh
// after
userData: file:///etc/kops/bootstrap.sh  // file exists and readable
Defensive patterns

Strategy: validation

Validate before calling

// ensure referenced userdata files exist and render before apply
for f in $(kops get ig -o yaml | yq '.spec.hooks[].execContainer.command[0]' 2>/dev/null); do test -r "$f" || echo "missing: $f"; done

Try / catch

if strings.Contains(err.Error(), "error rendering LaunchTemplate UserData") { fix the unreadable/invalid resource named in the wrapped error and re-apply }

Prevention

When it happens

Trigger: RenderAWS where t.UserData != nil and fi.ResourceAsBytes fails - unreadable file backing the resource, failed templating/string expansion, or a nil/dead resource body.

Common situations: Custom nodeup/bootstrap script referenced by path that no longer exists; a templated userdata referencing missing values; broken addon/hook asset producing an invalid resource.

Related errors


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