Adds alias for dependencies

Fixes https://github.com/kubernetes/helm/issues/2383

Sample `requirements.yaml` I used for test purpose was for wordpress chart

```dependencies:
- name: mariadb
  version: 0.5.10
  repository: https://kubernetes-charts.storage.googleapis.com/
  alias:
  - db1
  - db2
  - db3
```
pull/2486/head
Sushil Kumar 8 years ago
parent fcf48f430b
commit 156d48bc3b

@ -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

@ -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"},

Loading…
Cancel
Save