Updating checkIfInstallable to handle multiple chart apiVersions

Signed-off-by: Matt Farina <matt.farina@suse.com>
pull/30593/head
Matt Farina 7 months ago
parent 8602af9e92
commit 20b88c33cc
No known key found for this signature in database
GPG Key ID: 92C44A3D421FF7F9

@ -31,8 +31,9 @@ import (
"github.com/spf13/pflag"
"helm.sh/helm/v4/cmd/helm/require"
ichart "helm.sh/helm/v4/internal/chart"
"helm.sh/helm/v4/pkg/action"
chart "helm.sh/helm/v4/pkg/chart/v2"
chartv2 "helm.sh/helm/v4/pkg/chart/v2"
"helm.sh/helm/v4/pkg/chart/v2/loader"
"helm.sh/helm/v4/pkg/cli/output"
"helm.sh/helm/v4/pkg/cli/values"
@ -327,12 +328,21 @@ func runInstall(args []string, client *action.Install, valueOpts *values.Options
// checkIfInstallable validates if a chart can be installed
//
// Application chart type is only installable
func checkIfInstallable(ch *chart.Chart) error {
switch ch.Metadata.Type {
case "", "application":
return nil
func checkIfInstallable(ch ichart.Chart) error {
// In order to access nested structs (i.e., Metadata) you need to do type switches as generics
// do not provide a means to handle accessing these.
switch v := any(ch).(type) {
case *chartv2.Chart:
switch v.Metadata.Type {
case "", "application":
return nil
}
return errors.Errorf("%s charts are not installable", v.Metadata.Type)
default:
return errors.Errorf("chart type cannot be installed, type: %T\n", v)
}
return errors.Errorf("%s charts are not installable", ch.Metadata.Type)
}
// Provide dynamic auto-completion for the install and template commands

@ -0,0 +1,23 @@
/*
Copyright The Helm Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package chart
// Chart provides an interface between multiple types of charts.
//
// Chat provides a union between different Chart versions so that functions and generics can work
// with one type. Note, chart v2 handles apiVersion v1 and v2 charts.
// TODO(mattfarina): Add chart v3 here.
type Chart interface{}
Loading…
Cancel
Save