github.com/rakanixu/helm@v2.8.2+incompatible/cmd/helm/printer.go (about) 1 /* 2 Copyright 2016 The Kubernetes Authors All rights reserved. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package main 18 19 import ( 20 "fmt" 21 "io" 22 "text/template" 23 "time" 24 25 "k8s.io/helm/pkg/chartutil" 26 "k8s.io/helm/pkg/proto/hapi/release" 27 "k8s.io/helm/pkg/timeconv" 28 ) 29 30 var printReleaseTemplate = `REVISION: {{.Release.Version}} 31 RELEASED: {{.ReleaseDate}} 32 CHART: {{.Release.Chart.Metadata.Name}}-{{.Release.Chart.Metadata.Version}} 33 USER-SUPPLIED VALUES: 34 {{.Release.Config.Raw}} 35 COMPUTED VALUES: 36 {{.ComputedValues}} 37 HOOKS: 38 {{- range .Release.Hooks }} 39 --- 40 # {{.Name}} 41 {{.Manifest}} 42 {{- end }} 43 MANIFEST: 44 {{.Release.Manifest}} 45 ` 46 47 func printRelease(out io.Writer, rel *release.Release) error { 48 if rel == nil { 49 return nil 50 } 51 52 cfg, err := chartutil.CoalesceValues(rel.Chart, rel.Config) 53 if err != nil { 54 return err 55 } 56 cfgStr, err := cfg.YAML() 57 if err != nil { 58 return err 59 } 60 61 data := map[string]interface{}{ 62 "Release": rel, 63 "ComputedValues": cfgStr, 64 "ReleaseDate": timeconv.Format(rel.Info.LastDeployed, time.ANSIC), 65 } 66 return tpl(printReleaseTemplate, data, out) 67 } 68 69 func tpl(t string, vals map[string]interface{}, out io.Writer) error { 70 tt, err := template.New("_").Parse(t) 71 if err != nil { 72 return err 73 } 74 return tt.Execute(out, vals) 75 } 76 77 func debug(format string, args ...interface{}) { 78 if settings.Debug { 79 format = fmt.Sprintf("[debug] %s\n", format) 80 fmt.Printf(format, args...) 81 } 82 }