diff --git a/pkg/chartutil/requirements.go b/pkg/chartutil/requirements.go index 5f9fa3b3de688a84d965bc2d4f3e3e50541243b8..26d13f3a598c9290b24ca22fffa445ace5225588 100644 --- a/pkg/chartutil/requirements.go +++ b/pkg/chartutil/requirements.go @@ -65,6 +65,8 @@ type Dependency struct { // ImportValues holds the mapping of source values to parent key to be imported. Each item can be a // string or pair of child/parent sublist items. ImportValues []interface{} `json:"import-values"` + // Alias usable alias to be used for the chart + Alias []string `json:"alias"` } // ErrNoRequirementsFile to detect error condition @@ -216,6 +218,45 @@ func ProcessRequirementsTags(reqs *Requirements, cvals Values) { } +func copyChartAsAlias(charts []*chart.Chart, dependentChart, aliasChart string) *chart.Chart { + var chartFound *chart.Chart + for _, existingChart := range charts { + if existingChart == nil { + continue + } + if existingChart.Metadata == nil { + continue + } + if existingChart.Metadata.Name != dependentChart { + continue + } + + chartFound = new(chart.Chart) + chartFound.Metadata = &chart.Metadata{ + Name: aliasChart, + Home: existingChart.Metadata.Home, + Sources: existingChart.Metadata.Sources, + Version: existingChart.Metadata.Version, + Description: existingChart.Metadata.Description, + Keywords: existingChart.Metadata.Keywords, + Maintainers: existingChart.Metadata.Maintainers, + Engine: existingChart.Metadata.Engine, + Icon: existingChart.Metadata.Icon, + ApiVersion: existingChart.Metadata.ApiVersion, + Condition: existingChart.Metadata.Condition, + Tags: existingChart.Metadata.Tags, + AppVersion: existingChart.Metadata.AppVersion, + Deprecated: existingChart.Metadata.Deprecated, + TillerVersion: existingChart.Metadata.TillerVersion, + } + chartFound.Templates = existingChart.Templates + chartFound.Dependencies = existingChart.Dependencies + chartFound.Values = existingChart.Values + chartFound.Files = existingChart.Files + } + return chartFound +} + // ProcessRequirementsEnabled removes disabled charts from dependencies func ProcessRequirementsEnabled(c *chart.Chart, v *chart.Config) error { reqs, err := LoadRequirements(c) @@ -228,6 +269,21 @@ func ProcessRequirementsEnabled(c *chart.Chart, v *chart.Config) error { // no requirements to process return nil } + + for _, req := range reqs.Dependencies { + for _, alias := range req.Alias { + aliasDependency := copyChartAsAlias(c.Dependencies, req.Name, alias) + if aliasDependency == nil { + break + } + c.Dependencies = append(c.Dependencies, aliasDependency) + origReqName := req.Name + req.Name = alias + reqs.Dependencies = append(reqs.Dependencies, req) + req.Name = origReqName + } + } + // set all to true for _, lr := range reqs.Dependencies { lr.Enabled = true diff --git a/pkg/resolver/resolver_test.go b/pkg/resolver/resolver_test.go index ef5a3bee0ff2ee877ea495e6bc6da043a2fbe922..9453a979f483653c149e17e976e0c9664c1bf1e7 100644 --- a/pkg/resolver/resolver_test.go +++ b/pkg/resolver/resolver_test.go @@ -146,7 +146,7 @@ func TestResolve(t *testing.T) { } func TestHashReq(t *testing.T) { - expect := "sha256:1feffe2016ca113f64159d91c1f77d6a83bcd23510b171d9264741bf9d63f741" + expect := "sha256:917e251ddba291096889f81eb7de713ab4e1afbbb07c576dfd7d66ba9300b12b" req := &chartutil.Requirements{ Dependencies: []*chartutil.Dependency{ {Name: "alpine", Version: "0.1.0", Repository: "http://localhost:8879/charts"},