mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-13 10:00:56 +00:00
Improved fn framework support for patching
- Generate patches with a func - Generate patches for containers
This commit is contained in:
@@ -286,6 +286,16 @@ type TemplateCommand struct {
|
||||
// PatchTemplates is a list of templates to render into Patches and apply.
|
||||
PatchTemplates []PatchTemplate
|
||||
|
||||
// PatchTemplateFn returns a list of templates to render into Patches and apply.
|
||||
// PatchTemplateFn is called after the ResourceList has been parsed.
|
||||
PatchTemplatesFn func(*ResourceList) ([]PatchTemplate, error)
|
||||
|
||||
// PatchContainerTemplates applies patches to matching container fields
|
||||
PatchContainerTemplates []ContainerPatchTemplate
|
||||
|
||||
// PatchContainerTemplates returns a list of PatchContainerTemplates
|
||||
PatchContainerTemplatesFn func(*ResourceList) ([]ContainerPatchTemplate, error)
|
||||
|
||||
// TemplateFiles list of templates to read from disk which are appended
|
||||
// to Templates.
|
||||
TemplatesFiles []string
|
||||
@@ -301,6 +311,13 @@ type TemplateCommand struct {
|
||||
PostProcess func(*ResourceList) error
|
||||
}
|
||||
|
||||
// ContainerPatchTemplate defines a patch to be applied to containers
|
||||
type ContainerPatchTemplate struct {
|
||||
PatchTemplate
|
||||
|
||||
ContainerNames []string
|
||||
}
|
||||
|
||||
func (tc TemplateCommand) doTemplate(t *template.Template, rl *ResourceList) error {
|
||||
// invoke the template
|
||||
var b bytes.Buffer
|
||||
@@ -372,12 +389,39 @@ func (tc TemplateCommand) GetCommand() *cobra.Command {
|
||||
}
|
||||
}
|
||||
|
||||
if tc.PatchTemplatesFn != nil {
|
||||
pt, err := tc.PatchTemplatesFn(&rl)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
tc.PatchTemplates = append(tc.PatchTemplates, pt...)
|
||||
}
|
||||
|
||||
for i := range tc.PatchTemplates {
|
||||
if err := tc.PatchTemplates[i].Apply(&rl); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if tc.PatchContainerTemplatesFn != nil {
|
||||
ct, err := tc.PatchContainerTemplatesFn(&rl)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
tc.PatchContainerTemplates = append(tc.PatchContainerTemplates, ct...)
|
||||
}
|
||||
for i := range tc.PatchContainerTemplates {
|
||||
ct := tc.PatchContainerTemplates[i]
|
||||
matches, err := ct.Selector.GetMatches(&rl)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = PatchContainersWithTemplate(matches, ct.Template, rl.FunctionConfig, ct.ContainerNames...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
var err error
|
||||
if tc.MergeResources {
|
||||
rl.Items, err = filters.MergeFilter{}.Filter(rl.Items)
|
||||
|
||||
Reference in New Issue
Block a user