kubernetes/kops · error

must set output flag; yaml or json

Error message

must set output flag; yaml or json

What it means

In --dry-run mode, RunCreateInstanceGroup must serialize the IG to a file-like output, but the --output flag was empty so the format (yaml or json) is unknown. Only the dry-run path requires this flag.

Source

Thrown at cmd/kops/create_instancegroup.go:233

	ig, err = cloudup.PopulateInstanceGroupSpec(cluster, ig, cloud, channel)
	if err != nil {
		return err
	}

	ig.AddInstanceGroupNodeLabel()
	if cluster.GetCloudProvider() == kopsapi.CloudProviderGCE {
		if len(ig.Spec.Zones) == 0 {
			return fmt.Errorf("zone flag is required for GCE clusters")
		}
		fmt.Println("detected a GCE cluster; labeling nodes to receive metadata-proxy.")
		ig.Spec.NodeLabels["cloud.google.com/metadata-proxy-ready"] = "true"
	}

	if options.DryRun {

		if options.Output == "" {
			return fmt.Errorf("must set output flag; yaml or json")
		}

		// Cluster name is not populated, and we need it
		ig.ObjectMeta.Labels = make(map[string]string)
		ig.ObjectMeta.Labels[kopsapi.LabelClusterName] = cluster.ObjectMeta.Name

		switch options.Output {
		case OutputYaml:
			if err := fullOutputYAML(out, ig); err != nil {
				return fmt.Errorf("error writing cluster yaml to stdout: %v", err)
			}
			return nil
		case OutputJSON:
			if err := fullOutputJSON(out, true, ig); err != nil {
				return fmt.Errorf("error writing cluster json to stdout: %v", err)
			}
			return nil
		default:

View on GitHub (pinned to 4c8573c808)

Solutions

  1. Add --output yaml or --output json to the dry-run command
  2. Omit --dry-run if you want the IG created directly in the state store
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at cmd/kops/create_instancegroup.go:233 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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