diff --git a/cmd/helm/install.go b/cmd/helm/install.go index 3e8d04cb2..c8ddc0d99 100644 --- a/cmd/helm/install.go +++ b/cmd/helm/install.go @@ -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 diff --git a/internal/chart/chart.go b/internal/chart/chart.go new file mode 100644 index 000000000..4e10e6c13 --- /dev/null +++ b/internal/chart/chart.go @@ -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{}