Allow to render manifest for custom resources in client only mode

Signed-off-by: Loïc Minaudier <loic.minaudier@datadoghq.com>
pull/6701/head
Loïc Minaudier 6 years ago
parent 387be04071
commit b57c8967f3

@ -211,7 +211,7 @@ func (i *Install) Run(chrt *chart.Chart, vals map[string]interface{}) (*release.
rel := i.createRelease(chrt, vals)
var manifestDoc *bytes.Buffer
rel.Hooks, manifestDoc, rel.Info.Notes, err = i.cfg.renderResources(chrt, valuesToRender, i.OutputDir, i.SubNotes)
rel.Hooks, manifestDoc, rel.Info.Notes, err = i.cfg.renderResources(chrt, valuesToRender, i.OutputDir, i.SubNotes, i.ClientOnly)
// Even for errors, attach this if available
if manifestDoc != nil {
rel.Manifest = manifestDoc.String()
@ -409,7 +409,7 @@ func (i *Install) replaceRelease(rel *release.Release) error {
}
// renderResources renders the templates in a chart
func (c *Configuration) renderResources(ch *chart.Chart, values chartutil.Values, outputDir string, subNotes bool) ([]*release.Hook, *bytes.Buffer, string, error) {
func (c *Configuration) renderResources(ch *chart.Chart, values chartutil.Values, outputDir string, subNotes bool, clientOnly bool) ([]*release.Hook, *bytes.Buffer, string, error) {
hs := []*release.Hook{}
b := bytes.NewBuffer(nil)
@ -452,7 +452,7 @@ func (c *Configuration) renderResources(ch *chart.Chart, values chartutil.Values
// Sort hooks, manifests, and partials. Only hooks and manifests are returned,
// as partials are not used after renderer.Render. Empty manifests are also
// removed here.
hs, manifests, err := releaseutil.SortManifests(files, caps.APIVersions, releaseutil.InstallOrder)
hs, manifests, err := releaseutil.SortManifests(files, caps.APIVersions, releaseutil.InstallOrder, clientOnly)
if err != nil {
// By catching parse errors here, we can prevent bogus releases from going
// to Kubernetes.

@ -170,7 +170,8 @@ func (u *Uninstall) deleteRelease(rel *release.Release) (string, []error) {
}
manifests := releaseutil.SplitManifests(rel.Manifest)
_, files, err := releaseutil.SortManifests(manifests, caps.APIVersions, releaseutil.UninstallOrder)
_, files, err := releaseutil.SortManifests(manifests, caps.APIVersions, releaseutil.UninstallOrder, false)
if err != nil {
// We could instead just delete everything in no particular order.
// FIXME: One way to delete at this point would be to try a label-based

@ -160,7 +160,7 @@ func (u *Upgrade) prepareUpgrade(name string, chart *chart.Chart, vals map[strin
return nil, nil, err
}
hooks, manifestDoc, notesTxt, err := u.cfg.renderResources(chart, valuesToRender, "", u.SubNotes)
hooks, manifestDoc, notesTxt, err := u.cfg.renderResources(chart, valuesToRender, "", u.SubNotes, false)
if err != nil {
return nil, nil, err
}

@ -74,7 +74,7 @@ var events = map[string]release.HookEvent{
//
// Files that do not parse into the expected format are simply placed into a map and
// returned.
func SortManifests(files map[string]string, apis chartutil.VersionSet, sort KindSortOrder) ([]*release.Hook, []Manifest, error) {
func SortManifests(files map[string]string, apis chartutil.VersionSet, sort KindSortOrder, clientOnly bool) ([]*release.Hook, []Manifest, error) {
result := &result{}
for filePath, c := range files {
@ -95,7 +95,7 @@ func SortManifests(files map[string]string, apis chartutil.VersionSet, sort Kind
apis: apis,
}
if err := manifestFile.sort(result); err != nil {
if err := manifestFile.sort(result, clientOnly); err != nil {
return result.hooks, result.generic, err
}
}
@ -122,14 +122,14 @@ func SortManifests(files map[string]string, apis chartutil.VersionSet, sort Kind
// metadata:
// annotations:
// helm.sh/hook-delete-policy: hook-succeeded
func (file *manifestFile) sort(result *result) error {
func (file *manifestFile) sort(result *result, clientOnly bool) error {
for _, m := range file.entries {
var entry SimpleHead
if err := yaml.Unmarshal([]byte(m), &entry); err != nil {
return errors.Wrapf(err, "YAML parse error on %s", file.path)
}
if entry.Version != "" && !file.apis.Has(entry.Version) {
if !clientOnly && (entry.Version != "" && !file.apis.Has(entry.Version)) {
return errors.Errorf("apiVersion %q in %s is not available", entry.Version, file.path)
}

@ -257,7 +257,7 @@ metadata:
manifests[o.path] = o.manifest
}
_, _, err := SortManifests(manifests, chartutil.VersionSet{"v1", "v1beta1"}, InstallOrder)
_, _, err := SortManifests(manifests, chartutil.VersionSet{"v1", "v1beta1"}, InstallOrder, true)
if err != nil {
t.Fatalf("Unexpected error: %s", err)
}

Loading…
Cancel
Save