Skip to content

Commit

Permalink
Issue 303: Providing the supportedVersions map as a ConfigMap (#341)
Browse files Browse the repository at this point in the history
* Issue 303: Removing supported versions map

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

* Issue 303: Fixing e2e tests

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

* Issue 303: Addressing review comments

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

* Issue 303: Addressing review comments

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

* Issue 303: Minor fix

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

* Issue 303: Fixing e2e tests

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

* Issue 303: Addressing review comments

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

* Issue 303: Addressing review comments

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

* Issue 303: Fixing e2e tests

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

* Issue 303: Updating configmap entries

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

* Issue 303: Addressing review comments

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

Co-authored-by: SrishT <[email protected]>
  • Loading branch information
SrishT and SrishT authored Mar 19, 2020
1 parent 8fe63b6 commit 2c7ce7a
Show file tree
Hide file tree
Showing 10 changed files with 131 additions and 33 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ jobs:
- sleep 30s
- kubectl -n default create -f test/e2e/resources/bk-cluster.yaml
- JPATH1='{.spec.replicas}'; JPATH2='{.status.readyReplicas}'; bk_replicas=$(kubectl get bookkeepercluster pravega -o jsonpath=$JPATH1);bk_ready=$(kubectl get bookkeepercluster pravega -o jsonpath=$JPATH2); echo "REPLICAS=$bk_replicas, READY=$bk_ready"; while [ "$bk_replicas" != "$bk_ready" ]; do sleep 1; bk_replicas=$(kubectl get bookkeepercluster pravega -o jsonpath=$JPATH1); bk_ready=$(kubectl get bookkeepercluster pravega -o jsonpath=$JPATH2); echo "REPLICAS=$bk_replicas, READY=$bk_ready"; done
# Install the ConfigMap for version dependency
- kubectl -n default create -f deploy/version_map.yaml
# Show Pravega dependencies
- kubectl -n default get pod,pvc,svc -o wide
script:
Expand Down
5 changes: 5 additions & 0 deletions charts/pravega/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,8 @@ We truncate at 63 chars because some Kubernetes name fields are limited to this
{{- $name := default .Chart.Name .Values.nameOverride -}}
{{- printf "%s-%s-%s" .Release.Name $name .Values.serviceAccount.name | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{- define "versionmap.fullname" -}}
{{- $name := default .Chart.Name .Values.nameOverride -}}
{{- printf "%s-%s-supported-upgrade-paths" .Release.Name $name -}}
{{- end -}}
17 changes: 17 additions & 0 deletions charts/pravega/templates/version_map.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
kind: ConfigMap
apiVersion: v1
metadata:
name: {{ template "versionmap.fullname" . }}
data:
0.1.0: "0.1.0"
0.2.0: "0.2.0"
0.3.0: "0.3.0,0.3.1,0.3.2"
0.3.1: "0.3.1,0.3.2"
0.3.2: "0.3.2"
0.4.0: "0.4.0"
0.5.0: "0.5.0,0.5.1,0.6.0,0.6.1,0.6.2,0.7.0"
0.5.1: "0.5.1,0.6.0,0.6.1,0.6.2,0.7.0"
0.6.0: "0.6.0,0.6.1,0.6.2,0.7.0"
0.6.1: "0.6.1,0.6.2,0.7.0"
0.6.2: "0.6.2,0.7.0"
0.7.0: "0.7.0"
2 changes: 1 addition & 1 deletion charts/pravega/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.

version: 0.5.0
version: 0.7.0
zookeeperUri: zk-client:2181

externalAccess:
Expand Down
6 changes: 0 additions & 6 deletions deploy/crds/pravega_v1alpha1_pravegacluster_cr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,23 @@ metadata:
name: "pravega"
spec:
zookeeperUri: zk-client:2181

externalAccess:
enabled: true
type: LoadBalancer

bookkeeperUri: "pravega-bookie-0.pravega-bookie-headless.default.svc.cluster.local:3181,pravega-bookie-1.pravega-bookie-headless.default.svc.cluster.local:3181,pravega-bookie-2.pravega-bookie-headless.default.svc.cluster.local:3181"

pravega:
controllerReplicas: 1
segmentStoreReplicas: 3

cacheVolumeClaimTemplate:
accessModes: [ "ReadWriteOnce" ]
storageClassName: "standard"
resources:
requests:
storage: 20Gi

image:
repository: pravega/pravega
tag: latest
pullPolicy: IfNotPresent

tier2:
filesystem:
persistentVolumeClaim:
Expand Down
17 changes: 17 additions & 0 deletions deploy/version_map.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
kind: ConfigMap
apiVersion: v1
metadata:
name: pravega-supported-upgrade-paths
data:
0.1.0: "0.1.0"
0.2.0: "0.2.0"
0.3.0: "0.3.0,0.3.1,0.3.2"
0.3.1: "0.3.1,0.3.2"
0.3.2: "0.3.2"
0.4.0: "0.4.0"
0.5.0: "0.5.0,0.5.1,0.6.0,0.6.1,0.6.2,0.7.0"
0.5.1: "0.5.1,0.6.0,0.6.1,0.6.2,0.7.0"
0.6.0: "0.6.0,0.6.1,0.6.2,0.7.0"
0.6.1: "0.6.1,0.6.2,0.7.0"
0.6.2: "0.6.2,0.7.0"
0.7.0: "0.7.0"
12 changes: 7 additions & 5 deletions doc/manual-installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ Install the operator.
$ kubectl create -f deploy/operator.yaml
```

Finally create a ConfigMap which contains the list of supported upgrade paths for the pravega cluster.

```
$ kubectl create -f deploy/version_map.yaml
```

### Deploying in Test Mode
We can enable test mode on operator by passing an argument `-test` in `operator.yaml` file.
Check out [test mode](../README.md#deploying-in-test-mode)
Expand Down Expand Up @@ -67,11 +73,7 @@ spec:
version: 0.4.0
zookeeperUri: [ZOOKEEPER_HOST]:2181

bookkeeper:
replicas: 3
image:
repository: pravega/bookkeeper
autoRecovery: true
bookkeeperUri: "pravega-bookie-0.pravega-bookie-headless.default.svc.cluster.local:3181,pravega-bookie-1.pravega-bookie-headless.default.svc.cluster.local:3181,pravega-bookie-2.pravega-bookie-headless.default.svc.cluster.local:3181"

pravega:
controllerReplicas: 1
Expand Down
4 changes: 4 additions & 0 deletions pkg/util/pravegacluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ func init() {
versionRegexp = regexp.MustCompile(MajorMinorVersionRegexp)
}

func ConfigMapNameForPravega(clusterName string) string {
return fmt.Sprintf("%s-supported-upgrade-paths", clusterName)
}

func PdbNameForBookie(clusterName string) string {
return fmt.Sprintf("%s-bookie", clusterName)
}
Expand Down
36 changes: 15 additions & 21 deletions pkg/webhook/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ import (
"context"
"fmt"
"net/http"
"strings"

pravegav1alpha1 "github.com/pravega/pravega-operator/pkg/apis/pravega/v1alpha1"
"github.com/pravega/pravega-operator/pkg/util"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
Expand All @@ -29,26 +31,6 @@ import (
log "github.com/sirupsen/logrus"
)

var (
// The key is the supported versions, the value is a list of versions that can upgrade to.
supportedVersions = map[string][]string{
"0.1.0": []string{"0.1.0"},
"0.2.0": []string{"0.2.0"},
"0.3.0": []string{"0.3.0", "0.3.1", "0.3.2"},
"0.3.1": []string{"0.3.1", "0.3.2"},
"0.3.2": []string{"0.3.2"},
"0.4.0": []string{"0.4.0"},
"0.5.0": []string{"0.5.0", "0.5.1", "0.6.0", "0.6.1", "0.6.2", "0.6.3", "0.7.0", "0.8.0"},
"0.5.1": []string{"0.5.1", "0.6.0", "0.6.1", "0.6.2", "0.6.3", "0.7.0", "0.8.0"},
"0.6.0": []string{"0.6.0", "0.6.1", "0.6.2", "0.6.3", "0.7.0", "0.8.0"},
"0.6.1": []string{"0.6.1", "0.6.2", "0.6.3", "0.7.0", "0.8.0"},
"0.6.2": []string{"0.6.2", "0.6.3", "0.7.0", "0.8.0"},
"0.6.3": []string{"0.6.3", "0.7.0", "0.8.0"},
"0.7.0": []string{"0.7.0", "0.8.0"},
"0.8.0": []string{"0.8.0"},
}
)

type pravegaWebhookHandler struct {
client client.Client
scheme *runtime.Scheme
Expand Down Expand Up @@ -88,6 +70,17 @@ func (pwh *pravegaWebhookHandler) mutatePravegaManifest(ctx context.Context, p *
}

func (pwh *pravegaWebhookHandler) mutatePravegaVersion(ctx context.Context, p *pravegav1alpha1.PravegaCluster) error {
configMap := &corev1.ConfigMap{}
err := pwh.client.Get(ctx, types.NamespacedName{Name: util.ConfigMapNameForPravega(p.Name), Namespace: p.Namespace}, configMap)
if err != nil {
if errors.IsNotFound(err) {
return fmt.Errorf("config map %s not found. Please create this config map first and then retry", util.ConfigMapNameForPravega(p.Name))
}
return err
}

supportedVersions := configMap.Data

// Identify the request Pravega version
// Mutate the version if it is empty
if p.Spec.Version == "" {
Expand Down Expand Up @@ -144,11 +137,12 @@ func (pwh *pravegaWebhookHandler) mutatePravegaVersion(ctx context.Context, p *p
// It should never happen
return fmt.Errorf("found version is not in valid format, something bad happens: %v", err)
}
upgradeList, ok := supportedVersions[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", foundVersion, requestVersion)
}
Expand Down
63 changes: 63 additions & 0 deletions pkg/webhook/webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@ package webhook

import (
"context"
"log"
"testing"

"github.com/pravega/pravega-operator/pkg/apis/pravega/v1alpha1"
"github.com/pravega/pravega-operator/pkg/util"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes/scheme"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand All @@ -41,18 +44,46 @@ var _ = Describe("Admission webhook", func() {

Context("Version", func() {
var (
cm *corev1.ConfigMap
p *v1alpha1.PravegaCluster
pwh *pravegaWebhookHandler
)

BeforeEach(func() {
configData := map[string]string{
"0.1.0": "0.1.0",
"0.2.0": "0.2.0",
"0.3.0": "0.3.0,0.3.1,0.3.2",
"0.3.1": "0.3.1,0.3.2",
"0.3.2": "0.3.2",
"0.4.0": "0.4.0",
"0.5.0": "0.5.0,0.5.1,0.6.0,0.6.1,0.6.2,0.7.0",
"0.5.1": "0.5.1,0.6.0,0.6.1,0.6.2,0.7.0",
"0.6.0": "0.6.0,0.6.1,0.6.2,0.7.0",
"0.6.1": "0.6.1,0.6.2,0.7.0",
"0.6.2": "0.6.2,0.7.0",
"0.7.0": "0.7.0",
}

p = &v1alpha1.PravegaCluster{
ObjectMeta: metav1.ObjectMeta{
Name: Name,
Namespace: Namespace,
},
}
s.AddKnownTypes(v1alpha1.SchemeGroupVersion, p)

cm = &corev1.ConfigMap{
TypeMeta: metav1.TypeMeta{
Kind: "ConfigMap",
APIVersion: "v1",
},
ObjectMeta: metav1.ObjectMeta{
Name: util.ConfigMapNameForPravega(p.Name),
Namespace: Namespace,
},
Data: configData,
}
})

Context("Mutate version", func() {
Expand All @@ -64,6 +95,10 @@ var _ = Describe("Admission webhook", func() {
BeforeEach(func() {
client = fake.NewFakeClient()
pwh = &pravegaWebhookHandler{client: client}
err = pwh.client.Create(context.TODO(), cm)
if err != nil {
log.Println(err)
}
})
Context("Version only in .spec", func() {
BeforeEach(func() {
Expand Down Expand Up @@ -140,6 +175,10 @@ var _ = Describe("Admission webhook", func() {
BeforeEach(func() {
client = fake.NewFakeClient()
pwh = &pravegaWebhookHandler{client: client}
err = pwh.client.Create(context.TODO(), cm)
if err != nil {
log.Println(err)
}
})

Context("Standard version", func() {
Expand Down Expand Up @@ -199,6 +238,10 @@ var _ = Describe("Admission webhook", func() {
BeforeEach(func() {
client = fake.NewFakeClient()
pwh = &pravegaWebhookHandler{client: client}
err = pwh.client.Create(context.TODO(), cm)
if err != nil {
log.Println(err)
}
})

Context("Version not compatible", func() {
Expand Down Expand Up @@ -236,6 +279,10 @@ var _ = Describe("Admission webhook", func() {
}
client = fake.NewFakeClient(p)
pwh = &pravegaWebhookHandler{client: client}
err = pwh.client.Create(context.TODO(), cm)
if err != nil {
log.Println(err)
}
})

Context("Supported and in upgrade path", func() {
Expand Down Expand Up @@ -284,6 +331,10 @@ var _ = Describe("Admission webhook", func() {
p.Status.SetUpgradingConditionTrue("", "")
client = fake.NewFakeClient(p)
pwh = &pravegaWebhookHandler{client: client}
err = pwh.client.Create(context.TODO(), cm)
if err != nil {
log.Println(err)
}
})

Context("Sending request when upgrading", func() {
Expand Down Expand Up @@ -311,6 +362,10 @@ var _ = Describe("Admission webhook", func() {
p.Status.SetRollbackConditionTrue("", "")
client = fake.NewFakeClient(p)
pwh = &pravegaWebhookHandler{client: client}
err = pwh.client.Create(context.TODO(), cm)
if err != nil {
log.Println(err)
}
})

Context("Sending request when rolling back", func() {
Expand Down Expand Up @@ -340,6 +395,10 @@ var _ = Describe("Admission webhook", func() {

client = fake.NewFakeClient(p)
pwh = &pravegaWebhookHandler{client: client}
err = pwh.client.Create(context.TODO(), cm)
if err != nil {
log.Println(err)
}
})

Context("Sending request when upgrade failed", func() {
Expand Down Expand Up @@ -381,6 +440,10 @@ var _ = Describe("Admission webhook", func() {

client = fake.NewFakeClient(p)
pwh = &pravegaWebhookHandler{client: client}
err = pwh.client.Create(context.TODO(), cm)
if err != nil {
log.Println(err)
}
})

Context("Sending request when cluster in error state", func() {
Expand Down

0 comments on commit 2c7ce7a

Please sign in to comment.