Commit 883da973 authored by Matt Butcher's avatar Matt Butcher Committed by GitHub

Merge pull request #2607 from sushilkm/issues/2599

Adds charts in "charts\" directory to dependencies
parents 475de1f4 82da721c
...@@ -258,6 +258,24 @@ func ProcessRequirementsEnabled(c *chart.Chart, v *chart.Config) error { ...@@ -258,6 +258,24 @@ func ProcessRequirementsEnabled(c *chart.Chart, v *chart.Config) error {
} }
var chartDependencies []*chart.Chart var chartDependencies []*chart.Chart
// If any dependency is not a part of requirements.yaml
// then this should be added to chartDependencies.
// However, if the dependency is already specified in requirements.yaml
// we should not add it, as it would be anyways processed from requirements.yaml
for _, existingDependency := range c.Dependencies {
var dependencyFound bool
for _, req := range reqs.Dependencies {
if existingDependency.Metadata.Name == req.Name && existingDependency.Metadata.Version == req.Version {
dependencyFound = true
break
}
}
if !dependencyFound {
chartDependencies = append(chartDependencies, existingDependency)
}
}
for _, req := range reqs.Dependencies { for _, req := range reqs.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)
......
...@@ -378,15 +378,89 @@ func TestDependentChartAliases(t *testing.T) { ...@@ -378,15 +378,89 @@ func TestDependentChartAliases(t *testing.T) {
t.Fatalf("Cannot load requirements for test chart, %v", err) 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) != len(reqmts.Dependencies) { if len(c.Dependencies) != len(reqmts.Dependencies) {
t.Fatalf("Expected number of chart dependencies %d, but got %d", len(reqmts.Dependencies), len(c.Dependencies)) t.Fatalf("Expected number of chart dependencies %d, but got %d", len(reqmts.Dependencies), len(c.Dependencies))
} }
} }
func TestDependentChartWithSubChartsAbsentInRequirements(t *testing.T) {
c, err := Load("testdata/dependent-chart-no-requirements-yaml")
if err != nil {
t.Fatalf("Failed to load testdata: %s", err)
}
if len(c.Dependencies) != 2 {
t.Fatalf("Expected 2 dependencies for this chart, but got %d", len(c.Dependencies))
}
origLength := len(c.Dependencies)
if err := ProcessRequirementsEnabled(c, c.Values); err != nil {
t.Fatalf("Expected no errors but got %q", err)
}
if len(c.Dependencies) != origLength {
t.Fatal("Expected no changes in dependencies to be, but did something got changed")
}
}
func TestDependentChartsWithSubchartsAllSpecifiedInRequirements(t *testing.T) {
c, err := Load("testdata/dependent-chart-with-all-in-requirements-yaml")
if err != nil {
t.Fatalf("Failed to load testdata: %s", err)
}
if len(c.Dependencies) == 0 {
t.Fatal("There are no dependencies to run this test")
}
origLength := len(c.Dependencies)
if err := ProcessRequirementsEnabled(c, c.Values); err != nil {
t.Fatalf("Expected no errors but got %q", err)
}
if len(c.Dependencies) != origLength {
t.Fatal("Expected no changes in dependencies to be, but did something got changed")
}
reqmts, err := LoadRequirements(c)
if err != nil {
t.Fatalf("Cannot load requirements for test chart, %v", err)
}
if len(c.Dependencies) != len(reqmts.Dependencies) {
t.Fatalf("Expected number of chart dependencies %d, but got %d", len(reqmts.Dependencies), len(c.Dependencies))
}
}
func TestDependentChartsWithSomeSubchartsSpecifiedInRequirements(t *testing.T) {
c, err := Load("testdata/dependent-chart-with-mixed-requirements-yaml")
if err != nil {
t.Fatalf("Failed to load testdata: %s", err)
}
if len(c.Dependencies) == 0 {
t.Fatal("There are no dependencies to run this test")
}
origLength := len(c.Dependencies)
if err := ProcessRequirementsEnabled(c, c.Values); err != nil {
t.Fatalf("Expected no errors but got %q", err)
}
if len(c.Dependencies) != origLength {
t.Fatal("Expected no changes in dependencies to be, but did something got changed")
}
reqmts, err := LoadRequirements(c)
if err != nil {
t.Fatalf("Cannot load requirements for test chart, %v", err)
}
if len(c.Dependencies) <= len(reqmts.Dependencies) {
t.Fatalf("Expected more dependencies than specified in requirements.yaml(%d), but got %d", len(reqmts.Dependencies), len(c.Dependencies))
}
}
apiVersion: v1
name: frobnitz
description: This is a frobnitz.
version: "1.2.3"
keywords:
- frobnitz
- sprocket
- dodad
maintainers:
- name: The Helm Team
email: helm@example.com
- name: Someone Else
email: nobody@example.com
sources:
- https://example.com/foo/bar
home: http://example.com
icon: https://example.com/64x64.png
This is an install document. The client may display this.
# Frobnitz
This is an example chart.
## Usage
This is an example. It has no usage.
## Development
For developer info, see the top-level repository.
This should be ignored by the loader, but may be included in a chart.
name: alpine
description: Deploy a basic Alpine Linux pod
version: 0.1.0
home: https://k8s.io/helm
This example was generated using the command `helm create alpine`.
The `templates/` directory contains a very simple pod resource with a
couple of parameters.
The `values.toml` file contains the default values for the
`alpine-pod.yaml` template.
You can install this example using `helm install docs/examples/alpine`.
name: mast1
description: A Helm chart for Kubernetes
version: 0.1.0
home: ""
# Default values for mast1.
# This is a YAML-formatted file.
# Declare name/value pairs to be passed into your templates.
# name = "value"
apiVersion: v1
kind: Pod
metadata:
name: {{.Release.Name}}-{{.Chart.Name}}
labels:
heritage: {{.Release.Service}}
chartName: {{.Chart.Name}}
chartVersion: {{.Chart.Version | quote}}
annotations:
"helm.sh/created": "{{.Release.Time.Seconds}}"
spec:
restartPolicy: {{default "Never" .restart_policy}}
containers:
- name: waiter
image: "alpine:3.3"
command: ["/bin/sleep","9000"]
<?xml version="1.0"?>
<svg xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
version="1.0" width="256" height="256" id="test">
<desc>Example icon</desc>
<rect id="first" x="2" y="2" width="40" height="60" fill="navy"/>
<rect id="second" x="15" y="4" width="40" height="60" fill="red"/>
</svg>
# A values file contains configuration.
name: "Some Name"
section:
name: "Name in a section"
apiVersion: v1
name: frobnitz
description: This is a frobnitz.
version: "1.2.3"
keywords:
- frobnitz
- sprocket
- dodad
maintainers:
- name: The Helm Team
email: helm@example.com
- name: Someone Else
email: nobody@example.com
sources:
- https://example.com/foo/bar
home: http://example.com
icon: https://example.com/64x64.png
This is an install document. The client may display this.
# Frobnitz
This is an example chart.
## Usage
This is an example. It has no usage.
## Development
For developer info, see the top-level repository.
This should be ignored by the loader, but may be included in a chart.
name: alpine
description: Deploy a basic Alpine Linux pod
version: 0.1.0
home: https://k8s.io/helm
This example was generated using the command `helm create alpine`.
The `templates/` directory contains a very simple pod resource with a
couple of parameters.
The `values.toml` file contains the default values for the
`alpine-pod.yaml` template.
You can install this example using `helm install docs/examples/alpine`.
name: mast1
description: A Helm chart for Kubernetes
version: 0.1.0
home: ""
# Default values for mast1.
# This is a YAML-formatted file.
# Declare name/value pairs to be passed into your templates.
# name = "value"
apiVersion: v1
kind: Pod
metadata:
name: {{.Release.Name}}-{{.Chart.Name}}
labels:
heritage: {{.Release.Service}}
chartName: {{.Chart.Name}}
chartVersion: {{.Chart.Version | quote}}
annotations:
"helm.sh/created": "{{.Release.Time.Seconds}}"
spec:
restartPolicy: {{default "Never" .restart_policy}}
containers:
- name: waiter
image: "alpine:3.3"
command: ["/bin/sleep","9000"]
<?xml version="1.0"?>
<svg xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
version="1.0" width="256" height="256" id="test">
<desc>Example icon</desc>
<rect id="first" x="2" y="2" width="40" height="60" fill="navy"/>
<rect id="second" x="15" y="4" width="40" height="60" fill="red"/>
</svg>
dependencies:
- name: alpine
version: "0.1.0"
repository: https://example.com/charts
- name: mariner
version: "4.3.2"
repository: https://example.com/charts
# A values file contains configuration.
name: "Some Name"
section:
name: "Name in a section"
apiVersion: v1
name: frobnitz
description: This is a frobnitz.
version: "1.2.3"
keywords:
- frobnitz
- sprocket
- dodad
maintainers:
- name: The Helm Team
email: helm@example.com
- name: Someone Else
email: nobody@example.com
sources:
- https://example.com/foo/bar
home: http://example.com
icon: https://example.com/64x64.png
This is an install document. The client may display this.
# Frobnitz
This is an example chart.
## Usage
This is an example. It has no usage.
## Development
For developer info, see the top-level repository.
This should be ignored by the loader, but may be included in a chart.
name: alpine
description: Deploy a basic Alpine Linux pod
version: 0.1.0
home: https://k8s.io/helm
This example was generated using the command `helm create alpine`.
The `templates/` directory contains a very simple pod resource with a
couple of parameters.
The `values.toml` file contains the default values for the
`alpine-pod.yaml` template.
You can install this example using `helm install docs/examples/alpine`.
name: mast1
description: A Helm chart for Kubernetes
version: 0.1.0
home: ""
# Default values for mast1.
# This is a YAML-formatted file.
# Declare name/value pairs to be passed into your templates.
# name = "value"
apiVersion: v1
kind: Pod
metadata:
name: {{.Release.Name}}-{{.Chart.Name}}
labels:
heritage: {{.Release.Service}}
chartName: {{.Chart.Name}}
chartVersion: {{.Chart.Version | quote}}
annotations:
"helm.sh/created": "{{.Release.Time.Seconds}}"
spec:
restartPolicy: {{default "Never" .restart_policy}}
containers:
- name: waiter
image: "alpine:3.3"
command: ["/bin/sleep","9000"]
<?xml version="1.0"?>
<svg xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
version="1.0" width="256" height="256" id="test">
<desc>Example icon</desc>
<rect id="first" x="2" y="2" width="40" height="60" fill="navy"/>
<rect id="second" x="15" y="4" width="40" height="60" fill="red"/>
</svg>
dependencies:
- name: alpine
version: "0.1.0"
repository: https://example.com/charts
# A values file contains configuration.
name: "Some Name"
section:
name: "Name in a section"
Markdown is supported
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