kubernetes/kops · error

unable decode the configuration file: %s, error: %v

Error message

unable decode the configuration file: %s, error: %v

What it means

After reading a --values file, newTemplateContext parses it with utils.YamlUnmarshal into map[string]interface{}. If the YAML is malformed or its top level is not a mapping, this error is returned wrapping the parse error.

Source

Thrown at cmd/kops/toolbox_template.go:249

// newTemplateContext is responsible for loading the --values and build a context for the template
func newTemplateContext(files []string, values []string, stringValues []string) (map[string]interface{}, error) {
	context := make(map[string]interface{})

	for _, x := range files {
		list, err := expandFiles(utils.ExpandPath(x))
		if err != nil {
			return nil, err
		}
		for _, j := range list {
			content, err := os.ReadFile(j)
			if err != nil {
				return nil, fmt.Errorf("unable to configuration file: %s, error: %s", j, err)
			}

			ctx := make(map[string]interface{})
			if err := utils.YamlUnmarshal(content, &ctx); err != nil {
				return nil, fmt.Errorf("unable decode the configuration file: %s, error: %v", j, err)
			}
			context = mergeMaps(context, ctx)
		}
	}

	// User specified a value via --set
	for _, value := range values {
		if err := helmstrvals.ParseInto(value, context); err != nil {
			return nil, fmt.Errorf("failed parsing --set data: %s", err)
		}
	}

	// User specified a value via --set-string
	for _, value := range stringValues {
		if err := helmstrvals.ParseIntoString(value, context); err != nil {
			return nil, fmt.Errorf("failed parsing --set-string data: %s", err)
		}
	}

View on GitHub (pinned to 4c8573c808)

Solutions

  1. Validate the YAML with `yamllint <file>` or a YAML parser and fix syntax errors.
  2. Ensure the top-level structure is a mapping (key: value), not a list or scalar.
  3. Replace tab characters with spaces and fix indentation.

Example fix

// before (invalid)
	key: value
// after
key: value
Defensive patterns

Strategy: validation

Validate before calling

var ctx map[string]interface{}
if err := utils.YamlUnmarshal(mustRead(valuesPath), &ctx); err != nil { return err } // same parser kops uses

Type guard

func isYAMLMapping(b []byte) bool { var m map[string]interface{}; return utils.YamlUnmarshal(b, &m) == nil }

Try / catch

out, err := exec.Command("kops", "toolbox", "template", "--values", p, ...).CombinedOutput()
if strings.Contains(string(out), "unable decode the configuration file") { lint the YAML and fix syntax }

Prevention

When it happens

Trigger: Running `kops toolbox template --values <file>` where the file contains invalid YAML syntax, or the document root is a list/scalar instead of a map.

Common situations: Bad indentation, tabs instead of spaces, duplicate keys, unquoted special characters, or a values file starting with '- ' (a list).

Related errors


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