Commit 716be14a authored by Sushil Kumar's avatar Sushil Kumar
Browse files

Updated code to read requirements.yaml as per following structure

```
- name: <dependency-chart-name>
  alias: <alias-name-to-be-used>
  version: <dependency-chart-version>
  repository: <dependency-chart-version>
```
parent 541d0522
main Release add-codeql dependabot/go_modules/github.com/docker/distribution-2.8.2incompatible dependabot/go_modules/github.com/lib/pq-1.10.9 dependabot/go_modules/github.com/rubenv/sql-migrate-1.4.0 dependabot/go_modules/golang.org/x/crypto-0.9.0 dependabot/go_modules/golang.org/x/term-0.8.0 dependabot/go_modules/k8s.io/klog/v2-2.100.1 dev-v2 feat-v3/event-emitter-lua release-2.10 release-2.11 release-2.12 release-2.13 release-2.14 release-2.15 release-2.16 release-2.17 release-2.5 release-2.6 release-2.7 release-2.8 release-2.9 release-3.0 release-3.1 release-3.10 release-3.11 release-3.12 release-3.2 release-3.3 release-3.4 release-3.5 release-3.6 release-3.6.1 release-3.6.2 release-3.7 release-3.8 release-3.9 release-v3.0.0-beta.4 v3.12.0 v3.12.0-rc.1 v3.12.0-dev.1 v3.11.3 v3.11.2 v3.11.1 v3.11.0 v3.11.0-rc.2 v3.11.0-rc.1 v3.10.3 v3.10.2 v3.10.1 v3.10.0 v3.10.0-rc.1 v3.9.4 v3.9.3 v3.9.2 v3.9.1 v3.9.0 v3.9.0-rc.1 v3.8.2 v3.8.1 v3.8.0 v3.8.0-rc.2 v3.8.0-rc.1 v3.7.2 v3.7.1 v3.7.0 v3.7.0-rc.3 v3.7.0-rc.2 v3.7.0-rc.1 v3.6.3 v3.6.2 v3.6.1 v3.6.0 v3.6.0-rc.1 v3.5.4 v3.5.3 v3.5.2 v3.5.1 v3.5.0 v3.5.0-rc.2 v3.5.0-rc.1 v3.4.2 v3.4.1 v3.4.0 v3.4.0-rc.1 v3.3.4 v3.3.3 v3.3.2 v3.3.1 v3.3.0 v3.3.0-rc.2 v3.3.0-rc.1 v3.2.4 v3.2.3 v3.2.2 v3.2.1 v3.2.0 v3.2.0-rc.1 v3.1.3 v3.1.2 v3.1.1 v3.1.0 v3.1.0-rc.3 v3.1.0-rc.2 v3.1.0-rc.1 v3.0.3 v3.0.2 v3.0.1 v3.0.0 v3.0.0-rc.4 v3.0.0-rc.3 v3.0.0-rc.2 v3.0.0-rc.1 v3.0.0-beta.5 v3.0.0-beta.4 v3.0.0-beta.3 v3.0.0-beta.2 v3.0.0-beta.1 v3.0.0-alpha.2 v3.0.0-alpha.1 v2.17.0 v2.17.0-rc.1 v2.16.12 v2.16.11 v2.16.10 v2.16.9 v2.16.8 v2.16.7 v2.16.6 v2.16.5 v2.16.4 v2.16.3 v2.16.2 v2.16.1 v2.16.0 v2.16.0-rc.2 v2.16.0-rc.1 v2.15.2 v2.15.1 v2.15.0 v2.15.0-rc.2 v2.15.0-rc.1 v2.14.3 v2.14.2 v2.14.1 v2.14.0 v2.14.0-rc.2 v2.14.0-rc.1 v2.13.1 v2.13.1-rc.1 v2.13.0 v2.13.0-rc.2 v2.13.0-rc.1 v2.12.3 v2.12.2 v2.12.1 v2.12.0 v2.12.0-rc.2 v2.12.0-rc.1 v2.11.0 v2.11.0-rc.4 v2.11.0-rc.3 v2.11.0-rc.2 v2.11.0-rc.1 v2.10.0 v2.10.0-rc.3 v2.10.0-rc.2 v2.10.0-rc.1 v2.9.1 v2.9.0 v2.9.0-rc5 v2.9.0-rc4 v2.9.0-rc3 v2.9.0-rc2 v2.9.0-rc1 v2.8.2 v2.8.2-rc1 v2.8.1 v2.8.0 v2.8.0-rc.1 v2.7.2 v2.7.1 v2.7.0 v2.7.0-rc1 v2.6.2 v2.6.1 v2.6.0 v2.5.1 v2.5.0
No related merge requests found
Showing with 49 additions and 52 deletions
+49 -52
......@@ -66,7 +66,7 @@ type Dependency struct {
// 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"`
Alias string `json:"alias"`
}
// ErrNoRequirementsFile to detect error condition
......@@ -218,7 +218,7 @@ func ProcessRequirementsTags(reqs *Requirements, cvals Values) {
}
func updateChartDependencyAlias(charts []*chart.Chart, dependentChart, aliasChart string, firstAlias bool) *chart.Chart {
func getAliasDependency(charts []*chart.Chart, aliasChart *Dependency) *chart.Chart {
var chartFound chart.Chart
for _, existingChart := range charts {
if existingChart == nil {
......@@ -227,17 +227,17 @@ func updateChartDependencyAlias(charts []*chart.Chart, dependentChart, aliasChar
if existingChart.Metadata == nil {
continue
}
if existingChart.Metadata.Name != dependentChart {
if existingChart.Metadata.Name != aliasChart.Name {
continue
}
if firstAlias {
existingChart.Metadata.Name = aliasChart
return nil
if existingChart.Metadata.Version != aliasChart.Version {
continue
}
chartFound = *existingChart
newMetadata := *existingChart.Metadata
newMetadata.Name = aliasChart
if aliasChart.Alias != "" {
newMetadata.Name = aliasChart.Alias
}
chartFound.Metadata = &newMetadata
return &chartFound
}
......@@ -257,25 +257,16 @@ func ProcessRequirementsEnabled(c *chart.Chart, v *chart.Config) error {
return nil
}
var chartDependencies []*chart.Chart
for _, req := range reqs.Dependencies {
var firstAlias = true
var dependentChartName = req.Name
for _, alias := range req.Alias {
aliasDependency := updateChartDependencyAlias(c.Dependencies, dependentChartName, alias, firstAlias)
if firstAlias {
dependentChartName = alias
firstAlias = false
continue
}
if aliasDependency == nil {
break
}
c.Dependencies = append(c.Dependencies, aliasDependency)
req.Name = alias
reqs.Dependencies = append(reqs.Dependencies, req)
req.Name = dependentChartName
if chartDependency := getAliasDependency(c.Dependencies, req); chartDependency != nil {
chartDependencies = append(chartDependencies, chartDependency)
}
if req.Alias != "" {
req.Name = req.Alias
}
}
c.Dependencies = chartDependencies
// set all to true
for _, lr := range reqs.Dependencies {
......
......@@ -321,33 +321,37 @@ func verifyRequirementsImportValues(t *testing.T, c *chart.Chart, v *chart.Confi
}
}
func TestUpdateChartDependencyAlias(t *testing.T) {
func TestGetAliasDependency(t *testing.T) {
c, err := Load("testdata/frobnitz")
if err != nil {
t.Fatalf("Failed to load testdata: %s", err)
}
if aliasChart := updateChartDependencyAlias(c.Dependencies, "mariners", "another-mariner", false); aliasChart != nil {
t.Fatalf("expected no chart but got %s", aliasChart.Metadata.Name)
req, err := LoadRequirements(c)
if err != nil {
t.Fatalf("Failed to load requirement for testdata: %s", err)
}
if len(req.Dependencies) == 0 {
t.Fatalf("There are no requirements to test")
}
aliasChart := updateChartDependencyAlias(c.Dependencies, "mariner", "another-mariner", false)
// Success case
aliasChart := getAliasDependency(c.Dependencies, req.Dependencies[0])
if aliasChart == nil {
t.Fatal("Failed to find dependent chart")
}
if aliasChart.Metadata.Name != "another-mariner" {
t.Fatal(`Failed to update chart-name for alias "dependent chart`)
t.Fatalf("Failed to get dependency chart for alias %s", req.Dependencies[0].Name)
}
//Testing single-alias update, first update and then try same with non-first alias, we should not be able to find chart
if aliasChart := updateChartDependencyAlias(c.Dependencies, "mariner", "another-mariner", true); aliasChart != nil {
t.Fatalf("expected no chart but got %s", aliasChart.Metadata.Name)
if req.Dependencies[0].Alias != "" {
if aliasChart.Metadata.Name != req.Dependencies[0].Alias {
t.Fatalf("Dependency chart name should be %s but got %s", req.Dependencies[0].Alias, aliasChart.Metadata.Name)
}
} else if aliasChart.Metadata.Name != req.Dependencies[0].Name {
t.Fatalf("Dependency chart name should be %s but got %s", req.Dependencies[0].Name, aliasChart.Metadata.Name)
}
if aliasChart := updateChartDependencyAlias(c.Dependencies, "mariner", "another-mariner", false); aliasChart != nil {
// Failure case
req.Dependencies[0].Name = "something-else"
if aliasChart := getAliasDependency(c.Dependencies, req.Dependencies[0]); aliasChart != nil {
t.Fatalf("expected no chart but got %s", aliasChart.Metadata.Name)
}
}
func TestDependentChartAliases(t *testing.T) {
......@@ -374,15 +378,15 @@ func TestDependentChartAliases(t *testing.T) {
t.Fatalf("Cannot load requirements for test chart, %v", err)
}
var expectedDependencyCharts int
for _, reqmt := range reqmts.Dependencies {
expectedDependencyCharts++
if len(reqmt.Alias) >= 0 {
expectedDependencyCharts += len(reqmt.Alias)
}
}
if len(c.Dependencies) != expectedDependencyCharts-1 {
t.Fatalf("Expected number of chart dependencies %d, but got %d", expectedDependencyCharts-1, len(c.Dependencies))
// var expectedDependencyCharts int
// for _, reqmt := range reqmts.Dependencies {
// expectedDependencyCharts++
// if len(reqmt.Alias) >= 0 {
// expectedDependencyCharts += len(reqmt.Alias)
// }
// }
if len(c.Dependencies) != len(reqmts.Dependencies) {
t.Fatalf("Expected number of chart dependencies %d, but got %d", len(reqmts.Dependencies), len(c.Dependencies))
}
}
......@@ -5,6 +5,8 @@ dependencies:
- name: mariner
version: "4.3.2"
repository: https://example.com/charts
alias:
- mariners1
- mariners2
alias: mariners2
- name: mariner
version: "4.3.2"
repository: https://example.com/charts
alias: mariners1
......@@ -146,7 +146,7 @@ func TestResolve(t *testing.T) {
}
func TestHashReq(t *testing.T) {
expect := "sha256:917e251ddba291096889f81eb7de713ab4e1afbbb07c576dfd7d66ba9300b12b"
expect := "sha256:45b06fcc4496c705bf3d634f8a2ff84e6a6f0bdcaf010614b8886572d1e52b99"
req := &chartutil.Requirements{
Dependencies: []*chartutil.Dependency{
{Name: "alpine", Version: "0.1.0", Repository: "http://localhost:8879/charts"},
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment