ref(pkg/chart): rename Requirements to Dependencies

Signed-off-by: Adam Reese <adam@reese.io>
pull/4972/head
Adam Reese 6 years ago
parent a6b8593152
commit 85aef0d3d7
No known key found for this signature in database
GPG Key ID: 06F35E60A7A18DD6

@ -34,18 +34,16 @@ const dependencyDesc = `
Manage the dependencies of a chart. Manage the dependencies of a chart.
Helm charts store their dependencies in 'charts/'. For chart developers, it is Helm charts store their dependencies in 'charts/'. For chart developers, it is
often easier to manage a single dependency file ('requirements.yaml') often easier to manage dependencies in 'Chart.yaml' which declares all
which declares all dependencies. dependencies.
The dependency commands operate on that file, making it easy to synchronize The dependency commands operate on that file, making it easy to synchronize
between the desired dependencies and the actual dependencies stored in the between the desired dependencies and the actual dependencies stored in the
'charts/' directory. 'charts/' directory.
A 'requirements.yaml' file is a YAML file in which developers can declare chart For example, this Chart.yaml declares two dependencies:
dependencies, along with the location of the chart and the desired version.
For example, this requirements file declares two dependencies:
# requirements.yaml # Chart.yaml
dependencies: dependencies:
- name: nginx - name: nginx
version: "1.2.3" version: "1.2.3"
@ -54,6 +52,7 @@ For example, this requirements file declares two dependencies:
version: "3.2.1" version: "3.2.1"
repository: "https://another.example.com/charts" repository: "https://another.example.com/charts"
The 'name' should be the name of a chart, where that name must match the name The 'name' should be the name of a chart, where that name must match the name
in that chart's 'Chart.yaml' file. in that chart's 'Chart.yaml' file.
@ -68,7 +67,7 @@ Starting from 2.2.0, repository can be defined as the path to the directory of
the dependency charts stored locally. The path should start with a prefix of the dependency charts stored locally. The path should start with a prefix of
"file://". For example, "file://". For example,
# requirements.yaml # Chart.yaml
dependencies: dependencies:
- name: nginx - name: nginx
version: "1.2.3" version: "1.2.3"
@ -85,8 +84,7 @@ List all of the dependencies declared in a chart.
This can take chart archives and chart directories as input. It will not alter This can take chart archives and chart directories as input. It will not alter
the contents of a chart. the contents of a chart.
This will produce an error if the chart cannot be loaded. It will emit a warning This will produce an error if the chart cannot be loaded.
if it cannot find a requirements.yaml.
` `
func newDependencyCmd(out io.Writer) *cobra.Command { func newDependencyCmd(out io.Writer) *cobra.Command {
@ -136,14 +134,14 @@ func (o *dependencyLisOptions) run(out io.Writer) error {
return err return err
} }
if c.Metadata.Requirements == nil { if c.Metadata.Dependencies == nil {
fmt.Fprintf(out, "WARNING: no requirements at %s/charts\n", o.chartpath) fmt.Fprintf(out, "WARNING: no dependencies at %s/charts\n", o.chartpath)
return nil return nil
} }
o.printRequirements(out, c.Metadata.Requirements) o.printDependencies(out, c.Metadata.Dependencies)
fmt.Fprintln(out) fmt.Fprintln(out)
o.printMissing(out, c.Metadata.Requirements) o.printMissing(out, c.Metadata.Dependencies)
return nil return nil
} }
@ -221,8 +219,8 @@ func (o *dependencyLisOptions) dependencyStatus(dep *chart.Dependency) string {
return "unpacked" return "unpacked"
} }
// printRequirements prints all of the requirements in the yaml file. // printDependencies prints all of the dependencies in the yaml file.
func (o *dependencyLisOptions) printRequirements(out io.Writer, reqs []*chart.Dependency) { func (o *dependencyLisOptions) printDependencies(out io.Writer, reqs []*chart.Dependency) {
table := uitable.New() table := uitable.New()
table.MaxColWidth = 80 table.MaxColWidth = 80
table.AddRow("NAME", "VERSION", "REPOSITORY", "STATUS") table.AddRow("NAME", "VERSION", "REPOSITORY", "STATUS")
@ -232,7 +230,8 @@ func (o *dependencyLisOptions) printRequirements(out io.Writer, reqs []*chart.De
fmt.Fprintln(out, table) fmt.Fprintln(out, table)
} }
// printMissing prints warnings about charts that are present on disk, but are not in the requirements. // printMissing prints warnings about charts that are present on disk, but are
// not in Charts.yaml.
func (o *dependencyLisOptions) printMissing(out io.Writer, reqs []*chart.Dependency) { func (o *dependencyLisOptions) printMissing(out io.Writer, reqs []*chart.Dependency) {
folder := filepath.Join(o.chartpath, "charts/*") folder := filepath.Join(o.chartpath, "charts/*")
files, err := filepath.Glob(folder) files, err := filepath.Glob(folder)

@ -26,15 +26,15 @@ func TestDependencyListCmd(t *testing.T) {
golden: "output/dependency-list-no-chart.txt", golden: "output/dependency-list-no-chart.txt",
wantError: true, wantError: true,
}, { }, {
name: "No requirements.yaml", name: "No dependencies",
cmd: "dependency list testdata/testcharts/alpine", cmd: "dependency list testdata/testcharts/alpine",
golden: "output/dependency-list-no-requirements.txt", golden: "output/dependency-list-no-requirements.txt",
}, { }, {
name: "Requirements in chart dir", name: "Dependencies in chart dir",
cmd: "dependency list testdata/testcharts/reqtest", cmd: "dependency list testdata/testcharts/reqtest",
golden: "output/dependency-list.txt", golden: "output/dependency-list.txt",
}, { }, {
name: "Requirements in chart archive", name: "Dependencies in chart archive",
cmd: "dependency list testdata/testcharts/reqtest-0.1.0.tgz", cmd: "dependency list testdata/testcharts/reqtest-0.1.0.tgz",
golden: "output/dependency-list-archive.txt", golden: "output/dependency-list-archive.txt",
}} }}

@ -35,7 +35,7 @@ are present in 'charts/' and are at an acceptable version. It will pull down
the latest charts that satisfy the dependencies, and clean up old dependencies. the latest charts that satisfy the dependencies, and clean up old dependencies.
On successful update, this will generate a lock file that can be used to On successful update, this will generate a lock file that can be used to
rebuild the requirements to an exact version. rebuild the dependencies to an exact version.
Dependencies are not required to be represented in 'Chart.yaml'. For that Dependencies are not required to be represented in 'Chart.yaml'. For that
reason, an update command will not remove charts unless they are (a) present reason, an update command will not remove charts unless they are (a) present

@ -86,7 +86,7 @@ func TestDependencyUpdateCmd(t *testing.T) {
// Now change the dependencies and update. This verifies that on update, // Now change the dependencies and update. This verifies that on update,
// old dependencies are cleansed and new dependencies are added. // old dependencies are cleansed and new dependencies are added.
md.Requirements = []*chart.Dependency{ md.Dependencies = []*chart.Dependency{
{Name: "reqtest", Version: "0.1.0", Repository: srv.URL()}, {Name: "reqtest", Version: "0.1.0", Repository: srv.URL()},
{Name: "compressedchart", Version: "0.3.0", Repository: srv.URL()}, {Name: "compressedchart", Version: "0.3.0", Repository: srv.URL()},
} }
@ -213,7 +213,7 @@ func createTestingMetadata(name, baseURL string) *chart.Metadata {
return &chart.Metadata{ return &chart.Metadata{
Name: name, Name: name,
Version: "1.2.3", Version: "1.2.3",
Requirements: []*chart.Dependency{ Dependencies: []*chart.Dependency{
{Name: "reqtest", Version: "0.1.0", Repository: baseURL}, {Name: "reqtest", Version: "0.1.0", Repository: baseURL},
{Name: "compressedchart", Version: "0.1.0", Repository: baseURL}, {Name: "compressedchart", Version: "0.1.0", Repository: baseURL},
}, },

@ -219,13 +219,13 @@ func (o *installOptions) run(out io.Writer) error {
fmt.Printf("FINAL NAME: %s\n", o.name) fmt.Printf("FINAL NAME: %s\n", o.name)
} }
// Check chart requirements to make sure all dependencies are present in /charts // Check chart dependencies to make sure all are present in /charts
chartRequested, err := loader.Load(o.chartPath) chartRequested, err := loader.Load(o.chartPath)
if err != nil { if err != nil {
return err return err
} }
if req := chartRequested.Metadata.Requirements; req != nil { if req := chartRequested.Metadata.Dependencies; req != nil {
// If checkDependencies returns an error, we have unfulfilled dependencies. // If checkDependencies returns an error, we have unfulfilled dependencies.
// As of Helm 2.4.0, this is treated as a stopping condition: // As of Helm 2.4.0, this is treated as a stopping condition:
// https://github.com/kubernetes/helm/issues/2209 // https://github.com/kubernetes/helm/issues/2209
@ -344,7 +344,7 @@ OUTER:
} }
if len(missing) > 0 { if len(missing) > 0 {
return errors.Errorf("found in requirements.yaml, but missing in charts/ directory: %s", strings.Join(missing, ", ")) return errors.Errorf("found in Chart.yaml, but missing in charts/ directory: %s", strings.Join(missing, ", "))
} }
return nil return nil
} }

@ -157,7 +157,7 @@ func (o *packageOptions) run(out io.Writer) error {
debug("Setting appVersion to %s", o.appVersion) debug("Setting appVersion to %s", o.appVersion)
} }
if reqs := ch.Metadata.Requirements; reqs != nil { if reqs := ch.Metadata.Dependencies; reqs != nil {
if err := checkDependencies(ch, reqs); err != nil { if err := checkDependencies(ch, reqs); err != nil {
return err return err
} }

@ -152,13 +152,13 @@ func (o *templateOptions) run(out io.Writer) error {
} }
} }
// Check chart requirements to make sure all dependencies are present in /charts // Check chart dependencies to make sure all are present in /charts
c, err := loader.Load(o.chartPath) c, err := loader.Load(o.chartPath)
if err != nil { if err != nil {
return err return err
} }
if req := c.Metadata.Requirements; req != nil { if req := c.Metadata.Dependencies; req != nil {
if err := checkDependencies(c, req); err != nil { if err := checkDependencies(c, req); err != nil {
return err return err
} }
@ -171,10 +171,10 @@ func (o *templateOptions) run(out io.Writer) error {
if err := yaml.Unmarshal(config, &m); err != nil { if err := yaml.Unmarshal(config, &m); err != nil {
return err return err
} }
if err := chartutil.ProcessRequirementsEnabled(c, m); err != nil { if err := chartutil.ProcessDependencyEnabled(c, m); err != nil {
return err return err
} }
if err := chartutil.ProcessRequirementsImportValues(c); err != nil { if err := chartutil.ProcessDependencyImportValues(c); err != nil {
return err return err
} }

@ -1 +1 @@
WARNING: no requirements at testdata/testcharts/alpine/charts WARNING: no dependencies at testdata/testcharts/alpine/charts

@ -1,2 +0,0 @@
thomas-guide
atlas-guide

@ -1,4 +0,0 @@
dependencies:
- name: reqsubchart
version: 0.1.0
repository: "https://example.com/charts"

@ -1,7 +0,0 @@
dependencies:
- name: reqsubchart
version: 0.1.0
repository: "https://example.com/charts"
- name: reqsubchart2
version: 0.2.0
repository: "https://example.com/charts"

@ -1,10 +0,0 @@
dependencies:
- name: reqsubchart
version: 0.1.0
repository: "https://example.com/charts"
- name: reqsubchart2
version: 0.2.0
repository: "https://example.com/charts"
- name: reqsubchart3
version: ">=0.1.0"
repository: "https://example.com/charts"

@ -146,12 +146,12 @@ func (o *upgradeOptions) run(out io.Writer) error {
return err return err
} }
// Check chart requirements to make sure all dependencies are present in /charts // Check chart dependencies to make sure all are present in /charts
ch, err := loader.Load(chartPath) ch, err := loader.Load(chartPath)
if err != nil { if err != nil {
return err return err
} }
if req := ch.Metadata.Requirements; req != nil { if req := ch.Metadata.Dependencies; req != nil {
if err := checkDependencies(ch, req); err != nil { if err := checkDependencies(ch, req); err != nil {
return err return err
} }

@ -49,13 +49,13 @@ type Dependency struct {
Alias string `json:"alias,omitempty"` Alias string `json:"alias,omitempty"`
} }
// Lock is a lock file for requirements. // Lock is a lock file for dependencies.
// //
// It represents the state that the dependencies should be in. // It represents the state that the dependencies should be in.
type Lock struct { type Lock struct {
// Genderated is the date the lock file was last generated. // Genderated is the date the lock file was last generated.
Generated time.Time `json:"generated"` Generated time.Time `json:"generated"`
// Digest is a hash of the requirements file used to generate it. // Digest is a hash of the dependencies in Chart.yaml.
Digest string `json:"digest"` Digest string `json:"digest"`
// Dependencies is the list of dependencies that this lock file has locked. // Dependencies is the list of dependencies that this lock file has locked.
Dependencies []*Dependency `json:"dependencies"` Dependencies []*Dependency `json:"dependencies"`

@ -33,8 +33,8 @@ func TestLoadDir(t *testing.T) {
} }
verifyFrobnitz(t, c) verifyFrobnitz(t, c)
verifyChart(t, c) verifyChart(t, c)
verifyRequirements(t, c) verifyDependencies(t, c)
verifyRequirementsLock(t, c) verifyDependenciesLock(t, c)
} }
func TestLoadFile(t *testing.T) { func TestLoadFile(t *testing.T) {
@ -48,7 +48,7 @@ func TestLoadFile(t *testing.T) {
} }
verifyFrobnitz(t, c) verifyFrobnitz(t, c)
verifyChart(t, c) verifyChart(t, c)
verifyRequirements(t, c) verifyDependencies(t, c)
} }
func TestLoadFiles(t *testing.T) { func TestLoadFiles(t *testing.T) {
@ -123,7 +123,7 @@ func TestLoadFileBackslash(t *testing.T) {
} }
verifyChartFileAndTemplate(t, c, "frobnitz_backslash") verifyChartFileAndTemplate(t, c, "frobnitz_backslash")
verifyChart(t, c) verifyChart(t, c)
verifyRequirements(t, c) verifyDependencies(t, c)
} }
func verifyChart(t *testing.T, c *chart.Chart) { func verifyChart(t *testing.T, c *chart.Chart) {
@ -175,16 +175,16 @@ func verifyChart(t *testing.T, c *chart.Chart) {
} }
func verifyRequirements(t *testing.T, c *chart.Chart) { func verifyDependencies(t *testing.T, c *chart.Chart) {
if len(c.Metadata.Requirements) != 2 { if len(c.Metadata.Dependencies) != 2 {
t.Errorf("Expected 2 requirements, got %d", len(c.Metadata.Requirements)) t.Errorf("Expected 2 dependencies, got %d", len(c.Metadata.Dependencies))
} }
tests := []*chart.Dependency{ tests := []*chart.Dependency{
{Name: "alpine", Version: "0.1.0", Repository: "https://example.com/charts"}, {Name: "alpine", Version: "0.1.0", Repository: "https://example.com/charts"},
{Name: "mariner", Version: "4.3.2", Repository: "https://example.com/charts"}, {Name: "mariner", Version: "4.3.2", Repository: "https://example.com/charts"},
} }
for i, tt := range tests { for i, tt := range tests {
d := c.Metadata.Requirements[i] d := c.Metadata.Dependencies[i]
if d.Name != tt.Name { if d.Name != tt.Name {
t.Errorf("Expected dependency named %q, got %q", tt.Name, d.Name) t.Errorf("Expected dependency named %q, got %q", tt.Name, d.Name)
} }
@ -197,16 +197,16 @@ func verifyRequirements(t *testing.T, c *chart.Chart) {
} }
} }
func verifyRequirementsLock(t *testing.T, c *chart.Chart) { func verifyDependenciesLock(t *testing.T, c *chart.Chart) {
if len(c.Metadata.Requirements) != 2 { if len(c.Metadata.Dependencies) != 2 {
t.Errorf("Expected 2 requirements, got %d", len(c.Metadata.Requirements)) t.Errorf("Expected 2 dependencies, got %d", len(c.Metadata.Dependencies))
} }
tests := []*chart.Dependency{ tests := []*chart.Dependency{
{Name: "alpine", Version: "0.1.0", Repository: "https://example.com/charts"}, {Name: "alpine", Version: "0.1.0", Repository: "https://example.com/charts"},
{Name: "mariner", Version: "4.3.2", Repository: "https://example.com/charts"}, {Name: "mariner", Version: "4.3.2", Repository: "https://example.com/charts"},
} }
for i, tt := range tests { for i, tt := range tests {
d := c.Metadata.Requirements[i] d := c.Metadata.Dependencies[i]
if d.Name != tt.Name { if d.Name != tt.Name {
t.Errorf("Expected dependency named %q, got %q", tt.Name, d.Name) t.Errorf("Expected dependency named %q, got %q", tt.Name, d.Name)
} }
@ -245,8 +245,8 @@ func verifyChartFileAndTemplate(t *testing.T, c *chart.Chart, name string) {
if len(c.Dependencies()) != 2 { if len(c.Dependencies()) != 2 {
t.Fatalf("Expected 2 Dependency, got %d", len(c.Dependencies())) t.Fatalf("Expected 2 Dependency, got %d", len(c.Dependencies()))
} }
if len(c.Metadata.Requirements) != 2 { if len(c.Metadata.Dependencies) != 2 {
t.Fatalf("Expected 2 Requirements.Dependency, got %d", len(c.Metadata.Requirements)) t.Fatalf("Expected 2 Dependencies.Dependency, got %d", len(c.Metadata.Dependencies))
} }
if len(c.Lock.Dependencies) != 2 { if len(c.Lock.Dependencies) != 2 {
t.Fatalf("Expected 2 Lock.Dependency, got %d", len(c.Lock.Dependencies)) t.Fatalf("Expected 2 Lock.Dependency, got %d", len(c.Lock.Dependencies))

@ -65,6 +65,6 @@ type Metadata struct {
Annotations map[string]string `json:"annotations,omitempty"` Annotations map[string]string `json:"annotations,omitempty"`
// KubeVersion is a SemVer constraint specifying the version of Kubernetes required. // KubeVersion is a SemVer constraint specifying the version of Kubernetes required.
KubeVersion string `json:"kubeVersion,omitempty"` KubeVersion string `json:"kubeVersion,omitempty"`
// Requirements are a list of requirements for a chart. // Dependencies are a list of dependencies for a chart.
Requirements []*Dependency `json:"dependencies,omitempty"` Dependencies []*Dependency `json:"dependencies,omitempty"`
} }

@ -25,8 +25,8 @@ import (
"k8s.io/helm/pkg/version" "k8s.io/helm/pkg/version"
) )
// ProcessRequirementsConditions disables charts based on condition path value in values // ProcessDependencyConditions disables charts based on condition path value in values
func ProcessRequirementsConditions(reqs []*chart.Dependency, cvals Values) { func ProcessDependencyConditions(reqs []*chart.Dependency, cvals Values) {
if reqs == nil { if reqs == nil {
return return
} }
@ -66,8 +66,8 @@ func ProcessRequirementsConditions(reqs []*chart.Dependency, cvals Values) {
} }
} }
// ProcessRequirementsTags disables charts based on tags in values // ProcessDependencyTags disables charts based on tags in values
func ProcessRequirementsTags(reqs []*chart.Dependency, cvals Values) { func ProcessDependencyTags(reqs []*chart.Dependency, cvals Values) {
if reqs == nil { if reqs == nil {
return return
} }
@ -125,9 +125,9 @@ func getAliasDependency(charts []*chart.Chart, aliasChart *chart.Dependency) *ch
return nil return nil
} }
// ProcessRequirementsEnabled removes disabled charts from dependencies // ProcessDependencyEnabled removes disabled charts from dependencies
func ProcessRequirementsEnabled(c *chart.Chart, v map[string]interface{}) error { func ProcessDependencyEnabled(c *chart.Chart, v map[string]interface{}) error {
if c.Metadata.Requirements == nil { if c.Metadata.Dependencies == nil {
return nil return nil
} }
@ -139,7 +139,7 @@ func ProcessRequirementsEnabled(c *chart.Chart, v map[string]interface{}) error
for _, existingDependency := range c.Dependencies() { for _, existingDependency := range c.Dependencies() {
var dependencyFound bool var dependencyFound bool
for _, req := range c.Metadata.Requirements { for _, req := range c.Metadata.Dependencies {
if existingDependency.Metadata.Name == req.Name && version.IsCompatibleRange(req.Version, existingDependency.Metadata.Version) { if existingDependency.Metadata.Name == req.Name && version.IsCompatibleRange(req.Version, existingDependency.Metadata.Version) {
dependencyFound = true dependencyFound = true
break break
@ -150,7 +150,7 @@ func ProcessRequirementsEnabled(c *chart.Chart, v map[string]interface{}) error
} }
} }
for _, req := range c.Metadata.Requirements { for _, req := range c.Metadata.Dependencies {
if chartDependency := getAliasDependency(c.Dependencies(), req); chartDependency != nil { if chartDependency := getAliasDependency(c.Dependencies(), req); chartDependency != nil {
chartDependencies = append(chartDependencies, chartDependency) chartDependencies = append(chartDependencies, chartDependency)
} }
@ -161,7 +161,7 @@ func ProcessRequirementsEnabled(c *chart.Chart, v map[string]interface{}) error
c.SetDependencies(chartDependencies...) c.SetDependencies(chartDependencies...)
// set all to true // set all to true
for _, lr := range c.Metadata.Requirements { for _, lr := range c.Metadata.Dependencies {
lr.Enabled = true lr.Enabled = true
} }
b, _ := yaml.Marshal(v) b, _ := yaml.Marshal(v)
@ -170,11 +170,11 @@ func ProcessRequirementsEnabled(c *chart.Chart, v map[string]interface{}) error
return err return err
} }
// flag dependencies as enabled/disabled // flag dependencies as enabled/disabled
ProcessRequirementsTags(c.Metadata.Requirements, cvals) ProcessDependencyTags(c.Metadata.Dependencies, cvals)
ProcessRequirementsConditions(c.Metadata.Requirements, cvals) ProcessDependencyConditions(c.Metadata.Dependencies, cvals)
// make a map of charts to remove // make a map of charts to remove
rm := map[string]struct{}{} rm := map[string]struct{}{}
for _, r := range c.Metadata.Requirements { for _, r := range c.Metadata.Dependencies {
if !r.Enabled { if !r.Enabled {
// remove disabled chart // remove disabled chart
rm[r.Name] = struct{}{} rm[r.Name] = struct{}{}
@ -191,7 +191,7 @@ func ProcessRequirementsEnabled(c *chart.Chart, v map[string]interface{}) error
// recursively call self to process sub dependencies // recursively call self to process sub dependencies
for _, t := range cd { for _, t := range cd {
if err := ProcessRequirementsEnabled(t, cvals); err != nil { if err := ProcessDependencyEnabled(t, cvals); err != nil {
return err return err
} }
} }
@ -221,7 +221,7 @@ func set(path []string, data map[string]interface{}) map[string]interface{} {
// processImportValues merges values from child to parent based on the chart's dependencies' ImportValues field. // processImportValues merges values from child to parent based on the chart's dependencies' ImportValues field.
func processImportValues(c *chart.Chart) error { func processImportValues(c *chart.Chart) error {
if c.Metadata.Requirements == nil { if c.Metadata.Dependencies == nil {
return nil return nil
} }
// combine chart values and empty config to get Values // combine chart values and empty config to get Values
@ -231,7 +231,7 @@ func processImportValues(c *chart.Chart) error {
} }
b := make(map[string]interface{}) b := make(map[string]interface{})
// import values from each dependency if specified in import-values // import values from each dependency if specified in import-values
for _, r := range c.Metadata.Requirements { for _, r := range c.Metadata.Dependencies {
var outiv []interface{} var outiv []interface{}
for _, riv := range r.ImportValues { for _, riv := range r.ImportValues {
switch iv := riv.(type) { switch iv := riv.(type) {
@ -276,11 +276,11 @@ func processImportValues(c *chart.Chart) error {
return nil return nil
} }
// ProcessRequirementsImportValues imports specified chart values from child to parent. // ProcessDependencyImportValues imports specified chart values from child to parent.
func ProcessRequirementsImportValues(c *chart.Chart) error { func ProcessDependencyImportValues(c *chart.Chart) error {
for _, d := range c.Dependencies() { for _, d := range c.Dependencies() {
// recurse // recurse
if err := ProcessRequirementsImportValues(d); err != nil { if err := ProcessDependencyImportValues(d); err != nil {
return err return err
} }
} }

@ -27,12 +27,12 @@ import (
"k8s.io/helm/pkg/version" "k8s.io/helm/pkg/version"
) )
func TestLoadRequirements(t *testing.T) { func TestLoadDependency(t *testing.T) {
c, err := loader.Load("testdata/frobnitz") c, err := loader.Load("testdata/frobnitz")
if err != nil { if err != nil {
t.Fatalf("Failed to load testdata: %s", err) t.Fatalf("Failed to load testdata: %s", err)
} }
verifyRequirements(t, c) verifyDependency(t, c)
} }
func TestLoadChartLock(t *testing.T) { func TestLoadChartLock(t *testing.T) {
@ -43,7 +43,7 @@ func TestLoadChartLock(t *testing.T) {
verifyChartLock(t, c) verifyChartLock(t, c)
} }
func TestRequirementsEnabled(t *testing.T) { func TestDependencyEnabled(t *testing.T) {
tests := []struct { tests := []struct {
name string name string
v []byte v []byte
@ -104,16 +104,16 @@ func TestRequirementsEnabled(t *testing.T) {
t.Fatalf("Failed to load testdata: %s", err) t.Fatalf("Failed to load testdata: %s", err)
} }
t.Run(tc.name, func(t *testing.T) { t.Run(tc.name, func(t *testing.T) {
verifyRequirementsEnabled(t, c, tc.v, tc.e) verifyDependencyEnabled(t, c, tc.v, tc.e)
}) })
} }
} }
func verifyRequirementsEnabled(t *testing.T, c *chart.Chart, v []byte, e []string) { func verifyDependencyEnabled(t *testing.T, c *chart.Chart, v []byte, e []string) {
var m map[string]interface{} var m map[string]interface{}
yaml.Unmarshal(v, &m) yaml.Unmarshal(v, &m)
if err := ProcessRequirementsEnabled(c, m); err != nil { if err := ProcessDependencyEnabled(c, m); err != nil {
t.Errorf("Error processing enabled requirements %v", err) t.Errorf("Error processing enabled dependencies %v", err)
} }
out := extractCharts(c, nil) out := extractCharts(c, nil)
@ -146,7 +146,7 @@ func extractCharts(c *chart.Chart, out []*chart.Chart) []*chart.Chart {
return out return out
} }
func TestProcessRequirementsImportValues(t *testing.T) { func TestProcessDependencyImportValues(t *testing.T) {
c, err := loader.Load("testdata/subpop") c, err := loader.Load("testdata/subpop")
if err != nil { if err != nil {
t.Fatalf("Failed to load testdata: %s", err) t.Fatalf("Failed to load testdata: %s", err)
@ -213,12 +213,12 @@ func TestProcessRequirementsImportValues(t *testing.T) {
e["SCBexported2A"] = "blaster" e["SCBexported2A"] = "blaster"
e["global.SC1exported2.all.SC1exported3"] = "SC1expstr" e["global.SC1exported2.all.SC1exported3"] = "SC1expstr"
verifyRequirementsImportValues(t, c, e) verifyDependencyImportValues(t, c, e)
} }
func verifyRequirementsImportValues(t *testing.T, c *chart.Chart, e map[string]string) { func verifyDependencyImportValues(t *testing.T, c *chart.Chart, e map[string]string) {
if err := ProcessRequirementsImportValues(c); err != nil { if err := ProcessDependencyImportValues(c); err != nil {
t.Fatalf("Error processing import values requirements %v", err) t.Fatalf("Error processing import values dependencies %v", err)
} }
cc := Values(c.Values) cc := Values(c.Values)
for kk, vv := range e { for kk, vv := range e {
@ -256,10 +256,10 @@ func TestGetAliasDependency(t *testing.T) {
t.Fatalf("Failed to load testdata: %s", err) t.Fatalf("Failed to load testdata: %s", err)
} }
req := c.Metadata.Requirements req := c.Metadata.Dependencies
if len(req) == 0 { if len(req) == 0 {
t.Fatalf("There are no requirements to test") t.Fatalf("There are no dependencies to test")
} }
// Success case // Success case
@ -304,7 +304,7 @@ func TestDependentChartAliases(t *testing.T) {
} }
origLength := len(c.Dependencies()) origLength := len(c.Dependencies())
if err := ProcessRequirementsEnabled(c, c.Values); err != nil { if err := ProcessDependencyEnabled(c, c.Values); err != nil {
t.Fatalf("Expected no errors but got %q", err) t.Fatalf("Expected no errors but got %q", err)
} }
@ -312,12 +312,12 @@ func TestDependentChartAliases(t *testing.T) {
t.Fatal("Expected alias dependencies to be added, but did not got that") t.Fatal("Expected alias dependencies to be added, but did not got that")
} }
if len(c.Dependencies()) != len(c.Metadata.Requirements) { if len(c.Dependencies()) != len(c.Metadata.Dependencies) {
t.Fatalf("Expected number of chart dependencies %d, but got %d", len(c.Metadata.Requirements), len(c.Dependencies())) t.Fatalf("Expected number of chart dependencies %d, but got %d", len(c.Metadata.Dependencies), len(c.Dependencies()))
} }
} }
func TestDependentChartWithSubChartsAbsentInRequirements(t *testing.T) { func TestDependentChartWithSubChartsAbsentInDependency(t *testing.T) {
c, err := loader.Load("testdata/dependent-chart-no-requirements-yaml") c, err := loader.Load("testdata/dependent-chart-no-requirements-yaml")
if err != nil { if err != nil {
t.Fatalf("Failed to load testdata: %s", err) t.Fatalf("Failed to load testdata: %s", err)
@ -328,7 +328,7 @@ func TestDependentChartWithSubChartsAbsentInRequirements(t *testing.T) {
} }
origLength := len(c.Dependencies()) origLength := len(c.Dependencies())
if err := ProcessRequirementsEnabled(c, c.Values); err != nil { if err := ProcessDependencyEnabled(c, c.Values); err != nil {
t.Fatalf("Expected no errors but got %q", err) t.Fatalf("Expected no errors but got %q", err)
} }
@ -356,7 +356,7 @@ func TestDependentChartsWithSubChartsSymlink(t *testing.T) {
} }
} }
func TestDependentChartsWithSubchartsAllSpecifiedInRequirements(t *testing.T) { func TestDependentChartsWithSubchartsAllSpecifiedInDependency(t *testing.T) {
c, err := loader.Load("testdata/dependent-chart-with-all-in-requirements-yaml") c, err := loader.Load("testdata/dependent-chart-with-all-in-requirements-yaml")
if err != nil { if err != nil {
t.Fatalf("Failed to load testdata: %s", err) t.Fatalf("Failed to load testdata: %s", err)
@ -367,7 +367,7 @@ func TestDependentChartsWithSubchartsAllSpecifiedInRequirements(t *testing.T) {
} }
origLength := len(c.Dependencies()) origLength := len(c.Dependencies())
if err := ProcessRequirementsEnabled(c, c.Values); err != nil { if err := ProcessDependencyEnabled(c, c.Values); err != nil {
t.Fatalf("Expected no errors but got %q", err) t.Fatalf("Expected no errors but got %q", err)
} }
@ -375,12 +375,12 @@ func TestDependentChartsWithSubchartsAllSpecifiedInRequirements(t *testing.T) {
t.Fatal("Expected no changes in dependencies to be, but did something got changed") t.Fatal("Expected no changes in dependencies to be, but did something got changed")
} }
if len(c.Dependencies()) != len(c.Metadata.Requirements) { if len(c.Dependencies()) != len(c.Metadata.Dependencies) {
t.Fatalf("Expected number of chart dependencies %d, but got %d", len(c.Metadata.Requirements), len(c.Dependencies())) t.Fatalf("Expected number of chart dependencies %d, but got %d", len(c.Metadata.Dependencies), len(c.Dependencies()))
} }
} }
func TestDependentChartsWithSomeSubchartsSpecifiedInRequirements(t *testing.T) { func TestDependentChartsWithSomeSubchartsSpecifiedInDependency(t *testing.T) {
c, err := loader.Load("testdata/dependent-chart-with-mixed-requirements-yaml") c, err := loader.Load("testdata/dependent-chart-with-mixed-requirements-yaml")
if err != nil { if err != nil {
t.Fatalf("Failed to load testdata: %s", err) t.Fatalf("Failed to load testdata: %s", err)
@ -391,7 +391,7 @@ func TestDependentChartsWithSomeSubchartsSpecifiedInRequirements(t *testing.T) {
} }
origLength := len(c.Dependencies()) origLength := len(c.Dependencies())
if err := ProcessRequirementsEnabled(c, c.Values); err != nil { if err := ProcessDependencyEnabled(c, c.Values); err != nil {
t.Fatalf("Expected no errors but got %q", err) t.Fatalf("Expected no errors but got %q", err)
} }
@ -399,21 +399,21 @@ func TestDependentChartsWithSomeSubchartsSpecifiedInRequirements(t *testing.T) {
t.Fatal("Expected no changes in dependencies to be, but did something got changed") t.Fatal("Expected no changes in dependencies to be, but did something got changed")
} }
if len(c.Dependencies()) <= len(c.Metadata.Requirements) { if len(c.Dependencies()) <= len(c.Metadata.Dependencies) {
t.Fatalf("Expected more dependencies than specified in requirements.yaml(%d), but got %d", len(c.Metadata.Requirements), len(c.Dependencies())) t.Fatalf("Expected more dependencies than specified in Chart.yaml(%d), but got %d", len(c.Metadata.Dependencies), len(c.Dependencies()))
} }
} }
func verifyRequirements(t *testing.T, c *chart.Chart) { func verifyDependency(t *testing.T, c *chart.Chart) {
if len(c.Metadata.Requirements) != 2 { if len(c.Metadata.Dependencies) != 2 {
t.Errorf("Expected 2 requirements, got %d", len(c.Metadata.Requirements)) t.Errorf("Expected 2 dependencies, got %d", len(c.Metadata.Dependencies))
} }
tests := []*chart.Dependency{ tests := []*chart.Dependency{
{Name: "alpine", Version: "0.1.0", Repository: "https://example.com/charts"}, {Name: "alpine", Version: "0.1.0", Repository: "https://example.com/charts"},
{Name: "mariner", Version: "4.3.2", Repository: "https://example.com/charts"}, {Name: "mariner", Version: "4.3.2", Repository: "https://example.com/charts"},
} }
for i, tt := range tests { for i, tt := range tests {
d := c.Metadata.Requirements[i] d := c.Metadata.Dependencies[i]
if d.Name != tt.Name { if d.Name != tt.Name {
t.Errorf("Expected dependency named %q, got %q", tt.Name, d.Name) t.Errorf("Expected dependency named %q, got %q", tt.Name, d.Name)
} }
@ -427,15 +427,15 @@ func verifyRequirements(t *testing.T, c *chart.Chart) {
} }
func verifyChartLock(t *testing.T, c *chart.Chart) { func verifyChartLock(t *testing.T, c *chart.Chart) {
if len(c.Metadata.Requirements) != 2 { if len(c.Metadata.Dependencies) != 2 {
t.Errorf("Expected 2 requirements, got %d", len(c.Metadata.Requirements)) t.Errorf("Expected 2 dependencies, got %d", len(c.Metadata.Dependencies))
} }
tests := []*chart.Dependency{ tests := []*chart.Dependency{
{Name: "alpine", Version: "0.1.0", Repository: "https://example.com/charts"}, {Name: "alpine", Version: "0.1.0", Repository: "https://example.com/charts"},
{Name: "mariner", Version: "4.3.2", Repository: "https://example.com/charts"}, {Name: "mariner", Version: "4.3.2", Repository: "https://example.com/charts"},
} }
for i, tt := range tests { for i, tt := range tests {
d := c.Metadata.Requirements[i] d := c.Metadata.Dependencies[i]
if d.Name != tt.Name { if d.Name != tt.Name {
t.Errorf("Expected dependency named %q, got %q", tt.Name, d.Name) t.Errorf("Expected dependency named %q, got %q", tt.Name, d.Name)
} }

@ -1,12 +0,0 @@
dependencies:
- name: alpine
version: "0.1.0"
repository: https://example.com/charts
- name: mariner
version: "4.3.2"
repository: https://example.com/charts
alias: mariners2
- name: mariner
version: "4.3.2"
repository: https://example.com/charts
alias: mariners1

@ -1,7 +0,0 @@
dependencies:
- name: alpine
version: "0.1.0"
repository: https://example.com/charts
- name: mariner
version: "4.3.2"
repository: https://example.com/charts

@ -1,4 +0,0 @@
dependencies:
- name: alpine
version: "0.1.0"
repository: https://example.com/charts

@ -1,7 +0,0 @@
dependencies:
- name: alpine
version: "0.1.0"
repository: https://example.com/charts
- name: mariner
version: "4.3.2"
repository: https://example.com/charts

@ -1,7 +0,0 @@
dependencies:
- name: alpine
version: "0.1.0"
repository: https://example.com/charts
- name: mariner
version: "4.3.2"
repository: https://example.com/charts

@ -1,4 +0,0 @@
dependencies:
- name: albatross
repository: https://example.com/mariner/charts
version: "0.1.0"

@ -1,32 +0,0 @@
dependencies:
- name: subcharta
repository: http://localhost:10191
version: 0.1.0
condition: subcharta.enabled,subchart1.subcharta.enabled
tags:
- front-end
- subcharta
import-values:
- child: SCAdata
parent: imported-chartA
- child: SCAdata
parent: overridden-chartA
- child: SCAdata
parent: imported-chartA-B
- name: subchartb
repository: http://localhost:10191
version: 0.1.0
condition: subchartb.enabled
import-values:
- child: SCBdata
parent: imported-chartB
- child: SCBdata
parent: imported-chartA-B
- child: exports.SCBexported2
parent: exports.SCBexported2
- SCBexported1
tags:
- front-end
- subchartb

@ -1,15 +0,0 @@
dependencies:
- name: subchartb
repository: http://localhost:10191
version: 0.1.0
condition: subchartb.enabled,subchart2.subchartb.enabled
tags:
- back-end
- subchartb
- name: subchartc
repository: http://localhost:10191
version: 0.1.0
condition: subchartc.enabled
tags:
- back-end
- subchartc

@ -1,31 +0,0 @@
dependencies:
- name: subchart1
repository: http://localhost:10191
version: 0.1.0
condition: subchart1.enabled
tags:
- front-end
- subchart1
import-values:
- child: SC1data
parent: imported-chart1
- child: SC1data
parent: overridden-chart1
- child: imported-chartA
parent: imported-chartA
- child: imported-chartA-B
parent: imported-chartA-B
- child: overridden-chartA-B
parent: overridden-chartA-B
- child: SCBexported1A
parent: .
- SCBexported2
- SC1exported1
- name: subchart2
repository: http://localhost:10191
version: 0.1.0
condition: subchart2.enabled
tags:
- back-end
- subchart2

@ -78,7 +78,7 @@ func (m *Manager) Build() error {
return m.Update() return m.Update()
} }
req := c.Metadata.Requirements req := c.Metadata.Dependencies
if sum, err := resolver.HashReq(req); err != nil || sum != lock.Digest { if sum, err := resolver.HashReq(req); err != nil || sum != lock.Digest {
return errors.New("Chart.lock is out of sync with Chart.yaml") return errors.New("Chart.lock is out of sync with Chart.yaml")
} }
@ -114,14 +114,14 @@ func (m *Manager) Update() error {
return err return err
} }
// If no requirements file is found, we consider this a successful // If no dependencies are found, we consider this a successful
// completion. // completion.
req := c.Metadata.Requirements req := c.Metadata.Dependencies
if req == nil { if req == nil {
return nil return nil
} }
// Hash requirements.yaml // Hash dependencies
// FIXME should this hash all of Chart.yaml // FIXME should this hash all of Chart.yaml
hash, err := resolver.HashReq(req) hash, err := resolver.HashReq(req)
if err != nil { if err != nil {
@ -143,7 +143,7 @@ func (m *Manager) Update() error {
} }
// Now we need to find out which version of a chart best satisfies the // Now we need to find out which version of a chart best satisfies the
// requirements in the Chart.yaml // dependencies in the Chart.yaml
lock, err := m.resolve(req, repoNames, hash) lock, err := m.resolve(req, repoNames, hash)
if err != nil { if err != nil {
return err return err
@ -173,9 +173,9 @@ func (m *Manager) loadChartDir() (*chart.Chart, error) {
return loader.LoadDir(m.ChartPath) return loader.LoadDir(m.ChartPath)
} }
// resolve takes a list of requirements and translates them into an exact version to download. // resolve takes a list of dependencies and translates them into an exact version to download.
// //
// This returns a lock file, which has all of the requirements normalized to a specific version. // This returns a lock file, which has all of the dependencies normalized to a specific version.
func (m *Manager) resolve(req []*chart.Dependency, repoNames map[string]string, hash string) (*chart.Lock, error) { func (m *Manager) resolve(req []*chart.Dependency, repoNames map[string]string, hash string) (*chart.Lock, error) {
res := resolver.New(m.ChartPath, m.HelmHome) res := resolver.New(m.ChartPath, m.HelmHome)
return res.Resolve(req, repoNames, hash) return res.Resolve(req, repoNames, hash)

@ -97,11 +97,11 @@ func (c *Client) InstallReleaseFromChart(chart *chart.Chart, ns string, opts ...
} }
var m map[string]interface{} var m map[string]interface{}
yaml.Unmarshal(req.Values, &m) yaml.Unmarshal(req.Values, &m)
err := chartutil.ProcessRequirementsEnabled(req.Chart, m) err := chartutil.ProcessDependencyEnabled(req.Chart, m)
if err != nil { if err != nil {
return nil, err return nil, err
} }
err = chartutil.ProcessRequirementsImportValues(req.Chart) err = chartutil.ProcessDependencyImportValues(req.Chart)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -171,10 +171,10 @@ func (c *Client) UpdateReleaseFromChart(rlsName string, chart *chart.Chart, opts
if err := yaml.Unmarshal(req.Values, &m); err != nil { if err := yaml.Unmarshal(req.Values, &m); err != nil {
return nil, err return nil, err
} }
if err := chartutil.ProcessRequirementsEnabled(req.Chart, m); err != nil { if err := chartutil.ProcessDependencyEnabled(req.Chart, m); err != nil {
return nil, err return nil, err
} }
if err := chartutil.ProcessRequirementsImportValues(req.Chart); err != nil { if err := chartutil.ProcessDependencyImportValues(req.Chart); err != nil {
return nil, err return nil, err
} }

@ -114,7 +114,7 @@ func (r *Resolver) Resolve(reqs []*chart.Dependency, repoNames map[string]string
}, nil }, nil
} }
// HashReq generates a hash of the requirements. // HashReq generates a hash of the dependencies.
// //
// This should be used only to compare against another hash generated by this // This should be used only to compare against another hash generated by this
// function. // function.
@ -128,7 +128,7 @@ func HashReq(req []*chart.Dependency) (string, error) {
} }
// GetLocalPath generates absolute local path when use // GetLocalPath generates absolute local path when use
// "file://" in repository of requirements // "file://" in repository of dependencies
func GetLocalPath(repo, chartpath string) (string, error) { func GetLocalPath(repo, chartpath string) (string, error) {
var depPath string var depPath string
var err error var err error

Loading…
Cancel
Save