From d87ab6faa7933756196d53083e39b65d4d4282c4 Mon Sep 17 00:00:00 2001 From: "Adam D. Cornett" Date: Tue, 5 Nov 2024 14:31:11 -0700 Subject: [PATCH] adding hasDifferentAPIVersion method directly for helm plugin, since this has been removed from kubebuilder and is probably still needed for helm Signed-off-by: Adam D. Cornett --- internal/plugins/helm/v1/api.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/internal/plugins/helm/v1/api.go b/internal/plugins/helm/v1/api.go index 128db5530d..696d7bcca0 100644 --- a/internal/plugins/helm/v1/api.go +++ b/internal/plugins/helm/v1/api.go @@ -203,6 +203,12 @@ func (p *createAPISubcommand) InjectResource(res *resource.Resource) error { return fmt.Errorf("multiple groups are not allowed by default, to enable multi-group set 'multigroup: true' in your PROJECT file") } + // Selected CRD version must match existing CRD versions. + // nolint:staticcheck + if hasDifferentAPIVersion(p.config.ListCRDVersions(), p.resource.API.CRDVersion) { + return fmt.Errorf("only one CRD version can be used for all resources, cannot add %q", p.resource.API.CRDVersion) + } + return nil } @@ -223,3 +229,8 @@ func (p *createAPISubcommand) Scaffold(fs machinery.Filesystem) error { return nil } + +// hasDifferentCRDVersion returns true if any other CRD version is tracked in the project configuration. +func hasDifferentAPIVersion(versions []string, version string) bool { + return !(len(versions) == 0 || (len(versions) == 1 && versions[0] == version)) +}