Skip to content

Commit

Permalink
feat(upgrade): add support for jiva-csi volume upgrades (#89)
Browse files Browse the repository at this point in the history
Signed-off-by: shubham <[email protected]>
  • Loading branch information
shubham14bajpai authored Mar 30, 2021
1 parent 86e5949 commit 9ab1d19
Show file tree
Hide file tree
Showing 1,651 changed files with 215,041 additions and 143,681 deletions.
1 change: 1 addition & 0 deletions changelogs/unreleased/89-shubham14bajpai
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
feat(upgrade): add support for jiva-csi volume upgrades
15 changes: 8 additions & 7 deletions cmd/migrate/executor/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package executor

import (
"context"
"os"
"strings"

Expand Down Expand Up @@ -61,14 +62,14 @@ func NewMigrateResourceJob() *cobra.Command {
openebsNamespace := cmdUtil.GetOpenEBSNamespace()
migrationTaskObj, err := client.OpenebsV1alpha1().
MigrationTasks(openebsNamespace).
Get(name, metav1.GetOptions{})
Get(context.TODO(), name, metav1.GetOptions{})
util.CheckErr(err, util.Fatal)
util.CheckErr(options.InitializeFromMigrationTaskResource(migrationTaskObj), util.Fatal)
util.CheckErr(options.RunPreFlightChecks(), util.Fatal)
err = options.RunResourceMigrate()
if err != nil {
migrationTaskObj, uerr := client.OpenebsV1alpha1().MigrationTasks(openebsNamespace).
Get(name, metav1.GetOptions{})
Get(context.TODO(), name, metav1.GetOptions{})
if uerr != nil {
util.Fatal(uerr.Error())
}
Expand All @@ -82,21 +83,21 @@ func NewMigrateResourceJob() *cobra.Command {
migrationTaskObj.Status.CompletedTime = metav1.Now()
}
_, uerr = client.OpenebsV1alpha1().MigrationTasks(openebsNamespace).
Update(migrationTaskObj)
Update(context.TODO(), migrationTaskObj, metav1.UpdateOptions{})
if uerr != nil {
util.Fatal(uerr.Error())
}
util.Fatal(err.Error())
} else {
migrationTaskObj, uerr := client.OpenebsV1alpha1().MigrationTasks(openebsNamespace).
Get(name, metav1.GetOptions{})
Get(context.TODO(), name, metav1.GetOptions{})
if uerr != nil {
util.Fatal(uerr.Error())
}
migrationTaskObj.Status.Phase = v1Alpha1API.MigrateSuccess
migrationTaskObj.Status.CompletedTime = metav1.Now()
_, uerr = client.OpenebsV1alpha1().MigrationTasks(openebsNamespace).
Update(migrationTaskObj)
Update(context.TODO(), migrationTaskObj, metav1.UpdateOptions{})
if uerr != nil {
util.Fatal(uerr.Error())
}
Expand Down Expand Up @@ -164,12 +165,12 @@ func getBackoffLimit(openebsNamespace string) (int, error) {
}
podName := os.Getenv("POD_NAME")
podObj, err := client.CoreV1().Pods(openebsNamespace).
Get(podName, metav1.GetOptions{})
Get(context.TODO(), podName, metav1.GetOptions{})
if err != nil {
return 0, errors.Wrapf(err, "failed to get backoff limit")
}
jobObj, err := client.BatchV1().Jobs(openebsNamespace).
Get(podObj.OwnerReferences[0].Name, metav1.GetOptions{})
Get(context.TODO(), podObj.OwnerReferences[0].Name, metav1.GetOptions{})
if err != nil {
return 0, errors.Wrapf(err, "failed to get backoff limit")
}
Expand Down
3 changes: 0 additions & 3 deletions cmd/upgrade/executor/cstor_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ limitations under the License.
package executor

import (
"fmt"

"github.com/openebs/maya/pkg/util"
"github.com/spf13/cobra"
"k8s.io/klog"
Expand Down Expand Up @@ -77,7 +75,6 @@ func (u *UpgradeOptions) RunCStorVolumeUpgrade(cmd *cobra.Command, name string)
}
klog.Infof("Successfully upgraded %s to %s", name, u.toVersion)
} else {
fmt.Println(version.IsCurrentVersionValid(u.fromVersion), version.IsDesiredVersionValid(u.toVersion))
return errors.Errorf("Invalid from version %s or to version %s", u.fromVersion, u.toVersion)
}
return nil
Expand Down
79 changes: 79 additions & 0 deletions cmd/upgrade/executor/jiva_volume.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
Copyright 2021 The OpenEBS Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package executor

import (
"github.com/openebs/maya/pkg/util"
"github.com/spf13/cobra"
"k8s.io/klog"

upgrade "github.com/openebs/upgrade/pkg/upgrade"
"github.com/openebs/upgrade/pkg/version"
errors "github.com/pkg/errors"
)

var (
jivaVolumeUpgradeCmdHelpText = `
This command upgrades the jiva volume
Usage: upgrade jiva-volume --options... <volume-name>...
`
)

// NewUpgradeJivaVolumeJob upgrades Jiva Volumes
func NewUpgradeJivaVolumeJob() *cobra.Command {
cmd := &cobra.Command{
Use: "jiva-volume",
Short: "Upgrade Jiva Volume",
Long: jivaVolumeUpgradeCmdHelpText,
Example: `upgrade jiva-volume <spc-name>...`,
Run: func(cmd *cobra.Command, args []string) {
if len(args) == 0 {
util.Fatal("failed to upgrade: no volume name provided")
}
for _, name := range args {
options.resourceKind = "jivaVolume"
util.CheckErr(options.RunPreFlightChecks(cmd), util.Fatal)
util.CheckErr(options.InitializeDefaults(cmd), util.Fatal)
util.CheckErr(options.RunJivaVolumeUpgrade(cmd, name), util.Fatal)
}
},
}
return cmd
}

// RunJivaVolumeUpgrade upgrades the given Jiva Volume.
func (u *UpgradeOptions) RunJivaVolumeUpgrade(cmd *cobra.Command, name string) error {

if version.IsCurrentVersionValid(u.fromVersion) && version.IsDesiredVersionValid(u.toVersion) {
klog.Infof("Upgrading JivaVolume %s to %s", name, u.toVersion)
err := upgrade.Exec(u.fromVersion, u.toVersion,
u.resourceKind,
name,
u.openebsNamespace,
u.imageURLPrefix,
u.toVersionImageTag)
if err != nil {
klog.Error(err)
return errors.Errorf("Failed to upgrade JivaVolume %v", name)
}
klog.Infof("Successfully upgraded %s to %s", name, u.toVersion)
} else {
return errors.Errorf("Invalid from version %s or to version %s", u.fromVersion, u.toVersion)
}
return nil
}
20 changes: 13 additions & 7 deletions cmd/upgrade/executor/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package executor

import (
"context"
"os"
"strings"

Expand Down Expand Up @@ -62,7 +63,7 @@ func NewUpgradeResourceJob() *cobra.Command {
upgradeTaskLabel := cmdUtil.GetUpgradeTaskLabel()
openebsNamespace := cmdUtil.GetOpenEBSNamespace()
upgradeTaskList, err := client.OpenebsV1alpha1().UpgradeTasks(openebsNamespace).
List(metav1.ListOptions{
List(context.TODO(), metav1.ListOptions{
LabelSelector: upgradeTaskLabel,
})
util.CheckErr(err, util.Fatal)
Expand All @@ -77,7 +78,7 @@ func NewUpgradeResourceJob() *cobra.Command {
err := options.RunResourceUpgrade(cmd)
if err != nil {
utaskObj, uerr := client.OpenebsV1alpha1().UpgradeTasks(openebsNamespace).
Get(cr.Name, metav1.GetOptions{})
Get(context.TODO(), cr.Name, metav1.GetOptions{})
if uerr != nil {
util.Fatal(uerr.Error())
}
Expand All @@ -91,21 +92,21 @@ func NewUpgradeResourceJob() *cobra.Command {
utaskObj.Status.CompletedTime = metav1.Now()
}
_, uerr = client.OpenebsV1alpha1().UpgradeTasks(openebsNamespace).
Update(utaskObj)
Update(context.TODO(), utaskObj, metav1.UpdateOptions{})
if uerr != nil {
util.Fatal(uerr.Error())
}
util.Fatal(err.Error())
} else {
utaskObj, uerr := client.OpenebsV1alpha1().UpgradeTasks(openebsNamespace).
Get(cr.Name, metav1.GetOptions{})
Get(context.TODO(), cr.Name, metav1.GetOptions{})
if uerr != nil {
util.Fatal(uerr.Error())
}
utaskObj.Status.Phase = v1Alpha1API.UpgradeSuccess
utaskObj.Status.CompletedTime = metav1.Now()
_, uerr = client.OpenebsV1alpha1().UpgradeTasks(openebsNamespace).
Update(utaskObj)
Update(context.TODO(), utaskObj, metav1.UpdateOptions{})
if uerr != nil {
util.Fatal(uerr.Error())
}
Expand Down Expand Up @@ -151,6 +152,11 @@ func (u *UpgradeOptions) InitializeFromUpgradeTaskResource(
case upgradeTaskCRObj.Spec.ResourceSpec.CStorVolume != nil:
u.resourceKind = "cstorVolume"
u.name = upgradeTaskCRObj.Spec.ResourceSpec.CStorVolume.PVName

case upgradeTaskCRObj.Spec.ResourceSpec.JivaVolume != nil:
u.resourceKind = "jivaVolume"
u.name = upgradeTaskCRObj.Spec.ResourceSpec.JivaVolume.PVName

}

return nil
Expand Down Expand Up @@ -207,12 +213,12 @@ func getBackoffLimit(openebsNamespace string) (int, error) {
}
podName := os.Getenv("POD_NAME")
podObj, err := client.CoreV1().Pods(openebsNamespace).
Get(podName, metav1.GetOptions{})
Get(context.TODO(), podName, metav1.GetOptions{})
if err != nil {
return 0, errors.Wrapf(err, "failed to get backoff limit")
}
jobObj, err := client.BatchV1().Jobs(openebsNamespace).
Get(podObj.OwnerReferences[0].Name, metav1.GetOptions{})
Get(context.TODO(), podObj.OwnerReferences[0].Name, metav1.GetOptions{})
if err != nil {
return 0, errors.Wrapf(err, "failed to get backoff limit")
}
Expand Down
1 change: 1 addition & 0 deletions cmd/upgrade/executor/setup_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func NewJob() *cobra.Command {
NewUpgradeCStorCSPCJob(),
NewUpgradeCStorVolumeJob(),
NewUpgradeResourceJob(),
NewUpgradeJivaVolumeJob(),
)

cmd.PersistentFlags().StringVarP(&options.fromVersion,
Expand Down
78 changes: 78 additions & 0 deletions examples/upgrade/jiva-volume.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Copyright © 2021 The OpenEBS Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# This is an example YAML for upgrading cstor volume.
# Some of the values below needs to be changed to
# match your openebs installation. The fields are
# indicated with VERIFY
---
apiVersion: batch/v1
kind: Job
metadata:
# VERIFY that you have provided a unique name for this upgrade job.
# The name can be any valid K8s string for name.
name: jiva-volume-upgrade

# VERIFY the value of namespace is same as the namespace where openebs components
# are installed. You can verify using the command:
# `kubectl get pods -n <openebs-namespace> -l openebs.io/component-name=maya-apiserver`
# The above command should return status of the openebs-apiserver.
namespace: openebs
spec:
template:
spec:
# VERIFY the value of serviceAccountName is pointing to service account
# created within openebs namespace. Use the non-default account.
# by running `kubectl get sa -n <openebs-namespace>`
serviceAccountName: jiva-operator
containers:
- name: upgrade
args:
- "jiva-volume"

# --from-version is the current version of the volume
- "--from-version=2.6.0"

# --to-version is the version desired upgrade version
- "--to-version=2.7.0"
# if required the image prefix of the volume deployments can be
# changed using the flag below, defaults to whatever was present on old
# deployments.
#- "--to-version-image-prefix=openebs/"
# if required the image tags for volume deployments can be changed
# to a custom image tag using the flag below,
# defaults to the --to-version mentioned above.
#- "--to-version-image-tag=ci"

# VERIFY that you have provided the correct list of volume Names
- "pvc-1d4f7cf6-9da6-433a-a2f6-b22bdeb592f0"

# Following are optional parameters
# Log Level
- "--v=4"
# DO NOT CHANGE BELOW PARAMETERS
env:
- name: OPENEBS_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
tty: true

# the image version should be same as the --to-version mentioned above
# in the args of the job
image: openebs/upgrade:<same-as-to-version>
imagePullPolicy: IfNotPresent
restartPolicy: OnFailure
---

21 changes: 13 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,20 @@ module github.com/openebs/upgrade
go 1.14

require (
github.com/google/go-cmp v0.4.0
github.com/kubernetes-csi/external-snapshotter/v2 v2.1.1
github.com/openebs/api/v2 v2.2.1-0.20210127083022-3d3257dd6a71
github.com/openebs/maya v0.0.0-20200602143918-71415115098d
github.com/google/go-cmp v0.5.4
github.com/kubernetes-csi/external-snapshotter/client/v4 v4.0.0
github.com/openebs/api/v2 v2.2.1-0.20210302070038-f282f96d77c6
github.com/openebs/jiva-operator v1.12.2-0.20210305095718-9ceaccf89e9d
github.com/openebs/maya v1.12.1-0.20210308113344-5c43ada4c9e2
github.com/pkg/errors v0.9.1
github.com/spf13/cobra v1.0.0
github.com/spf13/cobra v1.1.1
gopkg.in/yaml.v1 v1.0.0-20140924161607-9f9df34309c0
k8s.io/api v0.17.3
k8s.io/apimachinery v0.17.3
k8s.io/client-go v0.17.3
k8s.io/api v0.20.2
k8s.io/apimachinery v0.20.2
k8s.io/client-go v0.20.2
k8s.io/klog v1.0.0
k8s.io/kubectl v0.20.2
sigs.k8s.io/controller-runtime v0.8.2
)

replace k8s.io/client-go => k8s.io/client-go v0.20.2
Loading

0 comments on commit 9ab1d19

Please sign in to comment.