From 87317b49a363d870842369d47d3ed1d66567d797 Mon Sep 17 00:00:00 2001 From: Chris Seto Date: Mon, 21 Oct 2024 10:17:48 -0400 Subject: [PATCH] default `chartVersion: ""` to go redpanda's version Prior to this commit `chartVersion` would default to the latest version of the redpanda chart available at the time the helm repository controller ran. This ended up being more confusing and possibly dangerous than it did being convenient. Our documentation has begun telling users to explicitly pin `chartVersion` themselves for stability. Additionally, such functionality complicated the incipient de-fluxing migration. To resolve the above, this commit has changed the behavior to instead default `chartVersion` to the version of the redpanda chart that's installed via the `go.mod` file. At the time of this commit, that version is 5.9.9. --- acceptance/go.mod | 2 +- acceptance/go.sum | 2 +- harpoon/go.mod | 2 +- harpoon/go.sum | 2 +- .../api/redpanda/v1alpha2/redpanda_types.go | 2 +- .../redpanda/v1alpha2/redpanda_types_test.go | 15 +++ .../bases/cluster.redpanda.com_redpandas.yaml | 4 +- operator/config/crd/bases/crds.go | 111 ++++++++++++++++++ operator/config/crd/bases/crds_test.go | 45 +++++++ .../crd/bases/redpanda_controller_test.go | 37 ------ operator/go.mod | 4 +- operator/go.sum | 4 +- .../redpanda/redpanda_controller.go | 53 ++++----- operator/internal/testutils/setup_envtest.go | 8 +- 14 files changed, 208 insertions(+), 83 deletions(-) create mode 100644 operator/config/crd/bases/crds.go create mode 100644 operator/config/crd/bases/crds_test.go delete mode 100644 operator/config/crd/bases/redpanda_controller_test.go diff --git a/acceptance/go.mod b/acceptance/go.mod index bbabd3654..719091213 100644 --- a/acceptance/go.mod +++ b/acceptance/go.mod @@ -6,7 +6,7 @@ require ( github.com/cucumber/godog v0.14.1 github.com/go-logr/logr v1.4.2 github.com/redpanda-data/common-go/rpadmin v0.1.7-0.20240916201938-8d748d9ac10b - github.com/redpanda-data/helm-charts v0.0.0-20241015140509-56e8cc7a5e8a + github.com/redpanda-data/helm-charts v0.0.0-20241025092026-69353dfce9a1 github.com/redpanda-data/redpanda-operator/harpoon v0.0.0-00010101000000-000000000000 github.com/redpanda-data/redpanda-operator/operator v0.0.0-00010101000000-000000000000 github.com/stretchr/testify v1.9.0 diff --git a/acceptance/go.sum b/acceptance/go.sum index 9f6df3ebd..828c9946b 100644 --- a/acceptance/go.sum +++ b/acceptance/go.sum @@ -641,7 +641,7 @@ github.com/redpanda-data/common-go/rpadmin v0.1.7-0.20240916201938-8d748d9ac10b github.com/redpanda-data/common-go/rpadmin v0.1.7-0.20240916201938-8d748d9ac10b/go.mod h1:I7umqhnMhIOSEnIA3fvLtdQU7QO/SbWGCwFfFDs3De4= github.com/redpanda-data/console/backend v0.0.0-20240303221210-05d5d9e85f20 h1:+zsE3W1V86k2sjAGWOySIlF0xn5R1aXXQBaIdr80F48= github.com/redpanda-data/console/backend v0.0.0-20240303221210-05d5d9e85f20/go.mod h1:DC42/3+k5PefSo4IalYbDN3yRZrVFP0b69+gC/NwGd4= -github.com/redpanda-data/helm-charts v0.0.0-20241015140509-56e8cc7a5e8a h1:kNx8tH6z02nJctZS+oYt7LOWWoZgfMW4Ktees89GTh0= +github.com/redpanda-data/helm-charts v0.0.0-20241025092026-69353dfce9a1 h1:Z1dclhzMIk83tZIa+aXqmojZZ2R03DvtXAfxWpWOqug= github.com/redpanda-data/redpanda/src/go/rpk v0.0.0-20240827155712-244863ea0ae8 h1:uTQKqF8UPNxYxKBJ11VlG6Vt2l9ctkkeXsmmjHUSUG4= github.com/redpanda-data/redpanda/src/go/rpk v0.0.0-20240827155712-244863ea0ae8/go.mod h1:97qkjcMI3gDL+y+aY/w5o0xF2qGHFof6rCXIYjnTalM= github.com/rhnvrm/simples3 v0.6.1/go.mod h1:Y+3vYm2V7Y4VijFoJHHTrja6OgPrJ2cBti8dPGkC3sA= diff --git a/harpoon/go.mod b/harpoon/go.mod index ca661f050..53229774c 100644 --- a/harpoon/go.mod +++ b/harpoon/go.mod @@ -6,7 +6,7 @@ require ( github.com/cucumber/godog v0.14.1 github.com/cucumber/messages/go/v21 v21.0.1 github.com/olekukonko/tablewriter v0.0.5 - github.com/redpanda-data/helm-charts v0.0.0-20241015140509-56e8cc7a5e8a + github.com/redpanda-data/helm-charts v0.0.0-20241025092026-69353dfce9a1 github.com/stretchr/testify v1.9.0 golang.org/x/exp v0.0.0-20240904232852-e7e105dedf7e k8s.io/api v0.30.3 diff --git a/harpoon/go.sum b/harpoon/go.sum index 486838361..3e73ae36c 100644 --- a/harpoon/go.sum +++ b/harpoon/go.sum @@ -401,7 +401,7 @@ github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsT github.com/prometheus/procfs v0.0.3/go.mod h1:4A/X28fw3Fc593LaREMrKMqOKvUAntwMDaekg4FpcdQ= github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0learggepc= github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk= -github.com/redpanda-data/helm-charts v0.0.0-20241015140509-56e8cc7a5e8a h1:kNx8tH6z02nJctZS+oYt7LOWWoZgfMW4Ktees89GTh0= +github.com/redpanda-data/helm-charts v0.0.0-20241025092026-69353dfce9a1 h1:Z1dclhzMIk83tZIa+aXqmojZZ2R03DvtXAfxWpWOqug= github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ= github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= diff --git a/operator/api/redpanda/v1alpha2/redpanda_types.go b/operator/api/redpanda/v1alpha2/redpanda_types.go index 5bbab2062..6e9005075 100644 --- a/operator/api/redpanda/v1alpha2/redpanda_types.go +++ b/operator/api/redpanda/v1alpha2/redpanda_types.go @@ -48,7 +48,7 @@ type ChartRef struct { // UseFlux flag set to `false` will prevent helm controller from reconciling helm chart. The operator would be // tight with `go` based Redpanda helm chart version. The rest of the ChartRef fields would be ignored. // - // Before setting UseFlux flag to `false` please alight your ChartVersion to at least `5.9.3` + // Before setting UseFlux flag to `false` please alight your ChartVersion to at least `5.9.9` // version of the Redpanda chart. // // RedpandaStatus might not be accurate if flag is set to `false` and HelmRelease is manually deleted. diff --git a/operator/api/redpanda/v1alpha2/redpanda_types_test.go b/operator/api/redpanda/v1alpha2/redpanda_types_test.go index b06650f7a..c4cfd923e 100644 --- a/operator/api/redpanda/v1alpha2/redpanda_types_test.go +++ b/operator/api/redpanda/v1alpha2/redpanda_types_test.go @@ -22,6 +22,7 @@ import ( "github.com/redpanda-data/helm-charts/charts/redpanda" "github.com/redpanda-data/redpanda-operator/operator/api/apiutil" "github.com/redpanda-data/redpanda-operator/operator/api/redpanda/v1alpha2" + crds "github.com/redpanda-data/redpanda-operator/operator/config/crd/bases" "github.com/redpanda-data/redpanda-operator/operator/internal/testutils" "github.com/stretchr/testify/require" corev1 "k8s.io/api/core/v1" @@ -64,6 +65,20 @@ var ( }) ) +func TestDefluxedMinimumVersion(t *testing.T) { + crd := crds.Redpanda() + // 0 is v1alpha1 and 1 is v1alpha2 + recursiveProperties := crd.Spec.Versions[1].Schema.OpenAPIV3Schema.Properties + + require.Containsf( + t, + recursiveProperties["spec"].Properties["chartRef"].Properties["useFlux"].Description, + redpanda.Chart.Metadata().Version, + "'useFlux' should reference the version %q of the go.mod installed redpanda chart. Do you need to run 'task generate' or update the comment?", + redpanda.Chart.Metadata().Version, + ) +} + // TestRedpanda_ValuesJSON asserts that .ValuesJSON appropriately coalesces the // value of CloudStorageEnabled into a boolean. // NOTE: This test is close to being a duplicate of apiutil.JSONBoolean's tests diff --git a/operator/config/crd/bases/cluster.redpanda.com_redpandas.yaml b/operator/config/crd/bases/cluster.redpanda.com_redpandas.yaml index aa57ebaaa..77f00f46f 100644 --- a/operator/config/crd/bases/cluster.redpanda.com_redpandas.yaml +++ b/operator/config/crd/bases/cluster.redpanda.com_redpandas.yaml @@ -118,7 +118,7 @@ spec: UseFlux flag set to `false` will prevent helm controller from reconciling helm chart. The operator would be tight with `go` based Redpanda helm chart version. The rest of the ChartRef fields would be ignored. - Before setting UseFlux flag to `false` please alight your ChartVersion to at least `5.9.3` + Before setting UseFlux flag to `false` please alight your ChartVersion to at least `5.9.9` version of the Redpanda chart. RedpandaStatus might not be accurate if flag is set to `false` and HelmRelease is manually deleted. @@ -9905,7 +9905,7 @@ spec: UseFlux flag set to `false` will prevent helm controller from reconciling helm chart. The operator would be tight with `go` based Redpanda helm chart version. The rest of the ChartRef fields would be ignored. - Before setting UseFlux flag to `false` please alight your ChartVersion to at least `5.9.3` + Before setting UseFlux flag to `false` please alight your ChartVersion to at least `5.9.9` version of the Redpanda chart. RedpandaStatus might not be accurate if flag is set to `false` and HelmRelease is manually deleted. diff --git a/operator/config/crd/bases/crds.go b/operator/config/crd/bases/crds.go new file mode 100644 index 000000000..334b0060e --- /dev/null +++ b/operator/config/crd/bases/crds.go @@ -0,0 +1,111 @@ +// Copyright 2024 Redpanda Data, Inc. +// +// Use of this software is governed by the Business Source License +// included in the file licenses/BSL.md +// +// As of the Change Date specified in that file, in accordance with +// the Business Source License, use of this software will be governed +// by the Apache License, Version 2.0 + +// Package crds provide programmatic access to the CRDs generated by +// controller-gen. +package crds + +import ( + "embed" + "io/fs" + + "github.com/cockroachdb/errors" + "github.com/redpanda-data/helm-charts/pkg/kube" + apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" + "k8s.io/apimachinery/pkg/runtime" +) + +var ( + //go:embed *.yaml + //go:embed toolkit.fluxcd.io/*.yaml + crdFS embed.FS + + crds []*apiextensionsv1.CustomResourceDefinition + byName map[string]*apiextensionsv1.CustomResourceDefinition +) + +func init() { + scheme := runtime.NewScheme() + must(apiextensionsv1.AddToScheme(scheme)) + + byName = map[string]*apiextensionsv1.CustomResourceDefinition{} + + must(fs.WalkDir(crdFS, ".", func(path string, d fs.DirEntry, err error) error { + if err != nil { + return err + } + + if d.IsDir() { + return nil + } + + data, err := fs.ReadFile(crdFS, path) + if err != nil { + return err + } + + objs, err := kube.DecodeYAML(data, scheme) + if err != nil { + return err + } + + for _, obj := range objs { + crd := obj.(*apiextensionsv1.CustomResourceDefinition) + + crds = append(crds, crd) + byName[crd.Name] = crd + } + + return nil + })) +} + +func ByName(name string) (*apiextensionsv1.CustomResourceDefinition, error) { + crd, ok := byName[name] + if !ok { + return nil, errors.Newf("no such CRD %q", name) + } + return crd, nil +} + +func All() []*apiextensionsv1.CustomResourceDefinition { + ret := make([]*apiextensionsv1.CustomResourceDefinition, len(crds)) + + for i, crd := range crds { + ret[i] = crd.DeepCopy() + } + + return ret +} + +// Redpanda returns the Redpanda CustomResourceDefinition. +func Redpanda() *apiextensionsv1.CustomResourceDefinition { + return mustT(ByName("redpandas.cluster.redpanda.com")) +} + +// Topic returns the Redpanda CustomResourceDefinition. +func Topic() *apiextensionsv1.CustomResourceDefinition { + return mustT(ByName("topics.cluster.redpanda.com")) +} + +// Topic returns the Redpanda CustomResourceDefinition. +func User() *apiextensionsv1.CustomResourceDefinition { + return mustT(ByName("users.cluster.redpanda.com")) +} + +func mustT[T any](r T, err error) T { + must(err) + return r +} + +func must(err error) { + if err != nil { + panic(err) + } +} diff --git a/operator/config/crd/bases/crds_test.go b/operator/config/crd/bases/crds_test.go new file mode 100644 index 000000000..9ba5af97e --- /dev/null +++ b/operator/config/crd/bases/crds_test.go @@ -0,0 +1,45 @@ +// Copyright 2024 Redpanda Data, Inc. +// +// Use of this software is governed by the Business Source License +// included in the file licenses/BSL.md +// +// As of the Change Date specified in that file, in accordance with +// the Business Source License, use of this software will be governed +// by the Apache License, Version 2.0 + +package crds_test + +import ( + "testing" + + crds "github.com/redpanda-data/redpanda-operator/operator/config/crd/bases" + "github.com/stretchr/testify/require" +) + +func TestCRDS(t *testing.T) { + names := map[string]struct{}{ + "buckets.source.toolkit.fluxcd.io": {}, + "clusters.redpanda.vectorized.io": {}, + "consoles.redpanda.vectorized.io": {}, + "gitrepositories.source.toolkit.fluxcd.io": {}, + "helmcharts.source.toolkit.fluxcd.io": {}, + "helmreleases.helm.toolkit.fluxcd.io": {}, + "helmrepositories.source.toolkit.fluxcd.io": {}, + "ocirepositories.source.toolkit.fluxcd.io": {}, + "redpandas.cluster.redpanda.com": {}, + "schemas.cluster.redpanda.com": {}, + "topics.cluster.redpanda.com": {}, + "users.cluster.redpanda.com": {}, + } + + foundNames := map[string]struct{}{} + for _, crd := range crds.All() { + foundNames[crd.Name] = struct{}{} + } + + require.Equal(t, names, foundNames) + + require.Equal(t, "redpandas.cluster.redpanda.com", crds.Redpanda().Name) + require.Equal(t, "topics.cluster.redpanda.com", crds.Topic().Name) + require.Equal(t, "users.cluster.redpanda.com", crds.User().Name) +} diff --git a/operator/config/crd/bases/redpanda_controller_test.go b/operator/config/crd/bases/redpanda_controller_test.go deleted file mode 100644 index 5c6efa269..000000000 --- a/operator/config/crd/bases/redpanda_controller_test.go +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright 2024 Redpanda Data, Inc. -// -// Use of this software is governed by the Business Source License -// included in the file licenses/BSL.md -// -// As of the Change Date specified in that file, in accordance with -// the Business Source License, use of this software will be governed -// by the Apache License, Version 2.0 - -package redpanda - -import ( - _ "embed" - "encoding/json" - "testing" - - "github.com/redpanda-data/redpanda-operator/operator/internal/controller/redpanda" - "github.com/stretchr/testify/require" - v1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" - "k8s.io/apimachinery/pkg/util/yaml" -) - -//go:embed cluster.redpanda.com_redpandas.yaml -var redpandaCRD []byte - -func TestDefluxedMinimumVersion(t *testing.T) { - crd := v1.CustomResourceDefinition{} - - red, err := yaml.ToJSON(redpandaCRD) - require.NoError(t, err) - - require.NoError(t, json.Unmarshal(red, &crd)) - // 0 is v1alpha1 and 1 is v1alpha2 - recursiveProperties := crd.Spec.Versions[1].Schema.OpenAPIV3Schema.Properties - - require.Contains(t, recursiveProperties["spec"].Properties["chartRef"].Properties["useFlux"].Description, redpanda.HelmChartConstraint) -} diff --git a/operator/go.mod b/operator/go.mod index c64541bcc..9b24faba6 100644 --- a/operator/go.mod +++ b/operator/go.mod @@ -8,6 +8,7 @@ require ( github.com/cert-manager/cert-manager v1.14.5 github.com/cisco-open/k8s-objectmatcher v1.9.0 github.com/cloudhut/common v0.10.0 + github.com/cockroachdb/errors v1.11.1 github.com/distribution/reference v0.6.0 github.com/fluxcd/helm-controller/api v0.37.2 github.com/fluxcd/helm-controller/shim v0.0.0-00010101000000-000000000000 @@ -27,7 +28,7 @@ require ( github.com/prometheus/common v0.55.0 github.com/redpanda-data/common-go/rpadmin v0.1.7-0.20240916201938-8d748d9ac10b github.com/redpanda-data/console/backend v0.0.0-20240303221210-05d5d9e85f20 - github.com/redpanda-data/helm-charts v0.0.0-20241015140509-56e8cc7a5e8a + github.com/redpanda-data/helm-charts v0.0.0-20241025092026-69353dfce9a1 github.com/redpanda-data/redpanda/src/go/rpk v0.0.0-20240827155712-244863ea0ae8 github.com/scalalang2/golang-fifo v1.0.2 github.com/spf13/afero v1.11.0 @@ -138,7 +139,6 @@ require ( github.com/chrismellard/docker-credential-acr-env v0.0.0-20230304212654-82a0ddb27589 // indirect github.com/clbanning/mxj/v2 v2.7.0 // indirect github.com/cloudflare/circl v1.3.7 // indirect - github.com/cockroachdb/errors v1.11.1 // indirect github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b // indirect github.com/cockroachdb/redact v1.1.5 // indirect github.com/common-nighthawk/go-figure v0.0.0-20210622060536-734e95fb86be // indirect diff --git a/operator/go.sum b/operator/go.sum index 1101b87b1..c219be5d6 100644 --- a/operator/go.sum +++ b/operator/go.sum @@ -1093,8 +1093,8 @@ github.com/redpanda-data/flux-controller-shim/helm/shim v0.0.0-20231227162419-a4 github.com/redpanda-data/flux-controller-shim/helm/shim v0.0.0-20231227162419-a45126310240/go.mod h1:5KLXArOMFOrwb3BihpFaRNiPCyo9AXsXhvMdUmrCdUg= github.com/redpanda-data/flux-controller-shim/source/shim v0.0.0-20240113100428-5e301ef97b19 h1:sJjDhnIbTMOuP4Rnhm1N3GNfgv6BJlocCnGliNvhgbw= github.com/redpanda-data/flux-controller-shim/source/shim v0.0.0-20240113100428-5e301ef97b19/go.mod h1:T39OECA7eOlhpHZPBSGg+bpuwtt/G4m03fjBkJ821CM= -github.com/redpanda-data/helm-charts v0.0.0-20241015140509-56e8cc7a5e8a h1:kNx8tH6z02nJctZS+oYt7LOWWoZgfMW4Ktees89GTh0= -github.com/redpanda-data/helm-charts v0.0.0-20241015140509-56e8cc7a5e8a/go.mod h1:TqCaTv9K8+VbAeZHlR/OqHVksTlj0HYAzDkUEtZNyZc= +github.com/redpanda-data/helm-charts v0.0.0-20241025092026-69353dfce9a1 h1:Z1dclhzMIk83tZIa+aXqmojZZ2R03DvtXAfxWpWOqug= +github.com/redpanda-data/helm-charts v0.0.0-20241025092026-69353dfce9a1/go.mod h1:dmmGZo7DuHNnCy0QOykXN2sY9QI8kbdlkSKgIkCT978= github.com/redpanda-data/helm-controller v0.37.3-0.20240119022335-c90fadbd044e h1:8HB05vSCY+0MwjT2DIVq6gJV5iw7nQNIDfMqcc1NEC8= github.com/redpanda-data/helm-controller v0.37.3-0.20240119022335-c90fadbd044e/go.mod h1:jF5kbQy3qT/zufL27DE3lecfYTRWeAzSiVmrbDDQwUw= github.com/redpanda-data/redpanda/src/go/rpk v0.0.0-20240827155712-244863ea0ae8 h1:uTQKqF8UPNxYxKBJ11VlG6Vt2l9ctkkeXsmmjHUSUG4= diff --git a/operator/internal/controller/redpanda/redpanda_controller.go b/operator/internal/controller/redpanda/redpanda_controller.go index 34a5c76de..6f6476f64 100644 --- a/operator/internal/controller/redpanda/redpanda_controller.go +++ b/operator/internal/controller/redpanda/redpanda_controller.go @@ -20,7 +20,6 @@ import ( "strings" "time" - "github.com/Masterminds/semver/v3" helmv2beta1 "github.com/fluxcd/helm-controller/api/v2beta1" helmv2beta2 "github.com/fluxcd/helm-controller/api/v2beta2" "github.com/fluxcd/pkg/apis/meta" @@ -40,6 +39,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" "sigs.k8s.io/controller-runtime/pkg/predicate" + "github.com/redpanda-data/helm-charts/charts/redpanda" "github.com/redpanda-data/redpanda-operator/operator/api/redpanda/v1alpha2" "github.com/redpanda-data/redpanda-operator/operator/pkg/resources" ) @@ -59,8 +59,6 @@ const ( revisionPath = "/revision" componentLabelValue = "redpanda-statefulset" - - HelmChartConstraint = "5.9.3" ) var errWaitForReleaseDeletion = errors.New("wait for helm release deletion") @@ -236,38 +234,28 @@ func (r *RedpandaReconciler) reconcileDefluxed(ctx context.Context, rp *v1alpha2 log := ctrl.LoggerFrom(ctx) log.WithName("RedpandaReconciler.reconcileDefluxed") - if !ptr.Deref(rp.Spec.ChartRef.UseFlux, true) { - // TODO (Rafal) Implement Redpanda helm chart templating with Redpanda Status Report - // In the Redpanda.Status there will be only Conditions and Failures that would be used. - - if !atLeast(rp.Spec.ChartRef.ChartVersion) { - log.Error(fmt.Errorf("chart version needs to be at least %s", HelmChartConstraint), "", "chart version", rp.Spec.ChartRef.ChartVersion) - v1alpha2.RedpandaNotReady(rp, "ChartRefUnsupported", fmt.Sprintf("chart version needs to be at least %s. Currently it is %s", HelmChartConstraint, rp.Spec.ChartRef.ChartVersion)) - r.EventRecorder.Eventf(rp, "Warning", v1alpha2.EventSeverityError, fmt.Sprintf("chart version needs to be at least %s. Currently it is %s", HelmChartConstraint, rp.Spec.ChartRef.ChartVersion)) - // Do not error out to not requeue. User needs to first migrate helm release to at least 5.9.3 version - return nil - } + if ptr.Deref(rp.Spec.ChartRef.UseFlux, true) { + log.Info("useFlux is true; skipping non-flux reconciliation...") + return nil } - return nil -} -func atLeast(version string) bool { - if version == "" { - return true - } + chartVersion := rp.Spec.ChartRef.ChartVersion + desiredChartVersion := redpanda.Chart.Metadata().Version - c, err := semver.NewConstraint(fmt.Sprintf(">= %s", HelmChartConstraint)) - if err != nil { - // Handle constraint not being parsable. - return false - } + if !(chartVersion == "" || chartVersion == desiredChartVersion) { + msg := fmt.Sprintf(".spec.chartRef.chartVersion version needs to be %q or %q. got %q", desiredChartVersion, "", chartVersion) - v, err := semver.NewVersion(version) - if err != nil { - return false + // NB: passing `nil` as err is acceptable for log.Error. + log.Error(nil, msg, "chart version", rp.Spec.ChartRef.ChartVersion) + r.EventRecorder.Eventf(rp, "Warning", v1alpha2.EventSeverityError, msg) + + v1alpha2.RedpandaNotReady(rp, "ChartRefUnsupported", msg) + + // Do not error out to not requeue. User needs to first migrate helm release to either "" or the pinned chart's version. + return nil } - return c.Check(v) + return nil } func (r *RedpandaReconciler) reconcile(ctx context.Context, rp *v1alpha2.Redpanda) (*v1alpha2.Redpanda, error) { @@ -426,6 +414,11 @@ func (r *RedpandaReconciler) createHelmReleaseFromTemplate(ctx context.Context, timeout = &metav1.Duration{Duration: 15 * time.Minute} } + chartVersion := rp.Spec.ChartRef.ChartVersion + if chartVersion == "" { + chartVersion = redpanda.Chart.Metadata().Version + } + upgrade := &helmv2beta2.Upgrade{ // we skip waiting since relying on the Helm release process // to actually happen means that we block running any sort @@ -461,7 +454,7 @@ func (r *RedpandaReconciler) createHelmReleaseFromTemplate(ctx context.Context, Chart: helmv2beta2.HelmChartTemplate{ Spec: helmv2beta2.HelmChartTemplateSpec{ Chart: "redpanda", - Version: rp.Spec.ChartRef.ChartVersion, + Version: chartVersion, Interval: &metav1.Duration{Duration: 1 * time.Minute}, SourceRef: helmv2beta2.CrossNamespaceObjectReference{ Kind: "HelmRepository", diff --git a/operator/internal/testutils/setup_envtest.go b/operator/internal/testutils/setup_envtest.go index d5a2a0cf3..d2c2e2288 100644 --- a/operator/internal/testutils/setup_envtest.go +++ b/operator/internal/testutils/setup_envtest.go @@ -17,6 +17,7 @@ import ( "runtime" "strings" + crds "github.com/redpanda-data/redpanda-operator/operator/config/crd/bases" "k8s.io/client-go/rest" "sigs.k8s.io/controller-runtime/pkg/envtest" ) @@ -34,11 +35,8 @@ func (e *RedpandaTestEnv) StartRedpandaTestEnv(withWebhook bool) (*rest.Config, return nil, fmt.Errorf("unable to lookup path of calling function: %w", err) } - e.CRDDirectoryPaths = []string{ - filepath.Join(configPath, "crd", "bases"), - filepath.Join(configPath, "crd", "bases", "toolkit.fluxcd.io"), - } - e.ErrorIfCRDPathMissing = true + e.CRDInstallOptions.CRDs = crds.All() + if withWebhook { e.WebhookInstallOptions = envtest.WebhookInstallOptions{ Paths: []string{filepath.Join(configPath, "webhook")},