diff --git a/pkg/chart/loader/load.go b/pkg/chart/loader/load.go index dd4fd2dff..5f7b96f46 100644 --- a/pkg/chart/loader/load.go +++ b/pkg/chart/loader/load.go @@ -83,6 +83,17 @@ func LoadFiles(files []*BufferedFile) (*chart.Chart, error) { if err := yaml.Unmarshal(f.Data, c.Metadata); err != nil { return c, errors.Wrap(err, "cannot load Chart.yaml") } + // when unmarshaling dependencies, the value of Enabled will default to false + // in order to make use of this flag, first need to change all values to true, then unmarshal again + if len(c.Metadata.Dependencies) > 0 { + for _, dep := range c.Metadata.Dependencies { + dep.Enabled = true + } + if err := yaml.Unmarshal(f.Data, c.Metadata); err != nil { + return c, errors.Wrap(err, "reloading Chart.yaml failed") + } + } + // NOTE(bacongobbler): while the chart specification says that APIVersion must be set, // Helm 2 accepted charts that did not provide an APIVersion in their chart metadata. // Because of that, if APIVersion is unset, we should assume we're loading a v1 chart. diff --git a/pkg/chart/loader/load_test.go b/pkg/chart/loader/load_test.go index 40b86dec2..f5b45f326 100644 --- a/pkg/chart/loader/load_test.go +++ b/pkg/chart/loader/load_test.go @@ -450,8 +450,8 @@ func verifyDependencies(t *testing.T, c *chart.Chart) { t.Errorf("Expected 2 dependencies, got %d", len(c.Metadata.Dependencies)) } tests := []*chart.Dependency{ - {Name: "alpine", Version: "0.1.0", Repository: "https://example.com/charts"}, - {Name: "mariner", Version: "4.3.2", Repository: "https://example.com/charts"}, + {Name: "alpine", Version: "0.1.0", Repository: "https://example.com/charts", Enabled: true}, + {Name: "mariner", Version: "4.3.2", Repository: "https://example.com/charts", Enabled: false}, } for i, tt := range tests { d := c.Metadata.Dependencies[i] @@ -464,6 +464,9 @@ func verifyDependencies(t *testing.T, c *chart.Chart) { if d.Repository != tt.Repository { t.Errorf("Expected dependency named %q to have repository %q, got %q", tt.Name, tt.Repository, d.Repository) } + if d.Enabled != tt.Enabled { + t.Errorf("Expected dependency named %q to have enabled %t, got %t", tt.Name, tt.Enabled, d.Enabled) + } } } diff --git a/pkg/chart/loader/testdata/frobnitz-1.2.3.tgz b/pkg/chart/loader/testdata/frobnitz-1.2.3.tgz index b2b76a83c..3ba46430c 100644 Binary files a/pkg/chart/loader/testdata/frobnitz-1.2.3.tgz and b/pkg/chart/loader/testdata/frobnitz-1.2.3.tgz differ diff --git a/pkg/chart/loader/testdata/frobnitz.v1.tgz b/pkg/chart/loader/testdata/frobnitz.v1.tgz index 6282f9b73..3ba46430c 100644 Binary files a/pkg/chart/loader/testdata/frobnitz.v1.tgz and b/pkg/chart/loader/testdata/frobnitz.v1.tgz differ diff --git a/pkg/chart/loader/testdata/frobnitz.v1/requirements.yaml b/pkg/chart/loader/testdata/frobnitz.v1/requirements.yaml index 5eb0bc98b..5f2605c8b 100644 --- a/pkg/chart/loader/testdata/frobnitz.v1/requirements.yaml +++ b/pkg/chart/loader/testdata/frobnitz.v1/requirements.yaml @@ -2,6 +2,8 @@ dependencies: - name: alpine version: "0.1.0" repository: https://example.com/charts + enabled: true - name: mariner version: "4.3.2" repository: https://example.com/charts + enabled: false diff --git a/pkg/chart/loader/testdata/frobnitz.v2.reqs/requirements.yaml b/pkg/chart/loader/testdata/frobnitz.v2.reqs/requirements.yaml index 5eb0bc98b..5f2605c8b 100644 --- a/pkg/chart/loader/testdata/frobnitz.v2.reqs/requirements.yaml +++ b/pkg/chart/loader/testdata/frobnitz.v2.reqs/requirements.yaml @@ -2,6 +2,8 @@ dependencies: - name: alpine version: "0.1.0" repository: https://example.com/charts + enabled: true - name: mariner version: "4.3.2" repository: https://example.com/charts + enabled: false diff --git a/pkg/chart/loader/testdata/frobnitz/Chart.yaml b/pkg/chart/loader/testdata/frobnitz/Chart.yaml index fcd4a4a37..be60fdf23 100644 --- a/pkg/chart/loader/testdata/frobnitz/Chart.yaml +++ b/pkg/chart/loader/testdata/frobnitz/Chart.yaml @@ -22,6 +22,8 @@ dependencies: - name: alpine version: "0.1.0" repository: https://example.com/charts + enabled: true - name: mariner version: "4.3.2" repository: https://example.com/charts + enabled: false diff --git a/pkg/chart/loader/testdata/frobnitz/charts/mariner-4.3.2.tgz b/pkg/chart/loader/testdata/frobnitz/charts/mariner-4.3.2.tgz index 3190136b0..06a55572b 100644 Binary files a/pkg/chart/loader/testdata/frobnitz/charts/mariner-4.3.2.tgz and b/pkg/chart/loader/testdata/frobnitz/charts/mariner-4.3.2.tgz differ diff --git a/pkg/chart/loader/testdata/frobnitz_backslash-1.2.3.tgz b/pkg/chart/loader/testdata/frobnitz_backslash-1.2.3.tgz index a9d4c11d8..f796ee4e4 100644 Binary files a/pkg/chart/loader/testdata/frobnitz_backslash-1.2.3.tgz and b/pkg/chart/loader/testdata/frobnitz_backslash-1.2.3.tgz differ diff --git a/pkg/chart/loader/testdata/frobnitz_backslash/charts/mariner-4.3.2.tgz b/pkg/chart/loader/testdata/frobnitz_backslash/charts/mariner-4.3.2.tgz index 3190136b0..06a55572b 100755 Binary files a/pkg/chart/loader/testdata/frobnitz_backslash/charts/mariner-4.3.2.tgz and b/pkg/chart/loader/testdata/frobnitz_backslash/charts/mariner-4.3.2.tgz differ diff --git a/pkg/chart/loader/testdata/frobnitz_with_bom/Chart.yaml b/pkg/chart/loader/testdata/frobnitz_with_bom/Chart.yaml index 21b21f0b5..8415c385d 100644 --- a/pkg/chart/loader/testdata/frobnitz_with_bom/Chart.yaml +++ b/pkg/chart/loader/testdata/frobnitz_with_bom/Chart.yaml @@ -22,6 +22,8 @@ dependencies: - name: alpine version: "0.1.0" repository: https://example.com/charts + enabled: true - name: mariner version: "4.3.2" repository: https://example.com/charts + enabled: false diff --git a/pkg/chart/loader/testdata/frobnitz_with_symlink/Chart.yaml b/pkg/chart/loader/testdata/frobnitz_with_symlink/Chart.yaml index fcd4a4a37..be60fdf23 100644 --- a/pkg/chart/loader/testdata/frobnitz_with_symlink/Chart.yaml +++ b/pkg/chart/loader/testdata/frobnitz_with_symlink/Chart.yaml @@ -22,6 +22,8 @@ dependencies: - name: alpine version: "0.1.0" repository: https://example.com/charts + enabled: true - name: mariner version: "4.3.2" repository: https://example.com/charts + enabled: false diff --git a/pkg/chart/loader/testdata/mariner/charts/albatross-0.1.0.tgz b/pkg/chart/loader/testdata/mariner/charts/albatross-0.1.0.tgz index 128ef82f7..aab5a31de 100644 Binary files a/pkg/chart/loader/testdata/mariner/charts/albatross-0.1.0.tgz and b/pkg/chart/loader/testdata/mariner/charts/albatross-0.1.0.tgz differ diff --git a/pkg/chartutil/dependencies.go b/pkg/chartutil/dependencies.go index d2e7d6dc9..abe99f06e 100644 --- a/pkg/chartutil/dependencies.go +++ b/pkg/chartutil/dependencies.go @@ -137,6 +137,9 @@ Loop: } for _, req := range c.Metadata.Dependencies { + if req.Enabled == false { + continue + } if chartDependency := getAliasDependency(c.Dependencies(), req); chartDependency != nil { chartDependencies = append(chartDependencies, chartDependency) } diff --git a/pkg/chartutil/dependencies_test.go b/pkg/chartutil/dependencies_test.go index 342d7fe87..6112c6af4 100644 --- a/pkg/chartutil/dependencies_test.go +++ b/pkg/chartutil/dependencies_test.go @@ -70,47 +70,55 @@ func TestDependencyEnabled(t *testing.T) { }{{ "tags with no effect", M{"tags": M{"nothinguseful": false}}, - []string{"parentchart", "parentchart.subchart1", "parentchart.subchart1.subcharta", "parentchart.subchart1.subchartb"}, + []string{"parentchart", "parentchart.subchart1", "parentchart.subchart1.subcharta", "parentchart.subchart1.subchartb", "parentchart.subchart2alwaysEnabled"}, }, { "tags disabling a group", M{"tags": M{"front-end": false}}, - []string{"parentchart"}, + []string{"parentchart", "parentchart.subchart2alwaysEnabled"}, }, { "tags disabling a group and enabling a different group", M{"tags": M{"front-end": false, "back-end": true}}, - []string{"parentchart", "parentchart.subchart2", "parentchart.subchart2.subchartb", "parentchart.subchart2.subchartc"}, + []string{"parentchart", "parentchart.subchart2", "parentchart.subchart2.subchartb", "parentchart.subchart2.subchartc", "parentchart.subchart2alwaysEnabled", "parentchart.subchart2alwaysEnabled.subchartb", "parentchart.subchart2alwaysEnabled.subchartc"}, }, { "tags disabling only children, children still enabled since tag front-end=true in values.yaml", M{"tags": M{"subcharta": false, "subchartb": false}}, - []string{"parentchart", "parentchart.subchart1", "parentchart.subchart1.subcharta", "parentchart.subchart1.subchartb"}, + []string{"parentchart", "parentchart.subchart1", "parentchart.subchart1.subcharta", "parentchart.subchart1.subchartb", "parentchart.subchart2alwaysEnabled"}, }, { "tags disabling all parents/children with additional tag re-enabling a parent", M{"tags": M{"front-end": false, "subchart1": true, "back-end": false}}, - []string{"parentchart", "parentchart.subchart1"}, + []string{"parentchart", "parentchart.subchart1", "parentchart.subchart2alwaysEnabled"}, }, { "conditions enabling the parent charts, but back-end (b, c) is still disabled via values.yaml", M{"subchart1": M{"enabled": true}, "subchart2": M{"enabled": true}}, - []string{"parentchart", "parentchart.subchart1", "parentchart.subchart1.subcharta", "parentchart.subchart1.subchartb", "parentchart.subchart2"}, + []string{"parentchart", "parentchart.subchart1", "parentchart.subchart1.subcharta", "parentchart.subchart1.subchartb", "parentchart.subchart2", "parentchart.subchart2alwaysEnabled"}, }, { "conditions disabling the parent charts, effectively disabling children", M{"subchart1": M{"enabled": false}, "subchart2": M{"enabled": false}}, - []string{"parentchart"}, + []string{"parentchart", "parentchart.subchart2alwaysEnabled"}, }, { "conditions a child using the second condition path of child's condition", M{"subchart1": M{"subcharta": M{"enabled": false}}}, - []string{"parentchart", "parentchart.subchart1", "parentchart.subchart1.subchartb"}, + []string{"parentchart", "parentchart.subchart1", "parentchart.subchart1.subchartb", "parentchart.subchart2alwaysEnabled"}, }, { "tags enabling a parent/child group with condition disabling one child", M{"subchart2": M{"subchartc": M{"enabled": false}}, "tags": M{"back-end": true}}, - []string{"parentchart", "parentchart.subchart1", "parentchart.subchart1.subcharta", "parentchart.subchart1.subchartb", "parentchart.subchart2", "parentchart.subchart2.subchartb"}, + []string{"parentchart", "parentchart.subchart1", "parentchart.subchart1.subcharta", "parentchart.subchart1.subchartb", "parentchart.subchart2", "parentchart.subchart2.subchartb", "parentchart.subchart2alwaysEnabled", "parentchart.subchart2alwaysEnabled.subchartb"}, }, { "tags will not enable a child if parent is explicitly disabled with condition", M{"subchart1": M{"enabled": false}, "tags": M{"front-end": true}}, - []string{"parentchart"}, + []string{"parentchart", "parentchart.subchart2alwaysEnabled"}, }, { "subcharts with alias also respect conditions", M{"subchart1": M{"enabled": false}, "subchart2alias": M{"enabled": true, "subchartb": M{"enabled": true}}}, - []string{"parentchart", "parentchart.subchart2alias", "parentchart.subchart2alias.subchartb"}, + []string{"parentchart", "parentchart.subchart2alias", "parentchart.subchart2alias.subchartb", "parentchart.subchart2alwaysEnabled"}, + }, { + "conditions don't enable a disabled chart", + M{"subchart1": M{"enabled": false}, "subchart2diabled": M{"enabled": true}}, + []string{"parentchart", "parentchart.subchart2alwaysEnabled"}, + }, { + "conditions can disable an enabled chart", + M{"subchart1": M{"enabled": false}, "subchart2alwaysEnabled": M{"enabled": false}}, + []string{"parentchart"}, }} for _, tc := range tests { diff --git a/pkg/chartutil/testdata/subpop/Chart.yaml b/pkg/chartutil/testdata/subpop/Chart.yaml index 27118672a..806be2410 100644 --- a/pkg/chartutil/testdata/subpop/Chart.yaml +++ b/pkg/chartutil/testdata/subpop/Chart.yaml @@ -39,3 +39,17 @@ dependencies: repository: http://localhost:10191 version: 0.1.0 condition: subchart2alias.enabled + + - name: subchart2 + alias: subchart2diabled + repository: http://localhost:10191 + version: 0.1.0 + enabled: false + condition: subchart2diabled.enabled + + - name: subchart2 + alias: subchart2alwaysEnabled + repository: http://localhost:10191 + version: 0.1.0 + enabled: true + condition: subchart2alwaysEnabled.enabled