github.com/umeshredd/helm@v3.0.0-alpha.1+incompatible/pkg/chart/chart.go (about)

     1  /*
     2  Copyright The Helm Authors.
     3  Licensed under the Apache License, Version 2.0 (the "License");
     4  you may not use this file except in compliance with the License.
     5  You may obtain a copy of the License at
     6  
     7  http://www.apache.org/licenses/LICENSE-2.0
     8  
     9  Unless required by applicable law or agreed to in writing, software
    10  distributed under the License is distributed on an "AS IS" BASIS,
    11  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  See the License for the specific language governing permissions and
    13  limitations under the License.
    14  */
    15  
    16  package chart
    17  
    18  // APIVersionV1 is the API version number for version 1.
    19  const APIVersionV1 = "v1"
    20  
    21  // Chart is a helm package that contains metadata, a default config, zero or more
    22  // optionally parameterizable templates, and zero or more charts (dependencies).
    23  type Chart struct {
    24  	// Metadata is the contents of the Chartfile.
    25  	Metadata *Metadata
    26  	// LocK is the contents of Chart.lock.
    27  	Lock *Lock
    28  	// Templates for this chart.
    29  	Templates []*File
    30  	// TODO Delete RawValues after unit tests for `create` are refactored.
    31  	RawValues []byte
    32  	// Values are default config for this template.
    33  	Values map[string]interface{}
    34  	// Schema is an optional JSON schema for imposing structure on Values
    35  	Schema []byte
    36  	// Files are miscellaneous files in a chart archive,
    37  	// e.g. README, LICENSE, etc.
    38  	Files []*File
    39  
    40  	parent       *Chart
    41  	dependencies []*Chart
    42  }
    43  
    44  // SetDependencies replaces the chart dependencies.
    45  func (ch *Chart) SetDependencies(charts ...*Chart) {
    46  	ch.dependencies = nil
    47  	ch.AddDependency(charts...)
    48  }
    49  
    50  // Name returns the name of the chart.
    51  func (ch *Chart) Name() string {
    52  	if ch.Metadata == nil {
    53  		return ""
    54  	}
    55  	return ch.Metadata.Name
    56  }
    57  
    58  // AddDependency determines if the chart is a subchart.
    59  func (ch *Chart) AddDependency(charts ...*Chart) {
    60  	for i, x := range charts {
    61  		charts[i].parent = ch
    62  		ch.dependencies = append(ch.dependencies, x)
    63  	}
    64  }
    65  
    66  // Root finds the root chart.
    67  func (ch *Chart) Root() *Chart {
    68  	if ch.IsRoot() {
    69  		return ch
    70  	}
    71  	return ch.Parent().Root()
    72  }
    73  
    74  // Dependencies are the charts that this chart depends on.
    75  func (ch *Chart) Dependencies() []*Chart { return ch.dependencies }
    76  
    77  // IsRoot determines if the chart is the root chart.
    78  func (ch *Chart) IsRoot() bool { return ch.parent == nil }
    79  
    80  // Parent returns a subchart's parent chart.
    81  func (ch *Chart) Parent() *Chart { return ch.parent }
    82  
    83  // SetParent sets a subchart's parent chart.
    84  func (ch *Chart) SetParent(chart *Chart) { ch.parent = chart }
    85  
    86  // ChartPath returns the full path to this chart in dot notation.
    87  func (ch *Chart) ChartPath() string {
    88  	if !ch.IsRoot() {
    89  		return ch.Parent().ChartPath() + "." + ch.Name()
    90  	}
    91  	return ch.Name()
    92  }
    93  
    94  // ChartFullPath returns the full path to this chart.
    95  func (ch *Chart) ChartFullPath() string {
    96  	if !ch.IsRoot() {
    97  		return ch.Parent().ChartFullPath() + "/charts/" + ch.Name()
    98  	}
    99  	return ch.Name()
   100  }
   101  
   102  func (ch *Chart) Validate() error {
   103  	return ch.Metadata.Validate()
   104  }
   105  
   106  // AppVersion returns the appversion of the chart.
   107  func (ch *Chart) AppVersion() string {
   108  	if ch.Metadata == nil {
   109  		return ""
   110  	}
   111  	return ch.Metadata.AppVersion
   112  }