mirror of https://github.com/helm/helm
Signed-off-by: Taylor Thomas <taylor.thomas@microsoft.com>pull/6550/head
parent
3799d0024c
commit
768d27b387
@ -1,108 +0,0 @@
|
||||
/*
|
||||
Copyright The Helm Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package action
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"helm.sh/helm/v3/pkg/chartutil"
|
||||
"helm.sh/helm/v3/pkg/release"
|
||||
)
|
||||
|
||||
// PrintRelease prints info about a release. If fullInfo is true, it will print
|
||||
// the user supplied values and the computed values used to render the chart
|
||||
func PrintRelease(out io.Writer, rel *release.Release, fullInfo bool) error {
|
||||
if rel == nil {
|
||||
return nil
|
||||
}
|
||||
fmt.Fprintf(out, "NAME: %s\n", rel.Name)
|
||||
if !rel.Info.LastDeployed.IsZero() {
|
||||
fmt.Fprintf(out, "LAST DEPLOYED: %s\n", rel.Info.LastDeployed.Format(time.ANSIC))
|
||||
}
|
||||
fmt.Fprintf(out, "NAMESPACE: %s\n", rel.Namespace)
|
||||
fmt.Fprintf(out, "STATUS: %s\n", rel.Info.Status.String())
|
||||
fmt.Fprintf(out, "REVISION: %d\n", rel.Version)
|
||||
|
||||
executions := executionsByHookEvent(rel)
|
||||
if tests, ok := executions[release.HookTest]; ok {
|
||||
for _, h := range tests {
|
||||
// Don't print anything if hook has not been initiated
|
||||
if h.LastRun.StartedAt.IsZero() {
|
||||
continue
|
||||
}
|
||||
fmt.Fprintf(out, "TEST SUITE: %s\n%s\n%s\n%s\n\n",
|
||||
h.Name,
|
||||
fmt.Sprintf("Last Started: %s", h.LastRun.StartedAt.Format(time.ANSIC)),
|
||||
fmt.Sprintf("Last Completed: %s", h.LastRun.CompletedAt.Format(time.ANSIC)),
|
||||
fmt.Sprintf("Phase: %s", h.LastRun.Phase),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
if fullInfo {
|
||||
fmt.Fprintln(out, "USER-SUPPLIED VALUES:")
|
||||
err := EncodeYAML(out, rel.Config)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// Print an extra newline
|
||||
fmt.Fprintln(out)
|
||||
|
||||
cfg, err := chartutil.CoalesceValues(rel.Chart, rel.Config)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Fprintln(out, "COMPUTED VALUES:")
|
||||
err = EncodeYAML(out, cfg.AsMap())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// Print an extra newline
|
||||
fmt.Fprintln(out)
|
||||
}
|
||||
|
||||
if strings.EqualFold(rel.Info.Description, "Dry run complete") || fullInfo {
|
||||
fmt.Fprintln(out, "HOOKS:")
|
||||
for _, h := range rel.Hooks {
|
||||
fmt.Fprintf(out, "---\n# Source: %s\n%s\n", h.Path, h.Manifest)
|
||||
}
|
||||
fmt.Fprintf(out, "MANIFEST:\n%s\n", rel.Manifest)
|
||||
}
|
||||
|
||||
if len(rel.Info.Notes) > 0 {
|
||||
fmt.Fprintf(out, "NOTES:\n%s\n", strings.TrimSpace(rel.Info.Notes))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func executionsByHookEvent(rel *release.Release) map[release.HookEvent][]*release.Hook {
|
||||
result := make(map[release.HookEvent][]*release.Hook)
|
||||
for _, h := range rel.Hooks {
|
||||
for _, e := range h.Events {
|
||||
executions, ok := result[e]
|
||||
if !ok {
|
||||
executions = []*release.Hook{}
|
||||
}
|
||||
result[e] = append(executions, h)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
Loading…
Reference in new issue