github.com/azure-devops-engineer/helm@v3.0.0-alpha.2+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  	// Values are default config for this template.
    31  	Values map[string]interface{}
    32  	// Schema is an optional JSON schema for imposing structure on Values
    33  	Schema []byte
    34  	// Files are miscellaneous files in a chart archive,
    35  	// e.g. README, LICENSE, etc.
    36  	Files []*File
    37  
    38  	parent       *Chart
    39  	dependencies []*Chart
    40  }
    41  
    42  // SetDependencies replaces the chart dependencies.
    43  func (ch *Chart) SetDependencies(charts ...*Chart) {
    44  	ch.dependencies = nil
    45  	ch.AddDependency(charts...)
    46  }
    47  
    48  // Name returns the name of the chart.
    49  func (ch *Chart) Name() string {
    50  	if ch.Metadata == nil {
    51  		return ""
    52  	}
    53  	return ch.Metadata.Name
    54  }
    55  
    56  // AddDependency determines if the chart is a subchart.
    57  func (ch *Chart) AddDependency(charts ...*Chart) {
    58  	for i, x := range charts {
    59  		charts[i].parent = ch
    60  		ch.dependencies = append(ch.dependencies, x)
    61  	}
    62  }
    63  
    64  // Root finds the root chart.
    65  func (ch *Chart) Root() *Chart {
    66  	if ch.IsRoot() {
    67  		return ch
    68  	}
    69  	return ch.Parent().Root()
    70  }
    71  
    72  // Dependencies are the charts that this chart depends on.
    73  func (ch *Chart) Dependencies() []*Chart { return ch.dependencies }
    74  
    75  // IsRoot determines if the chart is the root chart.
    76  func (ch *Chart) IsRoot() bool { return ch.parent == nil }
    77  
    78  // Parent returns a subchart's parent chart.
    79  func (ch *Chart) Parent() *Chart { return ch.parent }
    80  
    81  // SetParent sets a subchart's parent chart.
    82  func (ch *Chart) SetParent(chart *Chart) { ch.parent = chart }
    83  
    84  // ChartPath returns the full path to this chart in dot notation.
    85  func (ch *Chart) ChartPath() string {
    86  	if !ch.IsRoot() {
    87  		return ch.Parent().ChartPath() + "." + ch.Name()
    88  	}
    89  	return ch.Name()
    90  }
    91  
    92  // ChartFullPath returns the full path to this chart.
    93  func (ch *Chart) ChartFullPath() string {
    94  	if !ch.IsRoot() {
    95  		return ch.Parent().ChartFullPath() + "/charts/" + ch.Name()
    96  	}
    97  	return ch.Name()
    98  }
    99  
   100  func (ch *Chart) Validate() error {
   101  	return ch.Metadata.Validate()
   102  }
   103  
   104  // AppVersion returns the appversion of the chart.
   105  func (ch *Chart) AppVersion() string {
   106  	if ch.Metadata == nil {
   107  		return ""
   108  	}
   109  	return ch.Metadata.AppVersion
   110  }