github.com/replicatedhq/ship@v0.55.0/pkg/helm/printer.go (about)

     1  /*
     2  Copyright The Helm Authors.
     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  /*This file was edited by Replicated in 2018 to expose printers to our helm package.*/
    18  
    19  package helm
    20  
    21  import (
    22  	"io"
    23  	"text/template"
    24  	"time"
    25  
    26  	"k8s.io/helm/pkg/chartutil"
    27  	"k8s.io/helm/pkg/proto/hapi/release"
    28  	"k8s.io/helm/pkg/timeconv"
    29  )
    30  
    31  var printReleaseTemplate = `REVISION: {{.Release.Version}}
    32  RELEASED: {{.ReleaseDate}}
    33  CHART: {{.Release.Chart.Metadata.Name}}-{{.Release.Chart.Metadata.Version}}
    34  USER-SUPPLIED VALUES:
    35  {{.Release.Config.Raw}}
    36  COMPUTED VALUES:
    37  {{.ComputedValues}}
    38  HOOKS:
    39  {{- range .Release.Hooks }}
    40  ---
    41  # {{.Name}}
    42  {{.Manifest}}
    43  {{- end }}
    44  MANIFEST:
    45  {{.Release.Manifest}}
    46  `
    47  
    48  func printRelease(out io.Writer, rel *release.Release) error {
    49  	if rel == nil {
    50  		return nil
    51  	}
    52  
    53  	cfg, err := chartutil.CoalesceValues(rel.Chart, rel.Config)
    54  	if err != nil {
    55  		return err
    56  	}
    57  	cfgStr, err := cfg.YAML()
    58  	if err != nil {
    59  		return err
    60  	}
    61  
    62  	data := map[string]interface{}{
    63  		"Release":        rel,
    64  		"ComputedValues": cfgStr,
    65  		"ReleaseDate":    timeconv.Format(rel.Info.LastDeployed, time.ANSIC),
    66  	}
    67  	return tpl(printReleaseTemplate, data, out)
    68  }
    69  
    70  func tpl(t string, vals map[string]interface{}, out io.Writer) error {
    71  	tt, err := template.New("_").Parse(t)
    72  	if err != nil {
    73  		return err
    74  	}
    75  	return tt.Execute(out, vals)
    76  }