fix(pkg/chart): do not install CRDs for disabled dependencies

Signed-off-by: Marton Waszlavik <marton.waszlavik@gmail.com>
pull/9007/head
Marton Waszlavik 5 years ago
parent a6c58b6cf8
commit aa9a517796

@ -181,17 +181,6 @@ func (i *Install) Run(chrt *chart.Chart, vals map[string]interface{}) (*release.
return nil, err
}
// Pre-install anything in the crd/ directory. We do this before Helm
// contacts the upstream server and builds the capabilities object.
if crds := chrt.CRDObjects(); !i.ClientOnly && !i.SkipCRDs && len(crds) > 0 {
// On dry run, bail here
if i.DryRun {
i.cfg.Log("WARNING: This chart or one of its subcharts contains CRDs. Rendering may fail or contain inaccuracies.")
} else if err := i.installCRDs(crds); err != nil {
return nil, err
}
}
if i.ClientOnly {
// Add mock objects in here so it doesn't use Kube API server
// NOTE(bacongobbler): used for `helm template`
@ -210,6 +199,17 @@ func (i *Install) Run(chrt *chart.Chart, vals map[string]interface{}) (*release.
return nil, err
}
// Pre-install anything in the crd/ directory. We do this before Helm
// contacts the upstream server and builds the capabilities object.
if crds := chrt.CRDObjects(); !i.ClientOnly && !i.SkipCRDs && len(crds) > 0 {
// On dry run, bail here
if i.DryRun {
i.cfg.Log("WARNING: This chart or one of its subcharts contains CRDs. Rendering may fail or contain inaccuracies.")
} else if err := i.installCRDs(crds); err != nil {
return nil, err
}
}
// Make sure if Atomic is set, that wait is set as well. This makes it so
// the user doesn't have to specify both
i.Wait = i.Wait || i.Atomic

@ -162,7 +162,11 @@ func (ch *Chart) CRDObjects() []CRD {
}
// Get CRDs from dependencies, too.
for _, dep := range ch.Dependencies() {
crds = append(crds, dep.CRDObjects()...)
for _, req := range ch.Metadata.Dependencies {
if dep.Name() == req.Name && req.Enabled {
crds = append(crds, dep.CRDObjects()...)
}
}
}
return crds
}

@ -209,3 +209,81 @@ func TestCRDObjects(t *testing.T) {
crds := chrt.CRDObjects()
is.Equal(expected, crds)
}
func TestCRDObjectsWithDependecy(t *testing.T) {
chrt := createTestChartWithCrdAndDependency(true)
expected := []CRD{
{
Name: "crds/foo.yaml",
Filename: "crds/foo.yaml",
File: &File{
Name: "crds/foo.yaml",
Data: []byte("hello"),
},
},
{
Name: "crds/baz.yaml",
Filename: "dependency1/crds/baz.yaml",
File: &File{
Name: "crds/baz.yaml",
Data: []byte("hello"),
},
},
}
is := assert.New(t)
crds := chrt.CRDObjects()
is.Equal(expected, crds)
}
func TestCRDObjectsWithDependecyDisabled(t *testing.T) {
chrt := createTestChartWithCrdAndDependency(false)
expected := []CRD{
{
Name: "crds/foo.yaml",
Filename: "crds/foo.yaml",
File: &File{
Name: "crds/foo.yaml",
Data: []byte("hello"),
},
},
}
is := assert.New(t)
crds := chrt.CRDObjects()
is.Equal(expected, crds)
}
func createTestChartWithCrdAndDependency(dependencyEnabled bool) Chart {
chrt := Chart{
Files: []*File{
{
Name: "crds/foo.yaml",
Data: []byte("hello"),
},
},
dependencies: []*Chart{
{
Metadata: &Metadata{
Name: "dependency1",
},
Files: []*File{
{
Name: "crds/baz.yaml",
Data: []byte("hello"),
},
},
},
},
Metadata: &Metadata{
Dependencies: []*Dependency{
{
Name: "dependency1",
Enabled: dependencyEnabled,
},
},
},
}
return chrt
}

Loading…
Cancel
Save