k3s-io/k3s · error
invalid output format: {cfg.Output}
Error message
invalid output format: {cfg.Output} What it means
The kubeadm token-create style command validates its --output flag against a closed set {text, json, yaml}; an empty value defaults to text, anything else is rejected immediately before any token is generated.
Source
Thrown at pkg/kubeadm/token.go:35
// SetDefaults ensures that the default values are set on the token configuration.
// These are set here, rather than in the default Token struct, to avoid
// importing the cluster-bootstrap packages into the CLI.
func SetDefaults(clx *cli.Context, cfg *cmds.Token) error {
if !clx.IsSet("groups") {
cfg.Groups = *cli.NewStringSlice(NodeBootstrapTokenAuthGroup)
}
if !clx.IsSet("usages") {
cfg.Usages = *cli.NewStringSlice(bootstrapapi.KnownTokenUsages...)
}
if cfg.Output == "" {
cfg.Output = "text"
} else {
switch cfg.Output {
case "text", "json", "yaml":
default:
return errors.New("invalid output format: " + cfg.Output)
}
}
if clx.Args().Len() > 0 {
cfg.Token = clx.Args().Get(0)
}
if cfg.Token == "" {
var err error
cfg.Token, err = bootstraputil.GenerateBootstrapToken()
if err != nil {
return err
}
}
return nil
}
View on GitHub (pinned to 6ba341e396)
Solutions
- Use one of: --output=text, --output=json, --output=yaml.
- Omit --output entirely when plain text is desired (it is the default).
- Validate the variable before passing it: case "$OUT" in text|json|yaml) ;; *) echo bad ;; esac.
Example fix
# before k3s token create --output=wide # after k3s token create --output=json
Defensive patterns
Strategy: validation
Validate before calling
switch cfg.Output {
case "", "text", "json", "yaml":
default:
return fmt.Errorf("invalid output format %q (want text|json|yaml)", cfg.Output)
} Type guard
func validOutputFormat(s string) bool {
switch s {
case "", "text", "json", "yaml":
return true
}
return false
} Prevention
- Default script variables explicitly: OUTPUT=${OUTPUT:-text}.
- Do not copy --output values from kubectl docs.
When it happens
Trigger: Running 'k3s token create --output=wide' or --output=table, or piping a script variable that is unset/whitespace into --output.
Common situations: Copy-pasting from kubectl docs where 'wide'/'name' are valid; shell defaults like OUTPUT=${OUTPUT:-table}; YAML templating that injects quotes into the value.
Related errors
- --token is required
- --server is required
- service %s is not recognized
- no snapshots given for removal
- invalid output format:
AI-assisted analysis of k3s-io/k3s@6ba341e396 (2026-08-15).
Data as JSON: /api/errors/43fca34e7f075e4b.
Report an issue: GitHub.