Only show CRDs for subcharts that are enabled in values

Process chart dependencies (as done in Install process) and only show
CRDs that would be included by default.

Signed-off-by: Tom Fenech <tomjwfenech@gmail.com>
pull/12156/head
Tom Fenech 2 years ago
parent 4e447d87cd
commit 5f5747f3f0

@ -137,6 +137,10 @@ func (s *Show) Run(chartpath string) (string, error) {
} }
if s.OutputFormat == ShowCRDs || s.OutputFormat == ShowAll { if s.OutputFormat == ShowCRDs || s.OutputFormat == ShowAll {
if err := chartutil.ProcessDependencies(s.chart, s.chart.Values); err != nil {
return "", errors.Wrap(err, "error processing chart dependencies")
}
crds := s.chart.CRDObjects() crds := s.chart.CRDObjects()
if len(crds) > 0 { if len(crds) > 0 {
if s.OutputFormat == ShowAll && !bytes.HasPrefix(crds[0].File.Data, []byte("---")) { if s.OutputFormat == ShowAll && !bytes.HasPrefix(crds[0].File.Data, []byte("---")) {

@ -122,6 +122,48 @@ bar
} }
} }
func TestShowCRDsDisabledSubchart(t *testing.T) {
client := NewShow(ShowCRDs)
client.chart = &chart.Chart{
Metadata: &chart.Metadata{Name: "alpine", Dependencies: []*chart.Dependency{
{Name: "enabledSubchart", Condition: "enabledSubchart.enabled"},
{Name: "disabledSubchart", Condition: "disabledSubchart.enabled"},
}},
Values: map[string]interface{}{
"enabledSubchart": map[string]interface{}{
"enabled": true,
},
"disabledSubchart": map[string]interface{}{
"enabled": false,
},
},
}
client.chart.SetDependencies(&chart.Chart{
Metadata: &chart.Metadata{Name: "enabledSubchart"},
Files: []*chart.File{
{Name: "crds/bar.yaml", Data: []byte("---\nbar\n")},
},
}, &chart.Chart{
Metadata: &chart.Metadata{Name: "disabledSubchart"},
Files: []*chart.File{
{Name: "crds/baz.yaml", Data: []byte("---\nbaz\n")},
},
})
output, err := client.Run("")
if err != nil {
t.Fatal(err)
}
expect := `---
bar
`
if output != expect {
t.Errorf("Expected\n%q\nGot\n%q\n", expect, output)
}
}
func TestShowNoReadme(t *testing.T) { func TestShowNoReadme(t *testing.T) {
client := NewShow(ShowAll) client := NewShow(ShowAll)
client.chart = &chart.Chart{ client.chart = &chart.Chart{

Loading…
Cancel
Save