Allow configuring custom ResourceVisitor in Install and Upgrade

Signed-off-by: Marko Lukša <marko.luksa@gmail.com>
pull/12129/head
Marko Lukša 2 years ago
parent 1c4885fce7
commit e5aebf3bb2
No known key found for this signature in database
GPG Key ID: 3F1D2ADE3A8AC5BC

@ -104,6 +104,12 @@ type Install struct {
// OutputDir/<ReleaseName>
UseReleaseName bool
PostRenderer postrender.PostRenderer
// ResourceVisitor is an optional VisitorFunc applied to each rendered resource
//
// This is an alternative to PostRenderer. Unike PostRenderer, it allows each
// individual resource to be modified without having to parse and re-serialize the
// manifests.
ResourceVisitor resource.VisitorFunc
// Lock to control raceconditions when the process receives a SIGTERM
Lock sync.Mutex
}
@ -302,6 +308,13 @@ func (i *Install) RunWithContext(ctx context.Context, chrt *chart.Chart, vals ma
return nil, errors.Wrap(err, "unable to build kubernetes objects from release manifest")
}
if i.ResourceVisitor != nil {
err = resources.Visit(i.ResourceVisitor)
if err != nil {
return nil, err
}
}
// It is safe to use "force" here because these are resources currently rendered by the chart.
err = resources.Visit(setMetadataVisitor(rel.Name, rel.Namespace, true))
if err != nil {

@ -98,6 +98,12 @@ type Upgrade struct {
// If this is non-nil, then after templates are rendered, they will be sent to the
// post renderer before sending to the Kubernetes API server.
PostRenderer postrender.PostRenderer
// ResourceVisitor is an optional VisitorFunc applied to each rendered resource
//
// This is an alternative to PostRenderer. Unike PostRenderer, it allows each
// individual resource to be modified without having to parse and re-serialize the
// manifests.
ResourceVisitor resource.VisitorFunc
// DisableOpenAPIValidation controls whether OpenAPI validation is enforced.
DisableOpenAPIValidation bool
// Get missing dependencies
@ -285,6 +291,13 @@ func (u *Upgrade) performUpgrade(ctx context.Context, originalRelease, upgradedR
return upgradedRelease, errors.Wrap(err, "unable to build kubernetes objects from new release manifest")
}
if u.ResourceVisitor != nil {
err = target.Visit(u.ResourceVisitor)
if err != nil {
return upgradedRelease, err
}
}
// It is safe to use force only on target because these are resources currently rendered by the chart.
err = target.Visit(setMetadataVisitor(upgradedRelease.Name, upgradedRelease.Namespace, true))
if err != nil {

Loading…
Cancel
Save