Skip to content

Commit

Permalink
Issue 149: Removing supported versions configmap (#151)
Browse files Browse the repository at this point in the history
* Issue 149: Removing supported versions configmap

Signed-off-by: SrishT <[email protected]>

* Issue 149: Adding check to prevent downgrades

Signed-off-by: SrishT <[email protected]>

* Issue 149: Adding unit and e2e tests

Signed-off-by: SrishT <[email protected]>

* Issue 149: Modifying e2e

Signed-off-by: SrishT <[email protected]>

* Issue 149: Testing

Signed-off-by: SrishT <[email protected]>

* Issue 149: Testing

Signed-off-by: SrishT <[email protected]>

* Issue 149: Minor changes

Signed-off-by: SrishT <[email protected]>

* Issue 149: Updating documentation

Signed-off-by: SrishT <[email protected]>

* Issue 149: Updating documentation

Signed-off-by: SrishT <[email protected]>

* Issue 149: Adding version map for backward compatibility

Signed-off-by: SrishT <[email protected]>

* ISsue 149: Fixing typo

Signed-off-by: SrishT <[email protected]>

Co-authored-by: SrishT <[email protected]>
  • Loading branch information
SrishT and SrishT authored Jul 6, 2021
1 parent fa42ba3 commit 007f45e
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 201 deletions.
1 change: 1 addition & 0 deletions deploy/version_map.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# this file is deprecated and will be removed in future releases
kind: ConfigMap
apiVersion: v1
metadata:
Expand Down
17 changes: 5 additions & 12 deletions doc/manual-installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/

Expand Down Expand Up @@ -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.

Expand All @@ -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:
Expand All @@ -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.

Expand All @@ -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 `<service-name>:<port-number>`

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.

Expand Down
4 changes: 0 additions & 4 deletions doc/operator-upgrade.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
40 changes: 0 additions & 40 deletions doc/troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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,
Expand Down
3 changes: 1 addition & 2 deletions doc/upgrade-cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
51 changes: 9 additions & 42 deletions pkg/apis/bookkeeper/v1alpha1/bookkeepercluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
package v1alpha1

import (
"bufio"
"context"
"fmt"
"log"
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand All @@ -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
Expand All @@ -637,17 +612,14 @@ 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)
if err != nil {
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
Expand All @@ -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
}
Expand Down
Loading

0 comments on commit 007f45e

Please sign in to comment.