From 007f45ebbdd06554fc7d936decfc8a642cdedce2 Mon Sep 17 00:00:00 2001 From: Srishti Thakkar Date: Tue, 6 Jul 2021 18:08:41 +0530 Subject: [PATCH] Issue 149: Removing supported versions configmap (#151) * Issue 149: Removing supported versions configmap Signed-off-by: SrishT * Issue 149: Adding check to prevent downgrades Signed-off-by: SrishT * Issue 149: Adding unit and e2e tests Signed-off-by: SrishT * Issue 149: Modifying e2e Signed-off-by: SrishT * Issue 149: Testing Signed-off-by: SrishT * Issue 149: Testing Signed-off-by: SrishT * Issue 149: Minor changes Signed-off-by: SrishT * Issue 149: Updating documentation Signed-off-by: SrishT * Issue 149: Updating documentation Signed-off-by: SrishT * Issue 149: Adding version map for backward compatibility Signed-off-by: SrishT * ISsue 149: Fixing typo Signed-off-by: SrishT Co-authored-by: SrishT --- deploy/version_map.yaml | 1 + doc/manual-installation.md | 17 +-- doc/operator-upgrade.md | 4 - doc/troubleshooting.md | 40 ------ doc/upgrade-cluster.md | 3 +- .../v1alpha1/bookkeepercluster_types.go | 51 ++----- .../v1alpha1/bookkeepercluster_types_test.go | 126 ++++++------------ test/e2e/webhook_test.go | 21 +-- 8 files changed, 62 insertions(+), 201 deletions(-) diff --git a/deploy/version_map.yaml b/deploy/version_map.yaml index 6a7b1ac7..2b5ce225 100644 --- a/deploy/version_map.yaml +++ b/deploy/version_map.yaml @@ -1,3 +1,4 @@ +# this file is deprecated and will be removed in future releases kind: ConfigMap apiVersion: v1 metadata: diff --git a/doc/manual-installation.md b/doc/manual-installation.md index 0f5de511..b85be30d 100644 --- a/doc/manual-installation.md +++ b/doc/manual-installation.md @@ -10,7 +10,7 @@ > Note: If you are running on Google Kubernetes Engine (GKE), please [check this first](#installation-on-google-kubernetes-engine). -In case you dont have a cert-manager, Install the cert-manager v0.15.0+ from the following link:- +In case you don't have a cert-manager, Install the cert-manager v0.15.0+ from the following link:- https://cert-manager.io/docs/installation/kubernetes/ @@ -43,12 +43,6 @@ Install the operator. $ kubectl create -f deploy/operator.yaml ``` -Finally create a ConfigMap which contains the list of supported upgrade paths for the Bookkeeper cluster. - -``` -$ kubectl create -f deploy/version_map.yaml -``` - #### Install the Operator in Test Mode The operator can be deployed in `test mode` by providing the argument `-test` inside the `operator.yaml` file in the following way. @@ -64,16 +58,15 @@ containers: imagePullPolicy: Always args: [-test] ``` -For more details check [this](../README.md#install-the-operator-in-test-mode) ### Install the Bookkeeper cluster manually > Note: the Bookkeeper cluster must be installed in the same namespace as the Zookeeper cluster. -If the BookKeeper cluster is expected to work with Pravega, we need to create a ConfigMap which needs to have the following values +If the Bookkeeper cluster is expected to work with Pravega, we need to create a ConfigMap which needs to have the following values | KEY | VALUE | |---|---| -| *PRAVEGA_CLUSTER_NAME* | Name of Pravega Cluster using this BookKeeper Cluster | +| *PRAVEGA_CLUSTER_NAME* | Name of the Pravega Cluster using this Bookkeeper Cluster | | *WAIT_FOR* | Zookeeper URL | To create this ConfigMap, use the following command: @@ -82,7 +75,7 @@ To create this ConfigMap, use the following command: $ kubectl create -f deploy/config_map.yaml ``` -The name of this ConfigMap needs to be mentioned in the field `envVars` present in the BookKeeper Spec. For more details about this ConfigMap refer to [this](bookkeeper-options.md#bookkeeper-custom-configuration). +The name of this ConfigMap needs to be mentioned in the field `envVars` present in the Bookkeeper Spec. For more details about this ConfigMap refer to [this](bookkeeper-options.md#bookkeeper-custom-configuration). Once all these have been installed, you can use the following YAML template to install a small development Bookkeeper Cluster. Create a `bookkeeper.yaml` file with the following content. @@ -106,7 +99,7 @@ where: - `[ZOOKEEPER_HOST]` is the Zookeeper service endpoint of your Zookeeper deployment (e.g. `zookeeper-client:2181`). It expects the zookeeper service URL in the given format `:` -Check out other sample CR files in the [`example`](../example) directory. +Check out other sample CR files in the [example](../example) directory. Deploy the Bookkeeper cluster. diff --git a/doc/operator-upgrade.md b/doc/operator-upgrade.md index a0508eee..9bd42e82 100644 --- a/doc/operator-upgrade.md +++ b/doc/operator-upgrade.md @@ -7,10 +7,6 @@ Bookkeeper operator can be upgraded to a version **[VERSION]** via helm using th ``` $ helm upgrade [BOOKKEEPER_OPERATOR_RELEASE_NAME] pravega/bookkeeper-operator --version=[VERSION] ``` -The bookkeeper operator with deployment name **[DEPLOYMENT_NAME]** can also be upgraded manually by modifying the image tag using kubectl edit, patch or apply -``` -$ kubectl edit deploy [DEPLOYMENT_NAME] -``` ## Upgrading to 0.1.3 diff --git a/doc/troubleshooting.md b/doc/troubleshooting.md index a2c01e34..321a5e49 100644 --- a/doc/troubleshooting.md +++ b/doc/troubleshooting.md @@ -3,8 +3,6 @@ ## Bookkeeper Cluster Issues * [Certificate Error: Internal error occurred: failed calling webhook](#certificate-error-internal-error-occurred-failed-calling-webhook) -* [Unsupported Bookkeeper cluster version](#unsupported-bookkeeper-cluster-version) -* [Unsupported upgrade from version](#unsupported-upgrade-from-version) * [Invalid Cookie Exception](#invalid-cookie-exception) * [Unrecognized VM option](#unrecognized-vm-option) @@ -20,44 +18,6 @@ Error: Post https://bookkeeper-webhook-svc.default.svc:443/validate-bookkeeper-p ``` We need to ensure that certificates are installed before installing the operator. Please refer [prerequisite](../charts/bookkeeper-operator/README.md#Prerequisites) -## Unsupported Bookkeeper cluster version - -While installing pravega, if we get the below error -``` -Error: admission webhook "bookkeeperwebhook.pravega.io" denied the request: unsupported Bookkeeper cluster version 0.10.0-2703.c9b7be114 -``` -We need to make sure the supported versions are present in config map by the following command - -`kubectl describe cm bk-supported-versions-map` - -If the entries are not there in configmap, we have to add these options in the configmap by enabling test mode as follows while installing operator - -``` -helm install bookkeeper-operator charts/bookkeeper-operator --set testmode.enabled=true --set testmode.version="0.10.0" -``` - -Alternatively, we can edit the configmap and add entry as `0.10.0:0.10.0` in the configmap and restart the bookkeeper-operator pod - -## Unsupported upgrade from version - -While upgrading bookkeeper, if we get the error similar to below - -``` -Error from server (unsupported upgrade from version 0.8.0-2640.e4c436ba9 to 0.9.0-2752.2652549b3): error when applying patch -``` -We need to make sure that supported versions are present in configmap as `0.8.0:0.9.0`. If the entries are missing, we have to add these options in the configmap by enabling test mode as follows while installing Operator - -If the version from which we are triggering upgrade is present in configmap, use the below command. -``` -helm install bookkeeper-operator charts/bookkeeper-operator --set testmode.enabled=true --set testmode.version="0.9.0" -``` -If the version from which we are triggering upgrade and the version to which upgrade is performed are not present in configmap use the below command. - -``` -helm install bookkeeper-operator charts/bookkeeper-operator --set testmode.enabled=true --set testmode.fromVersion="0.8.0" --set testmode.version="0.9.0" -``` -Alternatively, we can edit the configmap and add entry as `0.8.0:0.8.0,0.9.0` in the configmap and restart the bookkeeper-operator pod - ## Invalid Cookie Exception While installing bookkeeper, if the pods are not coming to ready state `1/1` and in the bookie logs if the error messages are seen as below, diff --git a/doc/upgrade-cluster.md b/doc/upgrade-cluster.md index d1bc4794..e302f482 100644 --- a/doc/upgrade-cluster.md +++ b/doc/upgrade-cluster.md @@ -20,8 +20,7 @@ bookkeeper 0.4.0 7 7 11m ``` ## Valid Upgrade Paths - -To understand the valid upgrade paths for a bookkeeper cluster, refer to the [version map](https://github.com/pravega/bookkeeper-operator/blob/master/deploy/version_map.yaml). The key indicates the base version of the cluster, and the value against each key indicates the list of valid versions this base version can be upgraded to. +Upgrade of bookkeeper cluster to any version will be allowed as long as the user does not try to downgrade the cluster version. ## Trigger an upgrade diff --git a/pkg/apis/bookkeeper/v1alpha1/bookkeepercluster_types.go b/pkg/apis/bookkeeper/v1alpha1/bookkeepercluster_types.go index 4c1c0b43..b5e9e30a 100644 --- a/pkg/apis/bookkeeper/v1alpha1/bookkeepercluster_types.go +++ b/pkg/apis/bookkeeper/v1alpha1/bookkeepercluster_types.go @@ -11,7 +11,6 @@ package v1alpha1 import ( - "bufio" "context" "fmt" "log" @@ -558,7 +557,7 @@ func (bk *BookkeeperCluster) SetupWebhookWithManager(mgr ctrl.Manager) error { // ValidateCreate implements webhook.Validator so a webhook will be registered for the type func (bk *BookkeeperCluster) ValidateCreate() error { log.Printf("validate create %s", bk.Name) - err := bk.ValidateBookkeeperVersion("") + err := bk.ValidateBookkeeperVersion() if err != nil { return err } @@ -569,7 +568,7 @@ func (bk *BookkeeperCluster) ValidateCreate() error { // ValidateUpdate implements webhook.Validator so a webhook will be registered for the type func (bk *BookkeeperCluster) ValidateUpdate(old runtime.Object) error { log.Printf("validate update %s", bk.Name) - err := bk.ValidateBookkeeperVersion("") + err := bk.ValidateBookkeeperVersion() if err != nil { return err } @@ -587,31 +586,7 @@ func (bk *BookkeeperCluster) ValidateDelete() error { return nil } -func getSupportedVersions(filename string) (map[string]string, error) { - supportedVersions := make(map[string]string) - filepath := filename - if filename == "" { - filepath = "/tmp/config/keys" - } - - file, err := os.Open(filepath) - if err != nil { - return supportedVersions, fmt.Errorf("Version map /tmp/config/keys not found") - } - scanner := bufio.NewScanner(file) - for scanner.Scan() { - data := strings.Split(scanner.Text(), ":") - supportedVersions[data[0]] = data[1] - } - file.Close() - return supportedVersions, nil -} - -func (bk *BookkeeperCluster) ValidateBookkeeperVersion(filename string) error { - supportedVersions, err := getSupportedVersions(filename) - if err != nil { - return fmt.Errorf("Error retrieving suported versions %v", err) - } +func (bk *BookkeeperCluster) ValidateBookkeeperVersion() error { if bk.Spec.Version == "" { bk.Spec.Version = DefaultBookkeeperVersion @@ -637,6 +612,7 @@ func (bk *BookkeeperCluster) ValidateBookkeeperVersion(filename string) error { if bk.Status.IsClusterInErrorState() { return fmt.Errorf("failed to process the request, cluster is in error state.") } + // Check if the request has a valid Bookkeeper version normRequestVersion, err := util.NormalizeVersion(requestVersion) log.Printf("validateBookkeeperVersion:: normRequestVersion %s", normRequestVersion) @@ -644,10 +620,6 @@ func (bk *BookkeeperCluster) ValidateBookkeeperVersion(filename string) error { return fmt.Errorf("request version is not in valid format: %v", err) } - if _, ok := supportedVersions[normRequestVersion]; !ok { - return fmt.Errorf("unsupported Bookkeeper cluster version %s", requestVersion) - } - if bk.Status.CurrentVersion == "" { // we're deploying for the very first time return nil @@ -657,23 +629,18 @@ func (bk *BookkeeperCluster) ValidateBookkeeperVersion(filename string) error { if bk.Status.CurrentVersion == requestVersion { return nil } + // This is an upgrade, check if requested version is in the upgrade path normFoundVersion, err := util.NormalizeVersion(bk.Status.CurrentVersion) if err != nil { // It should never happen return fmt.Errorf("found version is not in valid format, something bad happens: %v", err) } - - log.Printf("validateBookkeeperVersion:: normFoundVersion %s", normFoundVersion) - upgradeString, ok := supportedVersions[normFoundVersion] - if !ok { - // It should never happen - return fmt.Errorf("failed to find current cluster version in the supported versions") - } - upgradeList := strings.Split(upgradeString, ",") - if !util.ContainsVersion(upgradeList, normRequestVersion) { - return fmt.Errorf("unsupported upgrade from version %s to %s", bk.Status.CurrentVersion, requestVersion) + if match, _ := util.CompareVersions(normRequestVersion, normFoundVersion, "<"); match { + return fmt.Errorf("downgrading the cluster from version %s to %s is not supported", bk.Status.CurrentVersion, requestVersion) } + log.Printf("validateBookkeeperVersion:: normFoundVersion %s", normFoundVersion) + log.Print("validateBookkeeperVersion:: No error found...returning...") return nil } diff --git a/pkg/apis/bookkeeper/v1alpha1/bookkeepercluster_types_test.go b/pkg/apis/bookkeeper/v1alpha1/bookkeepercluster_types_test.go index f1a773ad..be1788f1 100644 --- a/pkg/apis/bookkeeper/v1alpha1/bookkeepercluster_types_test.go +++ b/pkg/apis/bookkeeper/v1alpha1/bookkeepercluster_types_test.go @@ -11,7 +11,6 @@ package v1alpha1_test import ( - "os" "strings" "testing" @@ -62,6 +61,7 @@ var _ = Describe("BookkeeperCluster Types Spec", func() { Ω(bk.Spec.Version).Should(Equal("0.9.0")) }) }) + Context("NewEvent", func() { var bk *v1alpha1.BookkeeperCluster var event *corev1.Event @@ -80,6 +80,7 @@ var _ = Describe("BookkeeperCluster Types Spec", func() { Ω(event.Size()).ShouldNot(Equal(0)) }) }) + Context("NewApplicationEvent", func() { var bk *v1alpha1.BookkeeperCluster var event *corev1.Event @@ -97,6 +98,7 @@ var _ = Describe("BookkeeperCluster Types Spec", func() { Ω(event.Size()).ShouldNot(Equal(0)) }) }) + Context("WaitForClusterToTerminate", func() { var bk *v1alpha1.BookkeeperCluster var client client.Client @@ -121,6 +123,7 @@ var _ = Describe("BookkeeperCluster Types Spec", func() { Ω(err).Should(BeNil()) }) }) + Context("GetClusterExpectedSize", func() { var replicas int var bk *v1alpha1.BookkeeperCluster @@ -138,6 +141,7 @@ var _ = Describe("BookkeeperCluster Types Spec", func() { Ω(replicas).To(Equal(3)) }) }) + Context("BookkeeperImage", func() { var image string var bk *v1alpha1.BookkeeperCluster @@ -159,6 +163,7 @@ var _ = Describe("BookkeeperCluster Types Spec", func() { }) }) + Context("BookkeeperTargetImage", func() { var image, image1 string var bk *v1alpha1.BookkeeperCluster @@ -181,6 +186,7 @@ var _ = Describe("BookkeeperCluster Types Spec", func() { Ω(image1).To(Equal("pravega/bookkeeper:0.6.1")) }) }) + Context("LabelsForBookie", func() { var str1 map[string]string var bk *v1alpha1.BookkeeperCluster @@ -203,25 +209,7 @@ var _ = Describe("BookkeeperCluster Types Spec", func() { Ω(str1["component"]).To(Equal("bookie")) }) }) - Context("ValidateCreate", func() { - var ( - bk *v1alpha1.BookkeeperCluster - err error - ) - BeforeEach(func() { - bk = &v1alpha1.BookkeeperCluster{ - ObjectMeta: metav1.ObjectMeta{ - Name: "default", - }, - } - bk.WithDefaults() - err = bk.ValidateCreate() - }) - It("should return error", func() { - Ω(strings.ContainsAny(err.Error(), "Error retrieving suported versions")).Should(Equal(true)) - }) - }) Context("ValidateDelete", func() { var ( bk *v1alpha1.BookkeeperCluster @@ -241,12 +229,13 @@ var _ = Describe("BookkeeperCluster Types Spec", func() { Ω(err).To(BeNil()) }) }) + Context("ValidateBookkeeperVersion", func() { var ( - bk *v1alpha1.BookkeeperCluster - err error - file1 *os.File + bk *v1alpha1.BookkeeperCluster + err error ) + BeforeEach(func() { bk = &v1alpha1.BookkeeperCluster{ ObjectMeta: metav1.ObjectMeta{ @@ -254,34 +243,18 @@ var _ = Describe("BookkeeperCluster Types Spec", func() { }, } bk.WithDefaults() - - file1, _ = os.Create("filename") - - file1, _ = os.OpenFile("filename", os.O_RDWR, 0644) - file1.WriteString("0.1.0:0.1.0 \n") - file1.WriteString("0.2.0:0.2.0 \n") - file1.WriteString("0.3.0:0.3.0,0.3.1,0.3.2 \n") - file1.WriteString("0.3.1:0.3.1,0.3.2 \n") - file1.WriteString("0.4.0:0.4.0 \n") - file1.WriteString("0.5.0:0.5.0,0.5.1,0.6.0,0.6.1,0.6.2,0.7.0,0.7.1 \n") - file1.WriteString("0.5.1:0.5.1,0.6.0,0.6.1,0.6.2,0.7.0,0.7.1 \n") - file1.WriteString("0.6.0:0.6.0,0.6.1,0.6.2,0.7.0,0.7.1 \n") - file1.WriteString("0.6.1:0.6.1,0.6.2,0.7.0,0.7.1 \n") - file1.WriteString("0.6.2:0.6.2,0.7.0,0.7.1 \n") - file1.WriteString("0.7.0:0.7.0,0.7.1 \n") - file1.WriteString("0.7.1:0.7.1 \n") - file1.WriteString("0.7.2:0.7.2 \n") - file1.WriteString("0.9.0:0.9.0 \n") }) + Context("Spec version empty", func() { BeforeEach(func() { bk.Spec.Version = "" - err = bk.ValidateBookkeeperVersion("filename") + err = bk.ValidateBookkeeperVersion() }) It("should return nil", func() { Ω(err).To(BeNil()) }) }) + Context("Absolute Path is incorrect", func() { BeforeEach(func() { bk.Spec = v1alpha1.BookkeeperClusterSpec{ @@ -298,85 +271,73 @@ var _ = Describe("BookkeeperCluster Types Spec", func() { Ω(strings.ContainsAny(err.Error(), "Error validating absolute paths of journal/ledger/index directories")).Should(Equal(true)) }) }) + Context("Version not in valid format", func() { BeforeEach(func() { bk.Spec.Version = "999" - err = bk.ValidateBookkeeperVersion("filename") + err = bk.ValidateBookkeeperVersion() }) It("should return error", func() { Ω(strings.ContainsAny(err.Error(), "request version is not in valid format")).Should(Equal(true)) }) }) - Context("Version not supported", func() { - BeforeEach(func() { - bk.Spec.Version = "0.7.5" - err = bk.ValidateBookkeeperVersion("filename") - }) - It("should return error", func() { - Ω(strings.ContainsAny(err.Error(), "unsupported Bookkeeper cluster version")).Should(Equal(true)) - }) - }) + Context("Spec version and current version same", func() { BeforeEach(func() { bk.Spec.Version = "0.7.0" bk.Status.CurrentVersion = "0.7.0" - err = bk.ValidateBookkeeperVersion("filename") + err = bk.ValidateBookkeeperVersion() }) It("should return nil", func() { Ω(err).To(BeNil()) }) }) - Context("Unsupported current version", func() { - BeforeEach(func() { - bk.Spec.Version = "0.7.0" - bk.Status.CurrentVersion = "0.9.0" - err = bk.ValidateBookkeeperVersion("filename") - }) - It("should return error", func() { - Ω(strings.ContainsAny(err.Error(), "failed to find current cluster version in the supported versions")).Should(Equal(true)) - }) - }) + Context("current version not in correct format", func() { BeforeEach(func() { bk.Spec.Version = "0.7.0" bk.Status.CurrentVersion = "999" - err = bk.ValidateBookkeeperVersion("filename") + err = bk.ValidateBookkeeperVersion() }) It("should return error", func() { Ω(strings.ContainsAny(err.Error(), "found version is not in valid format")).Should(Equal(true)) }) }) + Context("unsupported upgrade to a version", func() { BeforeEach(func() { - bk.Status.CurrentVersion = "0.7.0" - bk.Spec.Version = "0.7.2" - err = bk.ValidateBookkeeperVersion("filename") + bk.Status.CurrentVersion = "0.7.2" + bk.Spec.Version = "0.7.0" + err = bk.ValidateBookkeeperVersion() }) It("should return error", func() { - Ω(strings.ContainsAny(err.Error(), "unsupported upgrade from version")).Should(Equal(true)) + Ω(strings.ContainsAny(err.Error(), "downgrading the cluster from version 0.7.2 to 0.7.0 is not supported")).Should(Equal(true)) }) }) + Context("supported upgrade to a version", func() { BeforeEach(func() { bk.Status.CurrentVersion = "0.7.0" - bk.Spec.Version = "0.7.1" - err = bk.ValidateBookkeeperVersion("filename") + bk.Spec.Version = "0.7.3" + err = bk.ValidateBookkeeperVersion() }) It("should return nil", func() { Ω(err).To(BeNil()) }) }) + Context("validation while cluster upgrade in progress", func() { BeforeEach(func() { bk.Status.SetUpgradingConditionTrue(" ", " ") bk.Spec.Version = "0.7.1" bk.Status.TargetVersion = "0.7.0" - err = bk.ValidateBookkeeperVersion("filename") + err = bk.ValidateBookkeeperVersion() }) It("should return error", func() { Ω(strings.ContainsAny(err.Error(), "failed to process the request, cluster is upgrading")).Should(Equal(true)) }) }) + Context("validation while cluster rollback in progress", func() { BeforeEach(func() { bk.Status.CurrentVersion = "0.7.0" @@ -384,22 +345,24 @@ var _ = Describe("BookkeeperCluster Types Spec", func() { bk.Status.AddToVersionHistory("0.6.0") bk.Status.SetRollbackConditionTrue(" ", " ") bk.Spec.Version = "0.7.0" - err = bk.ValidateBookkeeperVersion("filename") + err = bk.ValidateBookkeeperVersion() }) It("should return error", func() { Ω(strings.ContainsAny(err.Error(), "failed to process the request, rollback in progress")).Should(Equal(true)) }) }) + Context("validation while cluster in error state", func() { BeforeEach(func() { bk.Status.SetErrorConditionTrue("some err", " ") bk.Spec.Version = "0.7.0" - err = bk.ValidateBookkeeperVersion("filename") + err = bk.ValidateBookkeeperVersion() }) It("should return error", func() { Ω(strings.ContainsAny(err.Error(), "failed to process the request, cluster is in error state")).Should(Equal(true)) }) }) + Context("validation while cluster in upgradefailed state", func() { BeforeEach(func() { bk.Status.CurrentVersion = "0.7.0" @@ -407,12 +370,13 @@ var _ = Describe("BookkeeperCluster Types Spec", func() { bk.Status.AddToVersionHistory("0.6.0") bk.Status.SetErrorConditionTrue("UpgradeFailed", " ") bk.Spec.Version = "0.7.0" - err = bk.ValidateBookkeeperVersion("filename") + err = bk.ValidateBookkeeperVersion() }) It("should return error", func() { Ω(strings.ContainsAny(err.Error(), "Rollback to version 0.7.0 not supported")).Should(Equal(true)) }) }) + Context("validation while cluster in upgradefailed state and supported rollback version", func() { BeforeEach(func() { bk.Status.CurrentVersion = "0.6.0" @@ -420,26 +384,14 @@ var _ = Describe("BookkeeperCluster Types Spec", func() { bk.Status.AddToVersionHistory("0.6.0") bk.Status.SetErrorConditionTrue("UpgradeFailed", " ") bk.Spec.Version = "0.6.0" - err = bk.ValidateBookkeeperVersion("filename") + err = bk.ValidateBookkeeperVersion() }) It("should return nil", func() { Ω(err).To(BeNil()) }) }) - Context("validation with configmap not present", func() { - BeforeEach(func() { - bk.Spec.Version = "0.7.0" - err = bk.ValidateBookkeeperVersion("") - }) - It("should return error", func() { - Ω(strings.ContainsAny(err.Error(), "Error retrieving suported versions")).Should(Equal(true)) - }) - }) - AfterEach(func() { - file1.Close() - os.Remove("filename") - }) }) + Context("HeadlessServiceNameForBookie", func() { var str1 string BeforeEach(func() { diff --git a/test/e2e/webhook_test.go b/test/e2e/webhook_test.go index cdb29189..fb93b1ed 100644 --- a/test/e2e/webhook_test.go +++ b/test/e2e/webhook_test.go @@ -32,14 +32,14 @@ func testWebhook(t *testing.T) { g.Expect(err).NotTo(HaveOccurred()) f := framework.Global - //Test webhook with an unsupported Bookkeeper cluster version - invalidVersion := bookkeeper_e2eutil.NewClusterWithVersion(namespace, "99.0.0") + //Test webhook with an invalid Bookkeeper cluster version format + invalidVersion := bookkeeper_e2eutil.NewClusterWithVersion(namespace, "999") invalidVersion.WithDefaults() _, err = bookkeeper_e2eutil.CreateBKCluster(t, f, ctx, invalidVersion) - g.Expect(err).To(HaveOccurred(), "Should reject deployment of unsupported version") - g.Expect(err.Error()).To(ContainSubstring("unsupported Bookkeeper cluster version 99.0.0")) + g.Expect(err).To(HaveOccurred(), "Should reject deployment of invalid version format") + g.Expect(err.Error()).To(ContainSubstring("request version is not in valid format:")) - // Test webhook with a supported Bookkeeper cluster version + // Test webhook with a valid Bookkeeper cluster version format validVersion := bookkeeper_e2eutil.NewClusterWithVersion(namespace, "0.6.0") validVersion.WithDefaults() bookkeeper, err := bookkeeper_e2eutil.CreateBKCluster(t, f, ctx, validVersion) @@ -48,20 +48,13 @@ func testWebhook(t *testing.T) { err = bookkeeper_e2eutil.WaitForBookkeeperClusterToBecomeReady(t, f, ctx, bookkeeper) g.Expect(err).NotTo(HaveOccurred()) - // Try to upgrade to a non-supported version + // Try to downgrade the cluster bookkeeper, err = bookkeeper_e2eutil.GetBKCluster(t, f, ctx, bookkeeper) g.Expect(err).NotTo(HaveOccurred()) - - bookkeeper.Spec.Version = "99.0.0" - err = bookkeeper_e2eutil.UpdateBKCluster(t, f, ctx, bookkeeper) - g.Expect(err).To(HaveOccurred(), "Should reject upgrade to an unsupported version") - g.Expect(err.Error()).To(ContainSubstring("unsupported Bookkeeper cluster version 99.0.0")) - - // Try to downgrade the cluster bookkeeper.Spec.Version = "0.5.0" err = bookkeeper_e2eutil.UpdateBKCluster(t, f, ctx, bookkeeper) g.Expect(err).To(HaveOccurred(), "Should not allow downgrade") - g.Expect(err.Error()).To(ContainSubstring("unsupported upgrade from version 0.6.0 to 0.5.0")) + g.Expect(err.Error()).To(ContainSubstring("downgrading the cluster from version 0.6.0 to 0.5.0 is not supported")) // Delete cluster err = bookkeeper_e2eutil.DeleteBKCluster(t, f, ctx, bookkeeper)