kubernetes/kops · error

snippet cannot have the same name as the template: %s

Error message

snippet cannot have the same name as the template: %s

What it means

templater.Render builds a Go text/template from the main template plus optional named snippets. A snippet registered under the exact same name as the template itself would overwrite the template in the template set, so Render rejects it up front with this error naming the conflicting filename.

Source

Thrown at pkg/util/templater/templater.go:58

		channel: channel,
	}
}

// Render is responsible for actually rendering the template
func (r *Templater) Render(content string, context map[string]interface{}, snippets map[string]string, failOnMissing bool) (rendered string, err error) {
	// @step: create the template
	tm := template.New(templateName)
	if _, err = tm.Funcs(r.templateFuncsMap(tm)).Parse(content); err != nil {
		return
	}
	if failOnMissing {
		tm.Option("missingkey=error")
	}

	// @step: add the snippits into the mix
	for filename, snippet := range snippets {
		if filename == templateName {
			return "", fmt.Errorf("snippet cannot have the same name as the template: %s", filename)
		}
		if _, err = tm.New(filename).Parse(snippet); err != nil {
			return rendered, fmt.Errorf("unable to parse snippet: %s, error: %s", filename, err)
		}
	}

	// @step: render the actual template
	writer := new(bytes.Buffer)
	defer func() {
		if r := recover(); r != nil {
			err = fmt.Errorf("failed to parse template, error: %s", r)
		}
	}()
	if err = tm.ExecuteTemplate(writer, templateName, context); err != nil {
		return
	}

	return writer.String(), nil

View on GitHub (pinned to 4c8573c808)

Solutions

  1. Rename the snippet so it differs from the template name shown in the error
  2. Check the snippets directory for a file whose basename matches the template and move/delete it
  3. If generating snippets programmatically, assert keys != templateName before calling Render

Example fix

// before
snippets := map[string]string{"nodeup": snippet} // collides with templateName "nodeup"
rendered, err := t.Render(snippets, values, "nodeup", "")
// after
snippets := map[string]string{"nodeup-config": snippet}
rendered, err := t.Render(snippets, values, "nodeup", "")
Defensive patterns

Strategy: validation

Validate before calling

// Reject colliding snippet keys before Render
for name := range snippets {
	if name == templateName {
		return fmt.Errorf("snippet %q collides with template name", name)
	}
}

Prevention

When it happens

Trigger: Calling Render with a snippets map containing a key equal to the templateName argument — e.g. a snippet file named the same as the base template (both "cluster.yaml") in the snippets directory.

Common situations: Dropping a snippet file into the snippets dir with the same basename as the main template, or programmatically building a snippets map where one key collides with the template name.

Related errors


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