github.com/sri09kanth/helm@v3.0.0-beta.3+incompatible/pkg/action/get_values.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  package action
    18  
    19  import (
    20  	"sigs.k8s.io/yaml"
    21  
    22  	"helm.sh/helm/pkg/chartutil"
    23  )
    24  
    25  // GetValues is the action for checking a given release's values.
    26  //
    27  // It provides the implementation of 'helm get values'.
    28  type GetValues struct {
    29  	cfg *Configuration
    30  
    31  	Version   int
    32  	AllValues bool
    33  }
    34  
    35  // NewGetValues creates a new GetValues object with the given configuration.
    36  func NewGetValues(cfg *Configuration) *GetValues {
    37  	return &GetValues{
    38  		cfg: cfg,
    39  	}
    40  }
    41  
    42  // Run executes 'helm get values' against the given release.
    43  func (g *GetValues) Run(name string) (string, error) {
    44  	res, err := g.cfg.releaseContent(name, g.Version)
    45  	if err != nil {
    46  		return "", err
    47  	}
    48  
    49  	// If the user wants all values, compute the values and return.
    50  	if g.AllValues {
    51  		cfg, err := chartutil.CoalesceValues(res.Chart, res.Config)
    52  		if err != nil {
    53  			return "", err
    54  		}
    55  		cfgStr, err := cfg.YAML()
    56  		if err != nil {
    57  			return "", err
    58  		}
    59  		return cfgStr, nil
    60  	}
    61  
    62  	resConfig, err := yaml.Marshal(res.Config)
    63  	if err != nil {
    64  		return "", err
    65  	}
    66  
    67  	return string(resConfig), nil
    68  }