From cd157656222c90e8396123b4e254125794064bec Mon Sep 17 00:00:00 2001 From: Christian Heike Date: Thu, 20 Jan 2022 13:52:54 +0100 Subject: [PATCH 1/2] Fix #808 --- api/v1alpha1/istiocontrolplane.pb.go | 2 +- api/v1alpha1/istiocontrolplane.pb.html | 2 +- api/v1alpha1/istiocontrolplane.proto | 2 +- config/crd/bases/istio-operator-crds.gen.yaml | 4 ++-- controllers/istiocontrolplane_controller.go | 2 +- controllers/meshgateway_controller.go | 2 +- controllers/version.go | 4 ++-- controllers/version_test.go | 22 +++++++++++++++++++ deploy/charts/istio-operator/Chart.yaml | 2 +- .../crds/istio-operator-crds.gen.yaml | 4 ++-- 10 files changed, 34 insertions(+), 12 deletions(-) create mode 100644 controllers/version_test.go diff --git a/api/v1alpha1/istiocontrolplane.pb.go b/api/v1alpha1/istiocontrolplane.pb.go index 2030b3134..41bf9d4a1 100644 --- a/api/v1alpha1/istiocontrolplane.pb.go +++ b/api/v1alpha1/istiocontrolplane.pb.go @@ -185,7 +185,7 @@ func (JWTPolicyType) EnumDescriptor() ([]byte, []int) { // --> type IstioControlPlaneSpec struct { // Contains the intended version for the Istio control plane. - // +kubebuilder:validation:Pattern=^1. + // +kubebuilder:validation:Pattern=^1\. Version string `protobuf:"bytes,1,opt,name=version,proto3" json:"version,omitempty"` // Configure the mode for this control plane. // Currently, two options are supported: "ACTIVE" and "PASSIVE". diff --git a/api/v1alpha1/istiocontrolplane.pb.html b/api/v1alpha1/istiocontrolplane.pb.html index 74bdc7495..7347f8187 100644 --- a/api/v1alpha1/istiocontrolplane.pb.html +++ b/api/v1alpha1/istiocontrolplane.pb.html @@ -25,7 +25,7 @@

IstioControlPlaneSpec

string

Contains the intended version for the Istio control plane. -+kubebuilder:validation:Pattern=^1.

++kubebuilder:validation:Pattern=^1\.

