kubernetes/kops · error

unknown output format: %q

Error message

unknown output format: %q

What it means

RunGetClusters switches on the --output (-o) flag; any value other than table/yaml/json (the handled cases) reaches the default branch and returns 'unknown output format'. The flag value is taken verbatim from user input with no preprocessing.

Source

Thrown at cmd/kops/get_cluster.go:188

	if options.Output != OutputTable {
		for _, c := range clusters {
			obj = append(obj, c)
		}
	}

	switch options.Output {
	case OutputTable:
		return clusterOutputTable(clusters, out)
	case OutputYaml:
		return fullOutputYAML(out, obj...)
	case OutputJSON:
		// if singleClusterSelected is true, only a single object is returned
		// otherwise to keep it consistent, always returns an array.
		// Ex: kops get clusters -ojson should will always return an array (even if 1 cluster is available)
		// kops get cluster test.example.com -o json will return a single object (since a specific cluster is selected)
		return fullOutputJSON(out, singleClusterSelected, obj...)
	default:
		return fmt.Errorf("unknown output format: %q", options.Output)
	}
}

// filterClustersByName returns the clusters matching the specified names.
// If names are specified and no cluster is found with a name, we return an error.
func filterClustersByName(clusterNames []string, clusters []*kopsapi.Cluster) ([]*kopsapi.Cluster, error) {
	if len(clusterNames) != 0 {
		// Build a map as we want to return them in the same order as args
		m := make(map[string]*kopsapi.Cluster)
		for _, c := range clusters {
			m[c.ObjectMeta.Name] = c
		}
		var filtered []*kopsapi.Cluster
		for _, clusterName := range clusterNames {
			c := m[clusterName]
			if c == nil {
				return nil, fmt.Errorf("cluster not found %q", clusterName)
			}

View on GitHub (pinned to 4c8573c808)

Solutions

  1. Use one of the supported values exactly: `-o table` (default), `-o yaml`, or `-o json`.
  2. Fix casing — the comparison is case-sensitive, so `-o YAML` must become `-o yaml`.
  3. If the value comes from a variable, validate/normalize it (e.g. `echo "$fmt" | tr 'A-Z' 'a-z'`) before invoking kops.

Example fix

// before
kops get clusters -o YAML
// after
kops get clusters -o yaml
Defensive patterns

Strategy: validation

Validate before calling

fmt="${OUTPUT_FMT:-table}"
case "$(echo "$fmt" | tr '[:upper:]' '[:lower:]')" in
  table|yaml|json) ;;
  *) echo "unsupported output: $fmt (use table|yaml|json)" >&2; exit 1;;
esac

Type guard

null

Try / catch

null

Prevention

When it happens

Trigger: `kops get clusters -o YAML`, `-o yml`, `-o text`, or any misspelled format string.

Common situations: Case-sensitivity mistakes (YAML vs yaml); muscle-memory from other tools that accept 'table' variants or abbreviations; templating scripts with interpolated format variables.

Related errors


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