Improved fn framework support for patching

- Generate patches with a func
- Generate patches for containers
This commit is contained in:
Phillip Wittrock
2020-11-24 12:02:55 -08:00
parent f8194bd3c2
commit f2706dce68
4 changed files with 261 additions and 9 deletions

View File

@@ -13,12 +13,18 @@ import (
"sigs.k8s.io/kustomize/kyaml/yaml/merge2"
)
// PatchTemplateContainers executes t as a template and patches each container in each resource
// PatchContainersWithString executes t as a template and patches each container in each resource
// with the result.
func PatchTemplateContainers(resources []*yaml.RNode, t string, input interface{}, containers ...string) error {
func PatchContainersWithString(resources []*yaml.RNode, t string, input interface{}, containers ...string) error {
resourcePatch := template.Must(template.New("containers").Parse(t))
return PatchContainersWithTemplate(resources, resourcePatch, input, containers...)
}
// PatchContainersWithTemplate executes t and patches each container in each resource
// with the result.
func PatchContainersWithTemplate(resources []*yaml.RNode, t *template.Template, input interface{}, containers ...string) error {
var b bytes.Buffer
if err := resourcePatch.Execute(&b, input); err != nil {
if err := t.Execute(&b, input); err != nil {
return errors.Wrap(err)
}
patch, err := yaml.Parse(b.String())