diff --git a/internal/ingress/controller/template/template.go b/internal/ingress/controller/template/template.go index 7ed297fa6d..dc4b78c1a4 100644 --- a/internal/ingress/controller/template/template.go +++ b/internal/ingress/controller/template/template.go @@ -63,6 +63,9 @@ const ( // Writer is the interface to render a template type Writer interface { + // Write renders the template. + // NOTE: Implementors must ensure that the content of the returned slice is not modified by the implementation + // after the return of this function. Write(conf config.TemplateConfig) ([]byte, error) } @@ -202,7 +205,12 @@ func (t *Template) Write(conf config.TemplateConfig) ([]byte, error) { return nil, err } - return outCmdBuf.Bytes(), nil + // make a copy to ensure that we are no longer modifying the content of the buffer + out := outCmdBuf.Bytes() + res := make([]byte, len(out)) + copy(res, out) + + return res, nil } var (