kubernetes/kops · error

error during apply: %w

Error message

error during apply: %w

What it means

GetAssetBuilder runs a full cloudup apply in DryRun mode (TargetDryRun, GetAssets=true) to build the asset builder. Any error returned by apply.Run is wrapped with 'error during apply: %w'. This surfaces all cluster-apply failures (validation, cloud API, templating) from the asset-building path.

Source

Thrown at pkg/commands/toolbox_enroll.go:702

	cloud, err := b.GetCloud(ctx)
	if err != nil {
		return nil, err
	}

	// ApplyClusterCmd is used to get the assets.
	// We use DryRun and GetAssets to do this without applying any changes.
	apply := &cloudup.ApplyClusterCmd{
		Cloud:      cloud,
		Cluster:    cluster,
		Clientset:  clientset,
		DryRun:     true,
		GetAssets:  true,
		TargetName: cloudup.TargetDryRun,
	}
	applyResults, err := apply.Run(ctx)
	if err != nil {
		return nil, fmt.Errorf("error during apply: %w", err)
	}
	b.AssetBuilder = applyResults.AssetBuilder
	return b.AssetBuilder, nil
}

func (b *ConfigBuilder) GetWellKnownAddresses(ctx context.Context) (model.WellKnownAddresses, error) {
	if b.wellKnownAddresses != nil {
		return *b.wellKnownAddresses, nil
	}

	cloud, err := b.GetCloud(ctx)
	if err != nil {
		return nil, err
	}

	fullCluster, err := b.GetFullCluster(ctx)
	if err != nil {
		return nil, err

View on GitHub (pinned to 4c8573c808)

Solutions

  1. Read the wrapped cause (%w) — it names the actual apply failure; fix that underlying issue first.
  2. Run `kops update cluster --dry-run` manually with the same flags to reproduce the apply error directly.
  3. Validate the spec with `kops validate` / `kops replace -f` to catch schema/feature errors.
  4. Refresh cloud credentials (AWS_PROFILE / GOOGLE_APPLICATION_CREDENTIALS / AZURE_AUTH) and retry.
  5. Upgrade/align the kops binary version with the cluster's kopsVersionChannel.

Example fix

// before
applyResults, err := apply.Run(ctx)
if err != nil { return nil, fmt.Errorf("error during apply: %w", err) }
// after
// inspect the wrapped cause; e.g. fix the spec error reported by the inner apply error
applyResults, err := apply.Run(ctx)
if err != nil {
	return nil, fmt.Errorf("error during apply: %w", err) // fix cause reported by %w
}
Defensive patterns

Strategy: try-catch

Validate before calling

// Pre-flight: dry-run apply via the CLI to surface apply errors early
if out, err := exec.Command("kops", "update", "cluster", clusterName, "--dry-run").CombinedOutput(); err != nil {
	return fmt.Errorf("apply pre-flight failed: %v: %s", err, out)
}

Try / catch

var applyErr *ApplyError
if errors.As(err, &applyErr) {
	// inspect applyErr cause: validation vs cloud API vs templating
	return fmt.Errorf("apply failed: %w", applyErr)
}
return err

Prevention

When it happens

Trigger: GetAssetBuilder (or GetBootstrapData which calls it) invoking apply.Run when the cluster spec fails validation, cloud credentials/API calls fail, or instance group/model rendering errors occur during dry-run apply.

Common situations: Invalid or outdated cluster spec (e.g. kubernetesVersion not supported); expired/insufficient cloud IAM credentials; unreachable cloud API (network/region mismatch); broken addons or hooks referencing missing files; feature-flag mismatch after kops upgrade.

Related errors


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