diff --git a/api/v1alpha1/istiocontrolplane.proto b/api/v1alpha1/istiocontrolplane.proto index a9f01b6e0..22f10fd7f 100644 --- a/api/v1alpha1/istiocontrolplane.proto +++ b/api/v1alpha1/istiocontrolplane.proto @@ -60,7 +60,7 @@ option go_package = "github.com/banzaicloud/istio-operator/v2/api/v1alpha1"; // --> message IstioControlPlaneSpec { // Contains the intended version for the Istio control plane. - // +kubebuilder:validation:Pattern=^1. + // +kubebuilder:validation:Pattern=^1\. string version = 1 [(google.api.field_behavior) = REQUIRED]; // Configure the mode for this control plane. // Currently, two options are supported: "ACTIVE" and "PASSIVE". diff --git a/config/crd/bases/istio-operator-crds.gen.yaml b/config/crd/bases/istio-operator-crds.gen.yaml index 1bd545257..b69dcce6e 100644 --- a/config/crd/bases/istio-operator-crds.gen.yaml +++ b/config/crd/bases/istio-operator-crds.gen.yaml @@ -6379,7 +6379,7 @@ spec: type: boolean type: object version: - pattern: ^1. + pattern: ^1\. type: string watchOneNamespace: nullable: true @@ -13704,7 +13704,7 @@ spec: type: boolean type: object version: - pattern: ^1. + pattern: ^1\. type: string watchOneNamespace: nullable: true diff --git a/controllers/istiocontrolplane_controller.go b/controllers/istiocontrolplane_controller.go index 13963b1ce..9aa8aa958 100644 --- a/controllers/istiocontrolplane_controller.go +++ b/controllers/istiocontrolplane_controller.go @@ -151,7 +151,7 @@ func (r *IstioControlPlaneReconciler) Reconcile(ctx context.Context, req ctrl.Re }, nil } - if !isIstioVersionSupported(icp.Spec.Version) { + if !IsIstioVersionSupported(icp.Spec.Version) { err = errors.New("intended Istio version is unsupported by this version of the operator") logger.Error(err, "", "version", icp.Spec.Version) diff --git a/controllers/meshgateway_controller.go b/controllers/meshgateway_controller.go index 9ff0912a2..d702b8983 100644 --- a/controllers/meshgateway_controller.go +++ b/controllers/meshgateway_controller.go @@ -103,7 +103,7 @@ func (r *IstioMeshGatewayReconciler) Reconcile(ctx context.Context, req ctrl.Req return ctrl.Result{}, err } - if !isIstioVersionSupported(icp.Spec.Version) { + if !IsIstioVersionSupported(icp.Spec.Version) { return ctrl.Result{}, nil } diff --git a/controllers/version.go b/controllers/version.go index 8d4c2d779..1b26ec43f 100644 --- a/controllers/version.go +++ b/controllers/version.go @@ -19,10 +19,10 @@ package controllers import "regexp" const ( - supportedIstioMinorVersionRegex = "^1.11" + supportedIstioMinorVersionRegex = "^1\\.11" ) -func isIstioVersionSupported(version string) bool { +func IsIstioVersionSupported(version string) bool { re, _ := regexp.Compile(supportedIstioMinorVersionRegex) return re.Match([]byte(version)) diff --git a/controllers/version_test.go b/controllers/version_test.go new file mode 100644 index 000000000..5bbd8a1dc --- /dev/null +++ b/controllers/version_test.go @@ -0,0 +1,22 @@ +package controllers_test + +import ( + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" + + "github.com/banzaicloud/istio-operator/v2/controllers" +) + +var _ = Describe("IsIstioVersionSupported()", func() { + It("should deny unsupported versions", func() { + Expect(controllers.IsIstioVersionSupported("2.1")).To(BeFalse()) + Expect(controllers.IsIstioVersionSupported("1.13")).To(BeFalse()) + Expect(controllers.IsIstioVersionSupported("1.13.1")).To(BeFalse()) + }) + It("should accept minor versions", func() { + Expect(controllers.IsIstioVersionSupported("1.11")).To(BeTrue()) + }) + It("should accept micro versions", func() { + Expect(controllers.IsIstioVersionSupported("1.11.1")).To(BeTrue()) + }) +}) diff --git a/deploy/charts/istio-operator/Chart.yaml b/deploy/charts/istio-operator/Chart.yaml index 7198ebb2c..608f1ed7f 100644 --- a/deploy/charts/istio-operator/Chart.yaml +++ b/deploy/charts/istio-operator/Chart.yaml @@ -11,5 +11,5 @@ icon: https://istio.io/latest/img/istio-whitelogo-bluebackground-framed.svg # Based on support status of Istio releases: https://istio.io/latest/docs/releases/supported-releases/#support-status-of-istio-releases kubeVersion: ">= 1.19.0-0 < 1.23.0-0" -version: 2.0.5 +version: 2.0.6 appVersion: "v2.11.5" diff --git a/deploy/charts/istio-operator/crds/istio-operator-crds.gen.yaml b/deploy/charts/istio-operator/crds/istio-operator-crds.gen.yaml index 1bd545257..b69dcce6e 100644 --- a/deploy/charts/istio-operator/crds/istio-operator-crds.gen.yaml +++ b/deploy/charts/istio-operator/crds/istio-operator-crds.gen.yaml @@ -6379,7 +6379,7 @@ spec: type: boolean type: object version: - pattern: ^1. + pattern: ^1\. type: string watchOneNamespace: nullable: true @@ -13704,7 +13704,7 @@ spec: type: boolean type: object version: - pattern: ^1. + pattern: ^1\. type: string watchOneNamespace: nullable: true From fdb042ffe9115b3de3534eebd8cea5b164ac4f02 Mon Sep 17 00:00:00 2001 From: Christian Heike Date: Fri, 21 Jan 2022 18:22:48 +0100 Subject: [PATCH 2/2] Changes from review --- controllers/version.go | 2 +- controllers/version_test.go | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/controllers/version.go b/controllers/version.go index 1b26ec43f..ac87b4f9e 100644 --- a/controllers/version.go +++ b/controllers/version.go @@ -19,7 +19,7 @@ package controllers import "regexp" const ( - supportedIstioMinorVersionRegex = "^1\\.11" + supportedIstioMinorVersionRegex = "^1\\.11(\\.[0-9]+)?(-.+)?$" ) func IsIstioVersionSupported(version string) bool { diff --git a/controllers/version_test.go b/controllers/version_test.go index 5bbd8a1dc..1b3727103 100644 --- a/controllers/version_test.go +++ b/controllers/version_test.go @@ -9,14 +9,20 @@ import ( var _ = Describe("IsIstioVersionSupported()", func() { It("should deny unsupported versions", func() { - Expect(controllers.IsIstioVersionSupported("2.1")).To(BeFalse()) - Expect(controllers.IsIstioVersionSupported("1.13")).To(BeFalse()) - Expect(controllers.IsIstioVersionSupported("1.13.1")).To(BeFalse()) + for _, version := range []string{"2.11", "2.11.1", "2.11.1-dev", "1.12", "1.12.1", "1.12.1-dev"} { + Expect(controllers.IsIstioVersionSupported(version)).To(BeFalse(), "invalid: "+version) + } }) - It("should accept minor versions", func() { + It("should accept all 1.11 versions", func() { Expect(controllers.IsIstioVersionSupported("1.11")).To(BeTrue()) }) + It("should accept all 1.11 versions with qualifier", func() { + Expect(controllers.IsIstioVersionSupported("1.11-dev")).To(BeTrue()) + }) It("should accept micro versions", func() { Expect(controllers.IsIstioVersionSupported("1.11.1")).To(BeTrue()) }) + It("should accept micro versions with qualifier", func() { + Expect(controllers.IsIstioVersionSupported("1.11.1-dev")).To(BeTrue()) + }) })