From 46c56c99d9a86cdbb50646247e415d6a68dd144e Mon Sep 17 00:00:00 2001 From: nicolaferraro Date: Mon, 4 Apr 2022 12:36:35 +0200 Subject: [PATCH] operator: add feature gate for maintenance mode --- .../featuregates/centralized_configuration.go | 2 +- .../k8s/pkg/resources/featuregates/common.go | 14 ++++++++ .../featuregates/maintenance_mode.go | 32 +++++++++++++++++++ 3 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 src/go/k8s/pkg/resources/featuregates/common.go create mode 100644 src/go/k8s/pkg/resources/featuregates/maintenance_mode.go diff --git a/src/go/k8s/pkg/resources/featuregates/centralized_configuration.go b/src/go/k8s/pkg/resources/featuregates/centralized_configuration.go index 56a1b14c56d9..61193916edee 100644 --- a/src/go/k8s/pkg/resources/featuregates/centralized_configuration.go +++ b/src/go/k8s/pkg/resources/featuregates/centralized_configuration.go @@ -19,7 +19,7 @@ const ( // CentralizedConfiguration feature gate should be removed when the operator // will no longer support 21.x or older versions func CentralizedConfiguration(version string) bool { - if version == "dev" { + if version == devVersion { // development version contains this feature return true } diff --git a/src/go/k8s/pkg/resources/featuregates/common.go b/src/go/k8s/pkg/resources/featuregates/common.go new file mode 100644 index 000000000000..f763da157730 --- /dev/null +++ b/src/go/k8s/pkg/resources/featuregates/common.go @@ -0,0 +1,14 @@ +// Copyright 2022 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 featuregates + +const ( + devVersion = "dev" +) diff --git a/src/go/k8s/pkg/resources/featuregates/maintenance_mode.go b/src/go/k8s/pkg/resources/featuregates/maintenance_mode.go new file mode 100644 index 000000000000..f6f6fe93db3a --- /dev/null +++ b/src/go/k8s/pkg/resources/featuregates/maintenance_mode.go @@ -0,0 +1,32 @@ +// Copyright 2022 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 featuregates + +import "github.com/Masterminds/semver/v3" + +const ( + maintenanceModeMajor = uint64(22) + maintenanceModeMinor = uint64(1) +) + +// MaintenanceMode feature gate should be removed when the operator +// will no longer support 21.x or older versions +func MaintenanceMode(version string) bool { + if version == devVersion { + // development version contains this feature + return true + } + v, err := semver.NewVersion(version) + if err != nil { + return false + } + + return v.Major() == maintenanceModeMajor && v.Minor() >= maintenanceModeMinor || v.Major() > maintenanceModeMajor +}