From 5e5d0fa23fee0cb3afdfea1bc4f4718f8ac48637 Mon Sep 17 00:00:00 2001 From: shubham Date: Fri, 26 Jun 2020 16:08:22 +0530 Subject: [PATCH 1/5] feat(upgrade): add support for UpgradeTask CR Signed-off-by: shubham --- cmd/upgrade/executor/options.go | 4 +- cmd/upgrade/executor/resource.go | 224 +++++++++++++++++++++++++++ cmd/upgrade/executor/setup_job.go | 1 + cmd/util/env.go | 7 + pkg/upgrade/upgrader/cstor_cspc.go | 37 ++++- pkg/upgrade/upgrader/cstor_cspi.go | 148 ++++++++++++++---- pkg/upgrade/upgrader/cstor_volume.go | 167 ++++++++++++++++---- pkg/upgrade/upgrader/upgrade.go | 9 ++ pkg/upgrade/upgrader/upgradetask.go | 178 +++++++++++++++++++++ pkg/version/util.go | 2 +- 10 files changed, 706 insertions(+), 71 deletions(-) create mode 100644 cmd/upgrade/executor/resource.go create mode 100644 pkg/upgrade/upgrader/upgradetask.go diff --git a/cmd/upgrade/executor/options.go b/cmd/upgrade/executor/options.go index 65e69b92..dfd56aa8 100644 --- a/cmd/upgrade/executor/options.go +++ b/cmd/upgrade/executor/options.go @@ -32,12 +32,13 @@ type UpgradeOptions struct { imageURLPrefix string toVersionImageTag string resourceKind string + name string } var ( options = &UpgradeOptions{ openebsNamespace: "openebs", - imageURLPrefix: "quay.io/openebs/", + imageURLPrefix: "", } ) @@ -68,6 +69,5 @@ func (u *UpgradeOptions) InitializeDefaults(cmd *cobra.Command) error { if len(strings.TrimSpace(u.toVersionImageTag)) == 0 { u.toVersionImageTag = u.toVersion } - return nil } diff --git a/cmd/upgrade/executor/resource.go b/cmd/upgrade/executor/resource.go new file mode 100644 index 00000000..8521fadc --- /dev/null +++ b/cmd/upgrade/executor/resource.go @@ -0,0 +1,224 @@ +/* +Copyright 2020 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 ( + "os" + "strings" + + "k8s.io/client-go/rest" + "k8s.io/klog" + + apis "github.com/openebs/api/pkg/apis/openebs.io/v1alpha1" + openebsclientset "github.com/openebs/api/pkg/client/clientset/versioned" + "github.com/openebs/maya/pkg/util" + cmdUtil "github.com/openebs/upgrade/cmd/util" + upgrade "github.com/openebs/upgrade/pkg/upgrade" + "github.com/openebs/upgrade/pkg/version" + errors "github.com/pkg/errors" + "github.com/spf13/cobra" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/client-go/kubernetes" +) + +var ( + resourceUpgradeCmdHelpText = ` +This command upgrades the resource mentioned in the UpgradeTask CR. +The name of the UpgradeTask CR is extracted from the ENV UPGRADE_TASK + +Usage: upgrade resource +` +) + +// ResourceOptions stores information required for upgradeTask upgrade +type ResourceOptions struct { + name string +} + +// NewUpgradeResourceJob upgrade a resource from upgradeTask +func NewUpgradeResourceJob() *cobra.Command { + client, err := initClient() + util.CheckErr(err, util.Fatal) + cmd := &cobra.Command{ + Use: "resource", + Short: "Upgrade a resource using the details specified in the UpgradeTask CR.", + Long: resourceUpgradeCmdHelpText, + Example: `upgrade resource`, + Run: func(cmd *cobra.Command, args []string) { + upgradeTaskLabel := cmdUtil.GetUpgradeTaskLabel() + openebsNamespace := cmdUtil.GetOpenEBSNamespace() + upgradeTaskList, err := client.OpenebsV1alpha1().UpgradeTasks(openebsNamespace). + List(metav1.ListOptions{ + LabelSelector: upgradeTaskLabel, + }) + util.CheckErr(err, util.Fatal) + if len(upgradeTaskList.Items) == 0 { + util.Fatal("No resource found for given label") + } + for _, cr := range upgradeTaskList.Items { + util.CheckErr(options.InitializeFromUpgradeTaskResource(cr), util.Fatal) + util.CheckErr(options.RunPreFlightChecks(cmd), util.Fatal) + util.CheckErr(options.RunResourceUpgradeChecks(cmd), util.Fatal) + util.CheckErr(options.InitializeDefaults(cmd), util.Fatal) + err := options.RunResourceUpgrade(cmd) + if err != nil { + utaskObj, err := client.OpenebsV1alpha1().UpgradeTasks(openebsNamespace). + Get(cr.Name, metav1.GetOptions{}) + if err != nil { + util.Fatal(err.Error()) + } + backoffLimit, err := getBackoffLimit(openebsNamespace) + if err != nil { + util.Fatal(err.Error()) + } + utaskObj.Status.Retries = utaskObj.Status.Retries + 1 + if utaskObj.Status.Retries == backoffLimit { + utaskObj.Status.Phase = apis.UpgradeError + utaskObj.Status.CompletedTime = metav1.Now() + } + _, err = client.OpenebsV1alpha1().UpgradeTasks(openebsNamespace). + Update(utaskObj) + if err != nil { + util.Fatal(err.Error()) + } + } else { + utaskObj, err := client.OpenebsV1alpha1().UpgradeTasks(openebsNamespace). + Get(cr.Name, metav1.GetOptions{}) + if err != nil { + util.Fatal(err.Error()) + } + utaskObj.Status.Phase = apis.UpgradeSuccess + utaskObj.Status.CompletedTime = metav1.Now() + _, err = client.OpenebsV1alpha1().UpgradeTasks(openebsNamespace). + Update(utaskObj) + if err != nil { + util.Fatal(err.Error()) + } + } + } + }, + } + return cmd +} + +// InitializeFromUpgradeTaskResource will populate the UpgradeOptions from given UpgradeTask +func (u *UpgradeOptions) InitializeFromUpgradeTaskResource( + upgradeTaskCRObj apis.UpgradeTask) error { + + if len(strings.TrimSpace(u.openebsNamespace)) == 0 { + return errors.Errorf("Cannot execute upgrade job: namespace is missing") + } + if len(strings.TrimSpace(upgradeTaskCRObj.Spec.FromVersion)) != 0 { + u.fromVersion = upgradeTaskCRObj.Spec.FromVersion + } + + if len(strings.TrimSpace(upgradeTaskCRObj.Spec.ToVersion)) != 0 { + u.toVersion = upgradeTaskCRObj.Spec.ToVersion + } + + if len(strings.TrimSpace(upgradeTaskCRObj.Spec.ImagePrefix)) != 0 { + u.imageURLPrefix = upgradeTaskCRObj.Spec.ImagePrefix + } + + if len(strings.TrimSpace(upgradeTaskCRObj.Spec.ImageTag)) != 0 { + u.toVersionImageTag = upgradeTaskCRObj.Spec.ImageTag + } + + switch { + case upgradeTaskCRObj.Spec.ResourceSpec.CStorPoolInstance != nil: + u.resourceKind = "cstorpoolinstance" + u.name = upgradeTaskCRObj.Spec.ResourceSpec.CStorPoolInstance.CSPIName + + case upgradeTaskCRObj.Spec.ResourceSpec.CStorPoolCluster != nil: + u.resourceKind = "cstorpoolcluster" + u.name = upgradeTaskCRObj.Spec.ResourceSpec.CStorPoolCluster.CSPCName + + case upgradeTaskCRObj.Spec.ResourceSpec.CStorVolume != nil: + u.resourceKind = "cstorVolume" + u.name = upgradeTaskCRObj.Spec.ResourceSpec.CStorVolume.PVName + } + + return nil +} + +// RunResourceUpgradeChecks will ensure the sanity of the upgradeTask upgrade options +func (u *UpgradeOptions) RunResourceUpgradeChecks(cmd *cobra.Command) error { + if len(strings.TrimSpace(u.name)) == 0 { + return errors.Errorf("Cannot execute upgrade job: resource name is missing") + } + + return nil +} + +// RunResourceUpgrade upgrades the given upgradeTask +func (u *UpgradeOptions) RunResourceUpgrade(cmd *cobra.Command) error { + if version.IsCurrentVersionValid(u.fromVersion) && version.IsDesiredVersionValid(u.toVersion) { + klog.Infof("Upgrading to %s", u.toVersion) + err := upgrade.Exec(u.fromVersion, u.toVersion, + u.resourceKind, + u.name, + u.openebsNamespace, + u.imageURLPrefix, + u.toVersionImageTag) + if err != nil { + return errors.Wrapf(err, "Failed to upgrade %v %v", u.resourceKind, u.name) + } + } else { + return errors.Errorf("Invalid from version %s or to version %s", u.fromVersion, u.toVersion) + } + return nil +} + +func initClient() (openebsclientset.Interface, error) { + cfg, err := rest.InClusterConfig() + if err != nil { + return nil, errors.Wrap(err, "error building kubeconfig") + } + client, err := openebsclientset.NewForConfig(cfg) + if err != nil { + return nil, errors.Wrap(err, "error building openebs clientset") + } + return client, nil +} + +func getBackoffLimit(openebsNamespace string) (int, error) { + cfg, err := rest.InClusterConfig() + if err != nil { + return 0, errors.Wrap(err, "error building kubeconfig") + } + client, err := kubernetes.NewForConfig(cfg) + if err != nil { + return 0, errors.Wrap(err, "error building openebs clientset") + } + podName := os.Getenv("POD_NAME") + podObj, err := client.CoreV1().Pods(openebsNamespace). + Get(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{}) + if err != nil { + return 0, errors.Wrapf(err, "failed to get backoff limit") + } + // if backoffLimit not present it returns the default as 6 + if jobObj.Spec.BackoffLimit == nil { + return 6, nil + } + backoffLimit := int(*jobObj.Spec.BackoffLimit) + return backoffLimit, nil +} diff --git a/cmd/upgrade/executor/setup_job.go b/cmd/upgrade/executor/setup_job.go index e378e5f0..467b23da 100644 --- a/cmd/upgrade/executor/setup_job.go +++ b/cmd/upgrade/executor/setup_job.go @@ -38,6 +38,7 @@ func NewJob() *cobra.Command { cmd.AddCommand( NewUpgradeCStorCSPCJob(), NewUpgradeCStorVolumeJob(), + NewUpgradeResourceJob(), ) cmd.PersistentFlags().StringVarP(&options.fromVersion, diff --git a/cmd/util/env.go b/cmd/util/env.go index 822005df..144f6273 100644 --- a/cmd/util/env.go +++ b/cmd/util/env.go @@ -22,6 +22,7 @@ import ( const ( openebsNamespaceEnv = "OPENEBS_NAMESPACE" + upgradeTaskLabel = "UPGRADE_TASK_LABEL" ) // GetOpenEBSNamespace gets the openebs namespace set to @@ -29,3 +30,9 @@ const ( func GetOpenEBSNamespace() string { return os.Getenv(openebsNamespaceEnv) } + +// GetUpgradeTaskLabel gets the upgradeTask label set to +// the UPGRADE_TASK_LABEL env +func GetUpgradeTaskLabel() string { + return os.Getenv(upgradeTaskLabel) +} diff --git a/pkg/upgrade/upgrader/cstor_cspc.go b/pkg/upgrade/upgrader/cstor_cspc.go index 2f9353a9..08a03fc1 100644 --- a/pkg/upgrade/upgrader/cstor_cspc.go +++ b/pkg/upgrade/upgrader/cstor_cspc.go @@ -19,7 +19,8 @@ package upgrader import ( "time" - apis "github.com/openebs/api/pkg/apis/cstor/v1" + cstor "github.com/openebs/api/pkg/apis/cstor/v1" + apis "github.com/openebs/api/pkg/apis/openebs.io/v1alpha1" "github.com/openebs/upgrade/pkg/upgrade/patch" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/klog" @@ -93,7 +94,7 @@ func getCSPCPatchData(obj *CSPCPatch) error { return err } -func transformCSPC(c *apis.CStorPoolCluster, res *ResourcePatch) error { +func transformCSPC(c *cstor.CStorPoolCluster, res *ResourcePatch) error { c.VersionDetails.Desired = res.To return nil } @@ -135,8 +136,40 @@ func (obj *CSPCPatch) Upgrade() error { ) err = dependant.Upgrade() if err != nil { + utaskObj, uerr := obj.OpenebsClientset.OpenebsV1alpha1(). + UpgradeTasks(obj.OpenebsNamespace). + Get("upgrade-cstor-cspi-"+cspiObj.Name, metav1.GetOptions{}) + if uerr != nil && isUpgradeTaskJob { + return uerr + } + backoffLimit, uerr := getBackoffLimit(obj.OpenebsNamespace, obj.Client) + if uerr != nil && isUpgradeTaskJob { + return uerr + } + utaskObj.Status.Retries = utaskObj.Status.Retries + 1 + if utaskObj.Status.Retries == backoffLimit { + utaskObj.Status.Phase = apis.UpgradeError + utaskObj.Status.CompletedTime = metav1.Now() + } + _, uerr = obj.OpenebsClientset.OpenebsV1alpha1().UpgradeTasks(obj.OpenebsNamespace). + Update(utaskObj) + if uerr != nil && isUpgradeTaskJob { + return uerr + } return err } + utaskObj, uerr := obj.OpenebsClientset.OpenebsV1alpha1().UpgradeTasks(obj.OpenebsNamespace). + Get("upgrade-cstor-cspi-"+cspiObj.Name, metav1.GetOptions{}) + if uerr != nil && isUpgradeTaskJob { + return uerr + } + utaskObj.Status.Phase = apis.UpgradeSuccess + utaskObj.Status.CompletedTime = metav1.Now() + _, uerr = obj.OpenebsClientset.OpenebsV1alpha1().UpgradeTasks(obj.OpenebsNamespace). + Update(utaskObj) + if uerr != nil && isUpgradeTaskJob { + return uerr + } } err = obj.CSPCUpgrade() if err != nil { diff --git a/pkg/upgrade/upgrader/cstor_cspi.go b/pkg/upgrade/upgrader/cstor_cspi.go index 3b12be45..7a5747f1 100644 --- a/pkg/upgrade/upgrader/cstor_cspi.go +++ b/pkg/upgrade/upgrader/cstor_cspi.go @@ -17,11 +17,14 @@ limitations under the License. package upgrader import ( - apis "github.com/openebs/api/pkg/apis/cstor/v1" + "time" + + cstor "github.com/openebs/api/pkg/apis/cstor/v1" + apis "github.com/openebs/api/pkg/apis/openebs.io/v1alpha1" "github.com/openebs/upgrade/pkg/upgrade/patch" + "github.com/pkg/errors" appsv1 "k8s.io/api/apps/v1" "k8s.io/klog" - "time" ) // CSPIPatch is the patch required to upgrade cspi @@ -30,6 +33,7 @@ type CSPIPatch struct { Namespace string Deploy *patch.Deployment CSPI *patch.CSPI + Utask *apis.UpgradeTask *Client } @@ -67,79 +71,159 @@ func NewCSPIPatch(opts ...CSPIPatchOptions) *CSPIPatch { } // PreUpgrade ... -func (obj *CSPIPatch) PreUpgrade() error { +func (obj *CSPIPatch) PreUpgrade() (string, error) { err := obj.Deploy.PreChecks(obj.From, obj.To) if err != nil { - return err + return "failed to verify cstor pool deployment", err } err = obj.CSPI.PreChecks(obj.From, obj.To) - return err + if err != nil { + return "failed to verify cstor pool instance", err + } + return "", nil } // DeployUpgrade ... -func (obj *CSPIPatch) DeployUpgrade() error { +func (obj *CSPIPatch) DeployUpgrade() (string, error) { err := obj.Deploy.Patch(obj.From, obj.To) if err != nil { - return err + return "failed to patch cstor pool deployment", err } - return nil + return "", nil } // CSPIUpgrade ... -func (obj *CSPIPatch) CSPIUpgrade() error { +func (obj *CSPIPatch) CSPIUpgrade() (string, error) { err := obj.CSPI.Patch(obj.From, obj.To) if err != nil { - return err + return "failed to verify cstor pool instance", err } - return nil + return "", nil } // Upgrade execute the steps to upgrade cspi func (obj *CSPIPatch) Upgrade() error { - err := obj.Init() + var err, uerr error + obj.Utask, err = getOrCreateUpgradeTask( + "cstorpoolinstance", + obj.ResourcePatch, + obj.Client, + ) + if uerr != nil && isUpgradeTaskJob { + return uerr + } + statusObj := apis.UpgradeDetailedStatuses{Step: apis.PreUpgrade} + statusObj.Phase = apis.StepWaiting + obj.Utask, uerr = updateUpgradeDetailedStatus(obj.Utask, statusObj, obj.OpenebsNamespace, obj.Client) + if uerr != nil && isUpgradeTaskJob { + return uerr + } + statusObj.Phase = apis.StepErrored + msg, err := obj.Init() if err != nil { - return err + statusObj.Message = msg + statusObj.Reason = err.Error() + obj.Utask, uerr = updateUpgradeDetailedStatus(obj.Utask, statusObj, obj.OpenebsNamespace, obj.Client) + if uerr != nil && isUpgradeTaskJob { + return uerr + } + return errors.Wrap(err, msg) } - err = obj.PreUpgrade() + msg, err = obj.PreUpgrade() if err != nil { - return err + statusObj.Message = msg + statusObj.Reason = err.Error() + obj.Utask, uerr = updateUpgradeDetailedStatus(obj.Utask, statusObj, obj.OpenebsNamespace, obj.Client) + if uerr != nil && isUpgradeTaskJob { + return uerr + } + return errors.Wrap(err, msg) + } + statusObj.Phase = apis.StepCompleted + statusObj.Message = "Pre-upgrade steps were successful" + statusObj.Reason = "" + obj.Utask, uerr = updateUpgradeDetailedStatus(obj.Utask, statusObj, obj.OpenebsNamespace, obj.Client) + if uerr != nil && isUpgradeTaskJob { + return uerr + } + + statusObj = apis.UpgradeDetailedStatuses{Step: apis.PoolInstanceUpgrade} + statusObj.Phase = apis.StepWaiting + obj.Utask, uerr = updateUpgradeDetailedStatus(obj.Utask, statusObj, obj.OpenebsNamespace, obj.Client) + if uerr != nil && isUpgradeTaskJob { + return uerr } - err = obj.DeployUpgrade() + statusObj.Phase = apis.StepErrored + msg, err = obj.DeployUpgrade() if err != nil { - return err + statusObj.Message = msg + statusObj.Reason = err.Error() + obj.Utask, uerr = updateUpgradeDetailedStatus(obj.Utask, statusObj, obj.OpenebsNamespace, obj.Client) + if uerr != nil && isUpgradeTaskJob { + return uerr + } + return errors.Wrap(err, msg) } - err = obj.CSPIUpgrade() + msg, err = obj.CSPIUpgrade() if err != nil { - return err + statusObj.Message = msg + statusObj.Reason = err.Error() + obj.Utask, uerr = updateUpgradeDetailedStatus(obj.Utask, statusObj, obj.OpenebsNamespace, obj.Client) + if uerr != nil && isUpgradeTaskJob { + return uerr + } + return errors.Wrap(err, msg) } - err = obj.verifyCSPIVersionReconcile() - return err + msg, err = obj.verifyCSPIVersionReconcile() + if err != nil { + statusObj.Message = msg + statusObj.Reason = err.Error() + obj.Utask, uerr = updateUpgradeDetailedStatus(obj.Utask, statusObj, obj.OpenebsNamespace, obj.Client) + if uerr != nil && isUpgradeTaskJob { + return uerr + } + return errors.Wrap(err, msg) + } + statusObj.Phase = apis.StepCompleted + statusObj.Message = "Pre-upgrade steps were successful" + statusObj.Reason = "" + obj.Utask, uerr = updateUpgradeDetailedStatus(obj.Utask, statusObj, obj.OpenebsNamespace, obj.Client) + if uerr != nil && isUpgradeTaskJob { + return uerr + } + return nil } // Init initializes all the fields of the CSPIPatch -func (obj *CSPIPatch) Init() error { +func (obj *CSPIPatch) Init() (string, error) { + var err error + statusObj := apis.UpgradeDetailedStatuses{Step: apis.PreUpgrade} + statusObj.Phase = apis.StepErrored obj.Deploy = patch.NewDeployment( patch.WithDeploymentClient(obj.KubeClientset), ) obj.Namespace = obj.OpenebsNamespace label := "openebs.io/cstor-pool-instance=" + obj.Name - err := obj.Deploy.Get(label, obj.Namespace) + err = obj.Deploy.Get(label, obj.Namespace) if err != nil { - return err + return "failed to get cstor pool deployment", err } obj.CSPI = patch.NewCSPI( patch.WithCSPIClient(obj.OpenebsClientset), ) err = obj.CSPI.Get(obj.Name, obj.Namespace) if err != nil { - return err + return "failed to get cstor pool instance", err } err = getCSPIDeployPatchData(obj) if err != nil { - return err + return "failed to create cstor pool deployment patch", err } err = getCSPIPatchData(obj) - return err + if err != nil { + return "failed to create cstor pool instance patch", err + } + return "", nil } func getCSPIDeployPatchData(obobj *CSPIPatch) error { @@ -184,17 +268,17 @@ func getCSPIPatchData(obj *CSPIPatch) error { return err } -func transformCSPI(c *apis.CStorPoolInstance, res *ResourcePatch) error { +func transformCSPI(c *cstor.CStorPoolInstance, res *ResourcePatch) error { c.Labels["openebs.io/version"] = res.To c.VersionDetails.Desired = res.To return nil } -func (obj *CSPIPatch) verifyCSPIVersionReconcile() error { +func (obj *CSPIPatch) verifyCSPIVersionReconcile() (string, error) { // get the latest cspi object err := obj.CSPI.Get(obj.Name, obj.Namespace) if err != nil { - return err + return "failed to get cstor pool to verify ", err } // waiting for the current version to be equal to desired version for obj.CSPI.Object.VersionDetails.Status.Current != obj.To { @@ -203,11 +287,11 @@ func (obj *CSPIPatch) verifyCSPIVersionReconcile() error { time.Sleep(10 * time.Second) err = obj.CSPI.Get(obj.Name, obj.Namespace) if err != nil { - return err + return "failed to get cstor pool to verify ", err } if obj.CSPI.Object.VersionDetails.Status.Message != "" { klog.Errorf("failed to reconcile: %s", obj.CSPI.Object.VersionDetails.Status.Reason) } } - return nil + return "", nil } diff --git a/pkg/upgrade/upgrader/cstor_volume.go b/pkg/upgrade/upgrader/cstor_volume.go index 62680147..e4682c9c 100644 --- a/pkg/upgrade/upgrader/cstor_volume.go +++ b/pkg/upgrade/upgrader/cstor_volume.go @@ -19,8 +19,10 @@ package upgrader import ( "time" - apis "github.com/openebs/api/pkg/apis/cstor/v1" + cstor "github.com/openebs/api/pkg/apis/cstor/v1" + apis "github.com/openebs/api/pkg/apis/openebs.io/v1alpha1" "github.com/openebs/upgrade/pkg/upgrade/patch" + "github.com/pkg/errors" appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -35,6 +37,7 @@ type CStorVolumePatch struct { CV *patch.CV Deploy *patch.Deployment Service *patch.Service + Utask *apis.UpgradeTask *Client } @@ -65,29 +68,32 @@ func NewCStorVolumePatch(opts ...CStorVolumePatchOptions) *CStorVolumePatch { } // PreUpgrade ... -func (obj *CStorVolumePatch) PreUpgrade() error { +func (obj *CStorVolumePatch) PreUpgrade() (string, error) { err := isOperatorUpgraded("cvc-operator", obj.Namespace, obj.To, obj.KubeClientset) if err != nil { - return err + return "failed to verify cvc-operator", err } err = obj.CVC.PreChecks(obj.From, obj.To) if err != nil { - return err + return "failed to verify CVC", err } err = obj.CV.PreChecks(obj.From, obj.To) if err != nil { - return err + return "failed to verify CV", err } err = obj.Deploy.PreChecks(obj.From, obj.To) if err != nil { - return err + return "failed to verify target deploy", err } err = obj.Service.PreChecks(obj.From, obj.To) - return err + if err != nil { + return "failed to verify target svc", err + } + return "", nil } // Init initializes all the fields of the CStorVolumePatch -func (obj *CStorVolumePatch) Init() error { +func (obj *CStorVolumePatch) Init() (string, error) { label := "openebs.io/persistent-volume=" + obj.Name obj.Namespace = obj.OpenebsNamespace obj.CVC = patch.NewCVC( @@ -95,43 +101,46 @@ func (obj *CStorVolumePatch) Init() error { ) err := obj.CVC.Get(obj.Name, obj.Namespace) if err != nil { - return err + return "failed to get CVC for volume" + obj.Name, err } obj.CV = patch.NewCV( patch.WithCVClient(obj.OpenebsClientset), ) err = obj.CV.Get(obj.Name, obj.Namespace) if err != nil { - return err + return "failed to get CV for volume" + obj.Name, err } obj.Deploy = patch.NewDeployment( patch.WithDeploymentClient(obj.KubeClientset), ) err = obj.Deploy.Get(label, obj.Namespace) if err != nil { - return err + return "failed to get target deploy for volume" + obj.Name, err } obj.Service = patch.NewService( patch.WithKubeClient(obj.KubeClientset), ) err = obj.Service.Get(label, obj.Namespace) if err != nil { - return err + return "failed to get target svc for volume" + obj.Name, err } err = getCVCPatchData(obj) if err != nil { - return err + return "failed to create CVC patch for volume" + obj.Name, err } err = getCVPatchData(obj) if err != nil { - return err + return "failed to create CV patch for volume" + obj.Name, err } err = getCVDeployPatchData(obj) if err != nil { - return err + return "failed to target deploy patch for volume" + obj.Name, err } err = getCVServicePatchData(obj) - return err + if err != nil { + return "failed to target svc patch for volume" + obj.Name, err + } + return "", nil } func getCVCPatchData(obj *CStorVolumePatch) error { @@ -144,7 +153,7 @@ func getCVCPatchData(obj *CStorVolumePatch) error { return err } -func transformCVC(c *apis.CStorVolumeConfig, res *ResourcePatch) error { +func transformCVC(c *cstor.CStorVolumeConfig, res *ResourcePatch) error { c.VersionDetails.Desired = res.To return nil } @@ -159,7 +168,7 @@ func getCVPatchData(obj *CStorVolumePatch) error { return err } -func transformCV(c *apis.CStorVolume, res *ResourcePatch) error { +func transformCV(c *cstor.CStorVolume, res *ResourcePatch) error { c.VersionDetails.Desired = res.To return nil } @@ -212,41 +221,87 @@ func transformCVService(svc *corev1.Service, res *ResourcePatch) error { } // CStorVolumeUpgrade ... -func (obj *CStorVolumePatch) CStorVolumeUpgrade() error { +func (obj *CStorVolumePatch) CStorVolumeUpgrade() (string, error) { err := obj.Deploy.Patch(obj.From, obj.To) if err != nil { - return err + return "failed to patch target deploy", err } err = obj.Service.Patch(obj.From, obj.To) if err != nil { - return err + return "failed to patch target svc", err } err = obj.CV.Patch(obj.From, obj.To) if err != nil { - return err + return "failed to patch CV", err } err = obj.verifyCVVersionReconcile() if err != nil { - return err + return "failed to verify version reconcile on CV", err } err = obj.CVC.Patch(obj.From, obj.To) if err != nil { - return err + return "failed to patch CVC", err } err = obj.verifyCVCVersionReconcile() - return err + if err != nil { + return "failed to verify version reconcile on CVC", err + } + return "", nil } // Upgrade execute the steps to upgrade CStorVolume func (obj *CStorVolumePatch) Upgrade() error { - err := obj.Init() + var err, uerr error + obj.Utask, err = getOrCreateUpgradeTask( + "cstorVolume", + obj.ResourcePatch, + obj.Client, + ) + if uerr != nil && isUpgradeTaskJob { + return uerr + } + statusObj := apis.UpgradeDetailedStatuses{Step: apis.PreUpgrade} + statusObj.Phase = apis.StepWaiting + obj.Utask, uerr = updateUpgradeDetailedStatus(obj.Utask, statusObj, obj.OpenebsNamespace, obj.Client) + if uerr != nil && isUpgradeTaskJob { + return uerr + } + statusObj.Phase = apis.StepErrored + msg, err := obj.Init() if err != nil { - return err + statusObj.Message = msg + statusObj.Reason = err.Error() + obj.Utask, uerr = updateUpgradeDetailedStatus(obj.Utask, statusObj, obj.OpenebsNamespace, obj.Client) + if uerr != nil && isUpgradeTaskJob { + return uerr + } + return errors.Wrap(err, msg) } - err = obj.PreUpgrade() + msg, err = obj.PreUpgrade() if err != nil { - return err + statusObj.Message = msg + statusObj.Reason = err.Error() + obj.Utask, uerr = updateUpgradeDetailedStatus(obj.Utask, statusObj, obj.OpenebsNamespace, obj.Client) + if uerr != nil && isUpgradeTaskJob { + return uerr + } + return errors.Wrap(err, msg) + } + statusObj.Phase = apis.StepCompleted + statusObj.Message = "Pre-upgrade steps were successful" + statusObj.Reason = "" + obj.Utask, uerr = updateUpgradeDetailedStatus(obj.Utask, statusObj, obj.OpenebsNamespace, obj.Client) + if uerr != nil && isUpgradeTaskJob { + return uerr + } + + statusObj = apis.UpgradeDetailedStatuses{Step: apis.ReplicaUpgrade} + statusObj.Phase = apis.StepWaiting + obj.Utask, uerr = updateUpgradeDetailedStatus(obj.Utask, statusObj, obj.OpenebsNamespace, obj.Client) + if uerr != nil && isUpgradeTaskJob { + return uerr } + statusObj.Phase = apis.StepErrored res := *obj.ResourcePatch cvrList, err := obj.Client.OpenebsClientset.CstorV1(). CStorVolumeReplicas(obj.Namespace).List( @@ -254,8 +309,15 @@ func (obj *CStorVolumePatch) Upgrade() error { LabelSelector: "openebs.io/persistent-volume=" + obj.Name, }, ) - if err != nil { - return err + if err != nil && isUpgradeTaskJob { + msg = "failed to list cvrs for volume" + statusObj.Message = msg + statusObj.Reason = err.Error() + obj.Utask, uerr = updateUpgradeDetailedStatus(obj.Utask, statusObj, obj.OpenebsNamespace, obj.Client) + if uerr != nil && isUpgradeTaskJob { + return uerr + } + return errors.Wrap(err, msg) } for _, cvrObj := range cvrList.Items { res.Name = cvrObj.Name @@ -265,11 +327,48 @@ func (obj *CStorVolumePatch) Upgrade() error { ) err = dependant.Upgrade() if err != nil { - return err + msg = "failed to patch cvr " + cvrObj.Name + statusObj.Message = msg + statusObj.Reason = err.Error() + obj.Utask, uerr = updateUpgradeDetailedStatus(obj.Utask, statusObj, obj.OpenebsNamespace, obj.Client) + if uerr != nil && isUpgradeTaskJob { + return uerr + } + return errors.Wrap(err, msg) } } - err = obj.CStorVolumeUpgrade() - return err + statusObj.Phase = apis.StepCompleted + statusObj.Message = "Replica upgrade was successful" + statusObj.Reason = "" + obj.Utask, uerr = updateUpgradeDetailedStatus(obj.Utask, statusObj, obj.OpenebsNamespace, obj.Client) + if uerr != nil && isUpgradeTaskJob { + return uerr + } + statusObj = apis.UpgradeDetailedStatuses{Step: apis.TargetUpgrade} + statusObj.Phase = apis.StepWaiting + obj.Utask, uerr = updateUpgradeDetailedStatus(obj.Utask, statusObj, obj.OpenebsNamespace, obj.Client) + if uerr != nil && isUpgradeTaskJob { + return uerr + } + statusObj.Phase = apis.StepErrored + msg, err = obj.CStorVolumeUpgrade() + if err != nil { + statusObj.Message = msg + statusObj.Reason = err.Error() + obj.Utask, uerr = updateUpgradeDetailedStatus(obj.Utask, statusObj, obj.OpenebsNamespace, obj.Client) + if uerr != nil && isUpgradeTaskJob { + return uerr + } + return errors.Wrap(err, msg) + } + statusObj.Phase = apis.StepCompleted + statusObj.Message = "Target upgrade was successful" + statusObj.Reason = "" + obj.Utask, uerr = updateUpgradeDetailedStatus(obj.Utask, statusObj, obj.OpenebsNamespace, obj.Client) + if uerr != nil && isUpgradeTaskJob { + return uerr + } + return nil } func (obj *CStorVolumePatch) verifyCVVersionReconcile() error { diff --git a/pkg/upgrade/upgrader/upgrade.go b/pkg/upgrade/upgrader/upgrade.go index e74dcf84..b5fc1f37 100644 --- a/pkg/upgrade/upgrader/upgrade.go +++ b/pkg/upgrade/upgrader/upgrade.go @@ -17,12 +17,18 @@ limitations under the License. package upgrader import ( + "os" + openebsclientset "github.com/openebs/api/pkg/client/clientset/versioned" "github.com/pkg/errors" "k8s.io/client-go/kubernetes" "k8s.io/client-go/rest" ) +var ( + isUpgradeTaskJob = false +) + // UpgradeOptions ... type UpgradeOptions func(*ResourcePatch, *Client) Upgrader @@ -64,5 +70,8 @@ func NewUpgrade() *Upgrade { } u.initClient() u.RegisterAll() + if os.Getenv("UPGRADE_TASK_LABEL") != "" { + isUpgradeTaskJob = true + } return u } diff --git a/pkg/upgrade/upgrader/upgradetask.go b/pkg/upgrade/upgrader/upgradetask.go new file mode 100644 index 00000000..6597b586 --- /dev/null +++ b/pkg/upgrade/upgrader/upgradetask.go @@ -0,0 +1,178 @@ +/* +Copyright 2020 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 upgrader + +import ( + "os" + + apis "github.com/openebs/api/pkg/apis/openebs.io/v1alpha1" + "github.com/pkg/errors" + k8serror "k8s.io/apimachinery/pkg/api/errors" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +func updateUpgradeDetailedStatus(utaskObj *apis.UpgradeTask, + uStatusObj apis.UpgradeDetailedStatuses, + openebsNamespace string, client *Client, +) (*apis.UpgradeTask, error) { + var err error + if !isValidStatus(uStatusObj) { + return nil, errors.Errorf( + "failed to update upgradetask status: invalid status %v", + uStatusObj, + ) + } + uStatusObj.LastUpdatedTime = metav1.Now() + if uStatusObj.Phase == apis.StepWaiting { + uStatusObj.StartTime = uStatusObj.LastUpdatedTime + utaskObj.Status.UpgradeDetailedStatuses = append( + utaskObj.Status.UpgradeDetailedStatuses, + uStatusObj, + ) + } else { + l := len(utaskObj.Status.UpgradeDetailedStatuses) + uStatusObj.StartTime = utaskObj.Status.UpgradeDetailedStatuses[l-1].StartTime + utaskObj.Status.UpgradeDetailedStatuses[l-1] = uStatusObj + } + utaskObj, err = client.OpenebsClientset.OpenebsV1alpha1(). + UpgradeTasks(openebsNamespace).Update(utaskObj) + if err != nil { + return nil, errors.Wrapf(err, "failed to update upgradetask ") + } + return utaskObj, nil +} + +// isValidStatus is used to validate IsValidStatus +func isValidStatus(o apis.UpgradeDetailedStatuses) bool { + if o.Step == "" { + return false + } + if o.Phase == "" { + return false + } + if o.Message == "" && o.Phase != apis.StepWaiting { + return false + } + if o.Reason == "" && o.Phase == apis.StepErrored { + return false + } + return true +} + +// getOrCreateUpgradeTask fetches upgrade task if provided or creates a new upgradetask CR +func getOrCreateUpgradeTask(kind string, r *ResourcePatch, client *Client) (*apis.UpgradeTask, error) { + var utaskObj *apis.UpgradeTask + var err error + if r.OpenebsNamespace == "" { + return nil, errors.Errorf("missing openebsNamespace") + } + if kind == "" { + return nil, errors.Errorf("missing kind for upgradeTask") + } + if r.Name == "" { + return nil, errors.Errorf("missing name for upgradeTask") + } + utaskObj = buildUpgradeTask(kind, r) + // the below logic first tries to fetch the CR if not found + // then creates a new CR + utaskObj1, err1 := client.OpenebsClientset.OpenebsV1alpha1(). + UpgradeTasks(r.OpenebsNamespace). + Get(utaskObj.Name, metav1.GetOptions{}) + if err1 != nil { + if k8serror.IsNotFound(err1) { + utaskObj, err = client.OpenebsClientset.OpenebsV1alpha1(). + UpgradeTasks(r.OpenebsNamespace).Create(utaskObj) + if err != nil { + return nil, err + } + } else { + return nil, err1 + } + } else { + utaskObj = utaskObj1 + } + + if utaskObj.Status.StartTime.IsZero() { + utaskObj.Status.Phase = apis.UpgradeStarted + utaskObj.Status.StartTime = metav1.Now() + } + + utaskObj.Status.UpgradeDetailedStatuses = []apis.UpgradeDetailedStatuses{} + utaskObj, err = client.OpenebsClientset.OpenebsV1alpha1(). + UpgradeTasks(r.OpenebsNamespace). + Update(utaskObj) + if err != nil { + return nil, errors.Wrapf(err, "failed to update upgradetask") + } + return utaskObj, nil +} + +func buildUpgradeTask(kind string, r *ResourcePatch) *apis.UpgradeTask { + // TODO builder + utaskObj := &apis.UpgradeTask{ + ObjectMeta: metav1.ObjectMeta{ + Namespace: r.OpenebsNamespace, + }, + Spec: apis.UpgradeTaskSpec{ + FromVersion: r.From, + ToVersion: r.To, + ImageTag: r.ImageTag, + ImagePrefix: r.BaseURL, + }, + Status: apis.UpgradeTaskStatus{ + Phase: apis.UpgradeStarted, + StartTime: metav1.Now(), + }, + } + switch kind { + case "cstorpoolinstance": + utaskObj.Name = "upgrade-cstor-cspi-" + r.Name + utaskObj.Spec.ResourceSpec = apis.ResourceSpec{ + CStorPoolInstance: &apis.CStorPoolInstance{ + CSPIName: r.Name, + }, + } + case "cstorVolume": + utaskObj.Name = "upgrade-cstor-csi-volume-" + r.Name + utaskObj.Spec.ResourceSpec = apis.ResourceSpec{ + CStorVolume: &apis.CStorVolume{ + PVName: r.Name, + }, + } + } + return utaskObj +} + +func getBackoffLimit(openebsNamespace string, client *Client) (int, error) { + podName := os.Getenv("POD_NAME") + podObj, err := client.KubeClientset.CoreV1().Pods(openebsNamespace). + Get(podName, metav1.GetOptions{}) + if err != nil { + return 0, errors.Wrapf(err, "failed to get backoff limit") + } + jobObj, err := client.KubeClientset.BatchV1().Jobs(openebsNamespace). + Get(podObj.OwnerReferences[0].Name, metav1.GetOptions{}) + if err != nil { + return 0, errors.Wrapf(err, "failed to get backoff limit") + } + // if backoffLimit not present it returns the default as 6 + if jobObj.Spec.BackoffLimit == nil { + return 6, nil + } + backoffLimit := int(*jobObj.Spec.BackoffLimit) + return backoffLimit, nil +} diff --git a/pkg/version/util.go b/pkg/version/util.go index 0e4b848e..dfc5445f 100644 --- a/pkg/version/util.go +++ b/pkg/version/util.go @@ -6,7 +6,7 @@ import ( var ( validCurrentVersions = map[string]bool{ - "1.9.0": true, "1.10.0": true, + "1.9.0": true, "1.10.0": true, "1.11.0": true, } validDesiredVersion = GetVersion() ) From b847b793e8c800df4a8771923b575c6f42c1012c Mon Sep 17 00:00:00 2001 From: shubham Date: Fri, 26 Jun 2020 16:09:51 +0530 Subject: [PATCH 2/5] update vendor files Signed-off-by: shubham --- go.mod | 2 +- go.sum | 4 +- .../pkg/apis/cstor/v1/cstorpoolinstance.go | 6 + .../pkg/apis/cstor/v1/cstorvolumebuilder.go | 68 ++-- .../pkg/apis/openebs.io/v1alpha1/register.go | 2 + .../openebs.io/v1alpha1/upgradetask_types.go | 225 +++++++++++ .../v1alpha1/zz_generated.deepcopy.go | 352 ++++++++++++++++++ .../openebs/api/pkg/apis/types/types.go | 2 +- .../v1alpha1/generated_expansion.go | 2 + .../openebs.io/v1alpha1/openebs.io_client.go | 5 + .../typed/openebs.io/v1alpha1/upgradetask.go | 191 ++++++++++ vendor/modules.txt | 2 +- 12 files changed, 821 insertions(+), 40 deletions(-) create mode 100644 vendor/github.com/openebs/api/pkg/apis/openebs.io/v1alpha1/upgradetask_types.go create mode 100644 vendor/github.com/openebs/api/pkg/client/clientset/versioned/typed/openebs.io/v1alpha1/upgradetask.go diff --git a/go.mod b/go.mod index 0fa36fe2..46e7414d 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.13 require ( github.com/hashicorp/go-version v1.2.0 github.com/kubernetes-csi/external-snapshotter/v2 v2.1.1 - github.com/openebs/api v1.10.0-RC1.0.20200602151240-2b7d2bdbe1ef + github.com/openebs/api v1.11.1-0.20200625121525-4ef7efa4b876 github.com/openebs/maya v0.0.0-20200602143918-71415115098d github.com/pkg/errors v0.9.1 github.com/spf13/cobra v1.0.0 diff --git a/go.sum b/go.sum index b568ec96..00e2d8bd 100644 --- a/go.sum +++ b/go.sum @@ -175,8 +175,8 @@ github.com/onsi/ginkgo v1.10.2/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+ github.com/onsi/gomega v0.0.0-20170829124025-dcabb60a477c/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA= github.com/onsi/gomega v1.7.0 h1:XPnZz8VVBHjVsy1vzJmRwIcSwiUO+JFfrv/xGiigmME= github.com/onsi/gomega v1.7.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= -github.com/openebs/api v1.10.0-RC1.0.20200602151240-2b7d2bdbe1ef h1:p66ZTG26pNr7TIxOMLmXvJcKjmIxIa+xsQ5Xw0hhJA4= -github.com/openebs/api v1.10.0-RC1.0.20200602151240-2b7d2bdbe1ef/go.mod h1:TASujm6H1LGdx43MN7Dab1xdAqR7MVU8bsS74Ywop5w= +github.com/openebs/api v1.11.1-0.20200625121525-4ef7efa4b876 h1:c6HE7cROx9mC+yJ8h9SO8J1PPAxEatbpw+vH9TpSWj0= +github.com/openebs/api v1.11.1-0.20200625121525-4ef7efa4b876/go.mod h1:TASujm6H1LGdx43MN7Dab1xdAqR7MVU8bsS74Ywop5w= github.com/openebs/maya v0.0.0-20200602143918-71415115098d h1:o8RIc8RzeZkUlzYM+Sg07wRdekIHytCTMaAhFl8Yams= github.com/openebs/maya v0.0.0-20200602143918-71415115098d/go.mod h1:QQY9cOHKQwZ73qbv6O//UYUBLNV2S0MRDIfG7t5KOCk= github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= diff --git a/vendor/github.com/openebs/api/pkg/apis/cstor/v1/cstorpoolinstance.go b/vendor/github.com/openebs/api/pkg/apis/cstor/v1/cstorpoolinstance.go index cbabe611..77983e67 100644 --- a/vendor/github.com/openebs/api/pkg/apis/cstor/v1/cstorpoolinstance.go +++ b/vendor/github.com/openebs/api/pkg/apis/cstor/v1/cstorpoolinstance.go @@ -106,6 +106,12 @@ type CStorPoolInstanceStatus struct { Capacity CStorPoolInstanceCapacity `json:"capacity"` //ReadOnly if pool is readOnly or not ReadOnly bool `json:"readOnly"` + // ProvisionedReplicas describes the total count of Volume Replicas + // present in the cstor pool + ProvisionedReplicas int32 `json:"provisionedReplicas"` + // HealthyReplicas describes the total count of healthy Volume Replicas + // in the cstor pool + HealthyReplicas int32 `json:"healthyReplicas"` } // CStorPoolInstanceCapacity stores the pool capacity related attributes. diff --git a/vendor/github.com/openebs/api/pkg/apis/cstor/v1/cstorvolumebuilder.go b/vendor/github.com/openebs/api/pkg/apis/cstor/v1/cstorvolumebuilder.go index 4d991e71..24ab4323 100644 --- a/vendor/github.com/openebs/api/pkg/apis/cstor/v1/cstorvolumebuilder.go +++ b/vendor/github.com/openebs/api/pkg/apis/cstor/v1/cstorvolumebuilder.go @@ -19,7 +19,6 @@ package v1 import ( "fmt" "strings" - "sync" "github.com/openebs/api/pkg/apis/types" "github.com/openebs/api/pkg/util" @@ -40,11 +39,7 @@ const ( CStorVolumeReplicaFinalizer = "cstorvolumereplica.openebs.io/finalizer" ) -var ( - // ConfFileMutex is to hold the lock while updating istgt.conf file - ConfFileMutex = &sync.Mutex{} -) - +// NewCStorVolumeConfig returns new instance of CStorVolumeConfig func NewCStorVolumeConfig() *CStorVolumeConfig { return &CStorVolumeConfig{} } @@ -83,7 +78,7 @@ func (cvc *CStorVolumeConfig) WithAnnotations(annotations map[string]string) *CS return cvc } -// WithLacvelsNew sets the Lacvels field of CVC with provided arguments +// WithLabelsNew sets the Lacvels field of CVC with provided arguments func (cvc *CStorVolumeConfig) WithLabelsNew(labels map[string]string) *CStorVolumeConfig { cvc.Labels = make(map[string]string) for key, value := range labels { @@ -92,7 +87,7 @@ func (cvc *CStorVolumeConfig) WithLabelsNew(labels map[string]string) *CStorVolu return cvc } -// WithLacvels appends or overwrites existing Lacvels +// WithLabels appends or overwrites existing Lacvels // values of CVC with provided arguments func (cvc *CStorVolumeConfig) WithLabels(labels map[string]string) *CStorVolumeConfig { if cvc.Labels == nil { @@ -165,6 +160,7 @@ func IsScaleDownInProgress(cv *CStorVolume) bool { // // ************************************************************************** +// NewCStorVolume returns new instance of CStorVolume func NewCStorVolume() *CStorVolume { return &CStorVolume{} } @@ -208,7 +204,7 @@ func (cv *CStorVolume) WithAnnotations(annotations map[string]string) *CStorVolu return cv } -// WithLacvelsNew sets the Lacvels field of CV with provided arguments +// WithLabelsNew sets the Lacvels field of CV with provided arguments func (cv *CStorVolume) WithLabelsNew(labels map[string]string) *CStorVolume { cv.Labels = make(map[string]string) for key, value := range labels { @@ -217,7 +213,7 @@ func (cv *CStorVolume) WithLabelsNew(labels map[string]string) *CStorVolume { return cv } -// WithLacvels appends or overwrites existing Lacvels +// WithLabels appends or overwrites existing Lacvels // values of CVC with provided arguments func (cv *CStorVolume) WithLabels(labels map[string]string) *CStorVolume { if cv.Labels == nil { @@ -229,7 +225,7 @@ func (cv *CStorVolume) WithLabels(labels map[string]string) *CStorVolume { return cv } -// WithFinalizer sets the finalizer field in the CV +// WithFinalizers sets the finalizer field in the CV func (cv *CStorVolume) WithFinalizers(finalizers ...string) *CStorVolume { cv.Finalizers = append(cv.Finalizers, finalizers...) return cv @@ -324,9 +320,9 @@ func (cv *CStorVolume) RemoveFinalizer(finalizer string) { } // IsResizePending return true if resize is in progress -func (c *CStorVolume) IsResizePending() bool { - curCapacity := c.Status.Capacity - desiredCapacity := c.Spec.Capacity +func (cv *CStorVolume) IsResizePending() bool { + curCapacity := cv.Status.Capacity + desiredCapacity := cv.Spec.Capacity // Cmp returns 0 if the curCapacity is equal to desiredCapacity, // -1 if the curCapacity is less than desiredCapacity, or 1 if the // curCapacity is greater than desiredCapacity. @@ -337,12 +333,12 @@ func (c *CStorVolume) IsResizePending() bool { // Steps to verify whether drf is required // 1. Read DesiredReplicationFactor configurations from istgt conf file // 2. Compare the value with spec.DesiredReplicationFactor and return result -func (c *CStorVolume) IsDRFPending() bool { +func (cv *CStorVolume) IsDRFPending() bool { fileOperator := util.RealFileOperator{} - ConfFileMutex.Lock() + types.ConfFileMutex.Lock() //If it has proper config then we will get --> " DesiredReplicationFactor 3" i, gotConfig, err := fileOperator.GetLineDetails(types.IstgtConfPath, types.DesiredReplicationFactorKey) - ConfFileMutex.Unlock() + types.ConfFileMutex.Unlock() if err != nil || i == -1 { klog.Infof("failed to get %s config details error: %v", types.DesiredReplicationFactorKey, @@ -350,21 +346,21 @@ func (c *CStorVolume) IsDRFPending() bool { ) return false } - drfStringValue := fmt.Sprintf(" %d", c.Spec.DesiredReplicationFactor) + drfStringValue := fmt.Sprintf(" %d", cv.Spec.DesiredReplicationFactor) // gotConfig will have " DesiredReplicationFactor 3" and we will extract // numeric character from output if !strings.HasSuffix(gotConfig, drfStringValue) { return true } // reconciliation check for replica scaledown scenarion - return (len(c.Spec.ReplicaDetails.KnownReplicas) < - len(c.Status.ReplicaDetails.KnownReplicas)) + return (len(cv.Spec.ReplicaDetails.KnownReplicas) < + len(cv.Status.ReplicaDetails.KnownReplicas)) } // GetCVCondition returns corresponding cstorvolume condition based argument passed -func (c *CStorVolume) GetCVCondition( +func (cv *CStorVolume) GetCVCondition( condType CStorVolumeConditionType) CStorVolumeCondition { - for _, cond := range c.Status.Conditions { + for _, cond := range cv.Status.Conditions { if condType == cond.Type { return cond } @@ -373,8 +369,8 @@ func (c *CStorVolume) GetCVCondition( } // IsConditionPresent returns true if condition is available -func (c *CStorVolume) IsConditionPresent(condType CStorVolumeConditionType) bool { - for _, cond := range c.Status.Conditions { +func (cv *CStorVolume) IsConditionPresent(condType CStorVolumeConditionType) bool { + for _, cond := range cv.Status.Conditions { if condType == cond.Type { return true } @@ -384,10 +380,10 @@ func (c *CStorVolume) IsConditionPresent(condType CStorVolumeConditionType) bool // AreSpecReplicasHealthy return true if all the spec replicas are in Healthy // state else return false -func (c *CStorVolume) AreSpecReplicasHealthy(volStatus *CVStatus) bool { +func (cv *CStorVolume) AreSpecReplicasHealthy(volStatus *CVStatus) bool { var isReplicaExist bool var replicaInfo ReplicaStatus - for _, replicaValue := range c.Spec.ReplicaDetails.KnownReplicas { + for _, replicaValue := range cv.Spec.ReplicaDetails.KnownReplicas { isReplicaExist = false for _, replicaInfo = range volStatus.ReplicaStatuses { if replicaInfo.ID == replicaValue { @@ -403,12 +399,12 @@ func (c *CStorVolume) AreSpecReplicasHealthy(volStatus *CVStatus) bool { } // GetRemovingReplicaID return replicaID that present in status but not in spec -func (c *CStorVolume) GetRemovingReplicaID() string { - for repID := range c.Status.ReplicaDetails.KnownReplicas { +func (cv *CStorVolume) GetRemovingReplicaID() string { + for repID := range cv.Status.ReplicaDetails.KnownReplicas { // If known replica is not exist in spec but if it exist in status then // user/operator selected that replica for removal if _, isReplicaExist := - c.Spec.ReplicaDetails.KnownReplicas[repID]; !isReplicaExist { + cv.Spec.ReplicaDetails.KnownReplicas[repID]; !isReplicaExist { return string(repID) } } @@ -416,9 +412,9 @@ func (c *CStorVolume) GetRemovingReplicaID() string { } // BuildScaleDownConfigData build data based on replica that needs to remove -func (c *CStorVolume) BuildScaleDownConfigData(repID string) map[string]string { +func (cv *CStorVolume) BuildScaleDownConfigData(repID string) map[string]string { configData := map[string]string{} - newReplicationFactor := c.Spec.DesiredReplicationFactor + newReplicationFactor := cv.Spec.DesiredReplicationFactor newConsistencyFactor := (newReplicationFactor / 2) + 1 key := fmt.Sprintf(" ReplicationFactor") value := fmt.Sprintf(" ReplicationFactor %d", newReplicationFactor) @@ -428,7 +424,7 @@ func (c *CStorVolume) BuildScaleDownConfigData(repID string) map[string]string { configData[key] = value key = fmt.Sprintf(" DesiredReplicationFactor") value = fmt.Sprintf(" DesiredReplicationFactor %d", - c.Spec.DesiredReplicationFactor) + cv.Spec.DesiredReplicationFactor) configData[key] = value key = fmt.Sprintf(" Replica %s", repID) value = fmt.Sprintf("") @@ -486,6 +482,7 @@ func GetResizeCondition() CStorVolumeCondition { // // // **************************************************************************** + // SetErrorStatus sets the message and reason for the error func (vs *VersionStatus) SetErrorStatus(msg string, err error) { vs.Message = msg @@ -516,6 +513,7 @@ func (vd *VersionDetails) SetSuccessStatus() { // // ************************************************************************** +// NewCStorVolumeReplica returns new instance of CStorVolumeReplica func NewCStorVolumeReplica() *CStorVolumeReplica { return &CStorVolumeReplica{} } @@ -554,7 +552,7 @@ func (cvr *CStorVolumeReplica) WithAnnotations(annotations map[string]string) *C return cvr } -// WithLacvrelsNew sets the Lacvrels field of CV with provided arguments +// WithLabelsNew sets the Lacvrels field of CV with provided arguments func (cvr *CStorVolumeReplica) WithLabelsNew(labels map[string]string) *CStorVolumeReplica { cvr.Labels = make(map[string]string) for key, value := range labels { @@ -563,7 +561,7 @@ func (cvr *CStorVolumeReplica) WithLabelsNew(labels map[string]string) *CStorVol return cvr } -// WithLacvrels appends or overwrites existing Lacvrels +// WithLabels appends or overwrites existing Lacvrels // values of CVC with provided arguments func (cvr *CStorVolumeReplica) WithLabels(labels map[string]string) *CStorVolumeReplica { if cvr.Labels == nil { @@ -575,7 +573,7 @@ func (cvr *CStorVolumeReplica) WithLabels(labels map[string]string) *CStorVolume return cvr } -// WithFinalizer sets the finalizer field in the CV +// WithFinalizers sets the finalizer field in the CV func (cvr *CStorVolumeReplica) WithFinalizers(finalizers ...string) *CStorVolumeReplica { cvr.Finalizers = append(cvr.Finalizers, finalizers...) return cvr diff --git a/vendor/github.com/openebs/api/pkg/apis/openebs.io/v1alpha1/register.go b/vendor/github.com/openebs/api/pkg/apis/openebs.io/v1alpha1/register.go index 024e44d1..8a5ed3a3 100644 --- a/vendor/github.com/openebs/api/pkg/apis/openebs.io/v1alpha1/register.go +++ b/vendor/github.com/openebs/api/pkg/apis/openebs.io/v1alpha1/register.go @@ -64,6 +64,8 @@ func addKnownTypes(scheme *runtime.Scheme) error { &CStorCompletedBackupList{}, &CStorRestore{}, &CStorRestoreList{}, + &UpgradeTask{}, + &UpgradeTaskList{}, ) metav1.AddToGroupVersion(scheme, SchemeGroupVersion) return nil diff --git a/vendor/github.com/openebs/api/pkg/apis/openebs.io/v1alpha1/upgradetask_types.go b/vendor/github.com/openebs/api/pkg/apis/openebs.io/v1alpha1/upgradetask_types.go new file mode 100644 index 00000000..1aa1d1da --- /dev/null +++ b/vendor/github.com/openebs/api/pkg/apis/openebs.io/v1alpha1/upgradetask_types.go @@ -0,0 +1,225 @@ +/* +Copyright 2020 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 v1alpha1 + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +// +genclient +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object +// +resource:path=upgradetask +// +k8s:openapi-gen=true + +// UpgradeTask represents an upgrade task +type UpgradeTask struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata,omitempty"` + // Spec i.e. specifications of the UpgradeTask + Spec UpgradeTaskSpec `json:"spec"` + // Status of UpgradeTask + Status UpgradeTaskStatus `json:"status"` +} + +// UpgradeTaskSpec is the properties of an upgrade task +type UpgradeTaskSpec struct { + // FromVersion is the current version of the resource. + FromVersion string `json:"fromVersion"` + // ToVersion is the upgraded version of the resource. It should be same + // as the version of control plane components version. + ToVersion string `json:"toVersion"` + // Options contains the optional flags that can be passed during upgrade. + Options *Options `json:"options,omitempty"` + // ResourceSpec contains the details of the resource that has to upgraded. + ResourceSpec `json:",inline"` + // ImagePrefix contains the url prefix of the image url. This field is + // optional. If not present upgrade takes the previously present ImagePrefix. + ImagePrefix string `json:"imagePrefix"` + // ImageTag contains the customized tag for ToVersion if any. This field is + // optional. If not present upgrade takes the ToVersion as the ImageTag + ImageTag string `json:"imageTag"` +} + +// Options provides additional optional arguments +type Options struct { + // Timeout is maximum seconds to wait at any given step in the upgrade + Timeout int `json:"timeout,omitempty"` +} + +// ResourceSpec is the type of resource which is to be upgraded. +// Exactly one of its members must be set. +type ResourceSpec struct { + // JivaVolume contains the details of the jiva volume to be upgraded + JivaVolume *JivaVolume `json:"jivaVolume,omitempty"` + // CStorVolume contains the details of the cstor volume to be upgraded + CStorVolume *CStorVolume `json:"cstorVolume,omitempty"` + // CStorPool contains the details of the cstor pool to be upgraded + CStorPool *CStorPool `json:"cstorPool,omitempty"` + // StoragePoolClaim contains the details of the storage pool claim to be upgraded + StoragePoolClaim *StoragePoolClaim `json:"storagePoolClaim,omitempty"` + // CStorPoolInstance contains the details of the cstor pool to be upgraded + CStorPoolInstance *CStorPoolInstance `json:"cstorPoolInstance,omitempty"` + // CStorPoolCluster contains the details of the storage pool claim to be upgraded + CStorPoolCluster *CStorPoolCluster `json:"cstorPoolCluster,omitempty"` +} + +// JivaVolume is the ResourceType for jiva volume +type JivaVolume struct { + // PVName contains the name of the pv associated with the jiva volume + PVName string `json:"pvName,omitempty"` + // Options can be used to change the default behaviour of upgrade + Options *ResourceOptions `json:"options,omitempty"` +} + +// CStorVolume is the ResourceType for cstor volume +type CStorVolume struct { + // PVName contains the name of the pv associated with the cstor volume + PVName string `json:"pvName,omitempty"` + // Options can be used to change the default behaviour of upgrade + Options *ResourceOptions `json:"options,omitempty"` +} + +// CStorPoolCluster is the ResourceType for cstor pool cluster +type CStorPoolCluster struct { + // CSPCName contains the name of the storage pool claim to be upgraded + CSPCName string `json:"cspcName,omitempty"` + // Options can be used to change the default behaviour of upgrade + Options *ResourceOptions `json:"options,omitempty"` +} + +// CStorPool is the ResourceType for cstor pool +type CStorPool struct { + // PoolName contains the name of the cstor pool to be upgraded + PoolName string `json:"poolName,omitempty"` + // Options can be used to change the default behaviour of upgrade + Options *ResourceOptions `json:"options,omitempty"` +} + +// StoragePoolClaim is the ResourceType for storage pool claim +type StoragePoolClaim struct { + // SPCName contains the name of the storage pool claim to be upgraded + SPCName string `json:"spcName,omitempty"` + // Options can be used to change the default behaviour of upgrade + Options *ResourceOptions `json:"options,omitempty"` +} + +// CStorPoolInstance is the ResourceType for cstor pool cluster +type CStorPoolInstance struct { + // CSPCName contains the name of the storage pool claim to be upgraded + CSPIName string `json:"cspiName,omitempty"` + // Options can be used to change the default behaviour of upgrade + Options *ResourceOptions `json:"options,omitempty"` +} + +// ResourceOptions provides additional options for a particular resource +type ResourceOptions struct { + // IgnoreStepsOnError allows to ignore steps which failed + IgnoreStepsOnError []string `json:"ignoreStepsOnError,omitempty"` +} + +// UpgradeTaskStatus provides status of a upgradeTask +type UpgradeTaskStatus struct { + // Phase indicates if a upgradeTask is started, success or errored + Phase UpgradePhase `json:"phase,omitempty"` + // StartTime of Upgrade + StartTime metav1.Time `json:"startTime,omitempty"` + // CompletedTime of Upgrade + CompletedTime metav1.Time `json:"completedTime,omitempty"` + // UpgradeDetailedStatuses contains the list of statuses of each step + UpgradeDetailedStatuses []UpgradeDetailedStatuses `json:"upgradeDetailedStatuses,omitempty"` + // Retries is the number of times the job attempted to upgrade the resource + Retries int `json:"retries"` +} + +// UpgradeDetailedStatuses represents the latest available observations +// of a UpgradeTask current state. +type UpgradeDetailedStatuses struct { + Step UpgradeStep `json:"step,omitempty"` + // StartTime of a UpgradeStep + StartTime metav1.Time `json:"startTime,omitempty"` + // LastUpdatedTime of a UpgradeStep + LastUpdatedTime metav1.Time `json:"lastUpdatedAt,omitempty"` + // Status of a UpgradeStep + Status `json:",inline"` +} + +// Status represents the state of the step performed during the upgrade. +type Status struct { + // Phase indicates if the UpgradeStep is waiting, errored or completed. + Phase StepPhase `json:"phase,omitempty"` + // A human-readable message indicating details about why the upgradeStep + // is in this state + Message string `json:"message,omitempty"` + // Reason is a brief CamelCase string that describes any failure and is meant + // for machine parsing and tidy display in the CLI + Reason string `json:"reason,omitempty"` +} + +// UpgradeStep is the current step being performed for a particular resource upgrade +type UpgradeStep string + +const ( + // PreUpgrade is the step to verify resource before upgrade + PreUpgrade UpgradeStep = "PRE_UPGRADE" + // TargetUpgrade is the step to upgrade Target depoyment of resource + TargetUpgrade UpgradeStep = "TARGET_UPGRADE" + // ReplicaUpgrade is the step to upgrade replica deployment of resource + ReplicaUpgrade UpgradeStep = "REPLICA_UPGRADE" + // Verify is the step to verify the upgrade + Verify UpgradeStep = "VERIFY" + // Rollback is the step to rollback to previous version if upgrade fails + Rollback UpgradeStep = "ROLLBACK" + // PoolInstanceUpgrade is the step to upgrade a pool (CSP or CSPI and it's deployment) + PoolInstanceUpgrade UpgradeStep = "POOL_INSTANCE_UPGRADE" +) + +// StepPhase defines the phase of a UpgradeStep +type StepPhase string + +const ( + // StepWaiting - used for upgrade step that not yet complete + StepWaiting StepPhase = "Waiting" + // StepErrored - used for upgrade step that failed + StepErrored StepPhase = "Errored" + // StepCompleted - used for upgrade step that completed successfully + StepCompleted StepPhase = "Completed" +) + +// UpgradePhase defines phase of a UpgradeTask +type UpgradePhase string + +const ( + // UpgradeStarted - used for Upgrades that are Started + UpgradeStarted UpgradePhase = "Started" + // UpgradeSuccess - used for Upgrades that are not available + UpgradeSuccess UpgradePhase = "Success" + // UpgradeError - used for Upgrades that Error for some reason + UpgradeError UpgradePhase = "Error" +) + +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object +// +resource:path=upgradetasks +// +k8s:openapi-gen=true + +// UpgradeTaskList is a list of UpgradeTask resources +type UpgradeTaskList struct { + metav1.TypeMeta `json:",inline"` + metav1.ListMeta `json:"metadata,omitempty"` + + // Items are the list of upgrade task items + Items []UpgradeTask `json:"items"` +} diff --git a/vendor/github.com/openebs/api/pkg/apis/openebs.io/v1alpha1/zz_generated.deepcopy.go b/vendor/github.com/openebs/api/pkg/apis/openebs.io/v1alpha1/zz_generated.deepcopy.go index 4c9847c1..3f82f935 100644 --- a/vendor/github.com/openebs/api/pkg/apis/openebs.io/v1alpha1/zz_generated.deepcopy.go +++ b/vendor/github.com/openebs/api/pkg/apis/openebs.io/v1alpha1/zz_generated.deepcopy.go @@ -300,6 +300,69 @@ func (in *CStorCompletedBackupList) DeepCopyObject() runtime.Object { return nil } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *CStorPool) DeepCopyInto(out *CStorPool) { + *out = *in + if in.Options != nil { + in, out := &in.Options, &out.Options + *out = new(ResourceOptions) + (*in).DeepCopyInto(*out) + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CStorPool. +func (in *CStorPool) DeepCopy() *CStorPool { + if in == nil { + return nil + } + out := new(CStorPool) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *CStorPoolCluster) DeepCopyInto(out *CStorPoolCluster) { + *out = *in + if in.Options != nil { + in, out := &in.Options, &out.Options + *out = new(ResourceOptions) + (*in).DeepCopyInto(*out) + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CStorPoolCluster. +func (in *CStorPoolCluster) DeepCopy() *CStorPoolCluster { + if in == nil { + return nil + } + out := new(CStorPoolCluster) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *CStorPoolInstance) DeepCopyInto(out *CStorPoolInstance) { + *out = *in + if in.Options != nil { + in, out := &in.Options, &out.Options + *out = new(ResourceOptions) + (*in).DeepCopyInto(*out) + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CStorPoolInstance. +func (in *CStorPoolInstance) DeepCopy() *CStorPoolInstance { + if in == nil { + return nil + } + out := new(CStorPoolInstance) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *CStorRestore) DeepCopyInto(out *CStorRestore) { *out = *in @@ -377,6 +440,27 @@ func (in *CStorRestoreSpec) DeepCopy() *CStorRestoreSpec { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *CStorVolume) DeepCopyInto(out *CStorVolume) { + *out = *in + if in.Options != nil { + in, out := &in.Options, &out.Options + *out = new(ResourceOptions) + (*in).DeepCopyInto(*out) + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CStorVolume. +func (in *CStorVolume) DeepCopy() *CStorVolume { + if in == nil { + return nil + } + out := new(CStorVolume) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *DeviceCapacity) DeepCopyInto(out *DeviceCapacity) { *out = *in @@ -573,6 +657,27 @@ func (in *FileSystemInfo) DeepCopy() *FileSystemInfo { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *JivaVolume) DeepCopyInto(out *JivaVolume) { + *out = *in + if in.Options != nil { + in, out := &in.Options, &out.Options + *out = new(ResourceOptions) + (*in).DeepCopyInto(*out) + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new JivaVolume. +func (in *JivaVolume) DeepCopy() *JivaVolume { + if in == nil { + return nil + } + out := new(JivaVolume) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *NodeAttribute) DeepCopyInto(out *NodeAttribute) { *out = *in @@ -588,3 +693,250 @@ func (in *NodeAttribute) DeepCopy() *NodeAttribute { in.DeepCopyInto(out) return out } + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Options) DeepCopyInto(out *Options) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Options. +func (in *Options) DeepCopy() *Options { + if in == nil { + return nil + } + out := new(Options) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ResourceOptions) DeepCopyInto(out *ResourceOptions) { + *out = *in + if in.IgnoreStepsOnError != nil { + in, out := &in.IgnoreStepsOnError, &out.IgnoreStepsOnError + *out = make([]string, len(*in)) + copy(*out, *in) + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ResourceOptions. +func (in *ResourceOptions) DeepCopy() *ResourceOptions { + if in == nil { + return nil + } + out := new(ResourceOptions) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ResourceSpec) DeepCopyInto(out *ResourceSpec) { + *out = *in + if in.JivaVolume != nil { + in, out := &in.JivaVolume, &out.JivaVolume + *out = new(JivaVolume) + (*in).DeepCopyInto(*out) + } + if in.CStorVolume != nil { + in, out := &in.CStorVolume, &out.CStorVolume + *out = new(CStorVolume) + (*in).DeepCopyInto(*out) + } + if in.CStorPool != nil { + in, out := &in.CStorPool, &out.CStorPool + *out = new(CStorPool) + (*in).DeepCopyInto(*out) + } + if in.StoragePoolClaim != nil { + in, out := &in.StoragePoolClaim, &out.StoragePoolClaim + *out = new(StoragePoolClaim) + (*in).DeepCopyInto(*out) + } + if in.CStorPoolInstance != nil { + in, out := &in.CStorPoolInstance, &out.CStorPoolInstance + *out = new(CStorPoolInstance) + (*in).DeepCopyInto(*out) + } + if in.CStorPoolCluster != nil { + in, out := &in.CStorPoolCluster, &out.CStorPoolCluster + *out = new(CStorPoolCluster) + (*in).DeepCopyInto(*out) + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ResourceSpec. +func (in *ResourceSpec) DeepCopy() *ResourceSpec { + if in == nil { + return nil + } + out := new(ResourceSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Status) DeepCopyInto(out *Status) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Status. +func (in *Status) DeepCopy() *Status { + if in == nil { + return nil + } + out := new(Status) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *StoragePoolClaim) DeepCopyInto(out *StoragePoolClaim) { + *out = *in + if in.Options != nil { + in, out := &in.Options, &out.Options + *out = new(ResourceOptions) + (*in).DeepCopyInto(*out) + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new StoragePoolClaim. +func (in *StoragePoolClaim) DeepCopy() *StoragePoolClaim { + if in == nil { + return nil + } + out := new(StoragePoolClaim) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *UpgradeDetailedStatuses) DeepCopyInto(out *UpgradeDetailedStatuses) { + *out = *in + in.StartTime.DeepCopyInto(&out.StartTime) + in.LastUpdatedTime.DeepCopyInto(&out.LastUpdatedTime) + out.Status = in.Status + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new UpgradeDetailedStatuses. +func (in *UpgradeDetailedStatuses) DeepCopy() *UpgradeDetailedStatuses { + if in == nil { + return nil + } + out := new(UpgradeDetailedStatuses) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *UpgradeTask) DeepCopyInto(out *UpgradeTask) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + in.Spec.DeepCopyInto(&out.Spec) + in.Status.DeepCopyInto(&out.Status) + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new UpgradeTask. +func (in *UpgradeTask) DeepCopy() *UpgradeTask { + if in == nil { + return nil + } + out := new(UpgradeTask) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *UpgradeTask) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *UpgradeTaskList) DeepCopyInto(out *UpgradeTaskList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]UpgradeTask, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new UpgradeTaskList. +func (in *UpgradeTaskList) DeepCopy() *UpgradeTaskList { + if in == nil { + return nil + } + out := new(UpgradeTaskList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *UpgradeTaskList) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *UpgradeTaskSpec) DeepCopyInto(out *UpgradeTaskSpec) { + *out = *in + if in.Options != nil { + in, out := &in.Options, &out.Options + *out = new(Options) + **out = **in + } + in.ResourceSpec.DeepCopyInto(&out.ResourceSpec) + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new UpgradeTaskSpec. +func (in *UpgradeTaskSpec) DeepCopy() *UpgradeTaskSpec { + if in == nil { + return nil + } + out := new(UpgradeTaskSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *UpgradeTaskStatus) DeepCopyInto(out *UpgradeTaskStatus) { + *out = *in + in.StartTime.DeepCopyInto(&out.StartTime) + in.CompletedTime.DeepCopyInto(&out.CompletedTime) + if in.UpgradeDetailedStatuses != nil { + in, out := &in.UpgradeDetailedStatuses, &out.UpgradeDetailedStatuses + *out = make([]UpgradeDetailedStatuses, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new UpgradeTaskStatus. +func (in *UpgradeTaskStatus) DeepCopy() *UpgradeTaskStatus { + if in == nil { + return nil + } + out := new(UpgradeTaskStatus) + in.DeepCopyInto(out) + return out +} diff --git a/vendor/github.com/openebs/api/pkg/apis/types/types.go b/vendor/github.com/openebs/api/pkg/apis/types/types.go index ff364054..0604088c 100644 --- a/vendor/github.com/openebs/api/pkg/apis/types/types.go +++ b/vendor/github.com/openebs/api/pkg/apis/types/types.go @@ -113,7 +113,7 @@ const ( // children objects with OpenEBSDisableReconcileKey as true or false OpenEBSDisableDependantsReconcileKey = "reconcile.openebs.io/disable-dependants" - // OpenEBSCStorExistingPoolName is the name of the cstor pool already present on + // OpenEBSCStorExistingPoolName is the name of the cstor pool already present on // the disk that needs to be imported and renamed OpenEBSCStorExistingPoolName = "import.cspi.cstor.openebs.io/existing-pool-name" ) diff --git a/vendor/github.com/openebs/api/pkg/client/clientset/versioned/typed/openebs.io/v1alpha1/generated_expansion.go b/vendor/github.com/openebs/api/pkg/client/clientset/versioned/typed/openebs.io/v1alpha1/generated_expansion.go index 4d527902..96e32a76 100644 --- a/vendor/github.com/openebs/api/pkg/client/clientset/versioned/typed/openebs.io/v1alpha1/generated_expansion.go +++ b/vendor/github.com/openebs/api/pkg/client/clientset/versioned/typed/openebs.io/v1alpha1/generated_expansion.go @@ -27,3 +27,5 @@ type CStorBackupExpansion interface{} type CStorCompletedBackupExpansion interface{} type CStorRestoreExpansion interface{} + +type UpgradeTaskExpansion interface{} diff --git a/vendor/github.com/openebs/api/pkg/client/clientset/versioned/typed/openebs.io/v1alpha1/openebs.io_client.go b/vendor/github.com/openebs/api/pkg/client/clientset/versioned/typed/openebs.io/v1alpha1/openebs.io_client.go index 926e1b60..96edcb21 100644 --- a/vendor/github.com/openebs/api/pkg/client/clientset/versioned/typed/openebs.io/v1alpha1/openebs.io_client.go +++ b/vendor/github.com/openebs/api/pkg/client/clientset/versioned/typed/openebs.io/v1alpha1/openebs.io_client.go @@ -31,6 +31,7 @@ type OpenebsV1alpha1Interface interface { CStorBackupsGetter CStorCompletedBackupsGetter CStorRestoresGetter + UpgradeTasksGetter } // OpenebsV1alpha1Client is used to interact with features provided by the openebs.io group. @@ -58,6 +59,10 @@ func (c *OpenebsV1alpha1Client) CStorRestores(namespace string) CStorRestoreInte return newCStorRestores(c, namespace) } +func (c *OpenebsV1alpha1Client) UpgradeTasks(namespace string) UpgradeTaskInterface { + return newUpgradeTasks(c, namespace) +} + // NewForConfig creates a new OpenebsV1alpha1Client for the given config. func NewForConfig(c *rest.Config) (*OpenebsV1alpha1Client, error) { config := *c diff --git a/vendor/github.com/openebs/api/pkg/client/clientset/versioned/typed/openebs.io/v1alpha1/upgradetask.go b/vendor/github.com/openebs/api/pkg/client/clientset/versioned/typed/openebs.io/v1alpha1/upgradetask.go new file mode 100644 index 00000000..5751921d --- /dev/null +++ b/vendor/github.com/openebs/api/pkg/client/clientset/versioned/typed/openebs.io/v1alpha1/upgradetask.go @@ -0,0 +1,191 @@ +/* +Copyright 2020 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. +*/ + +// Code generated by client-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + "time" + + v1alpha1 "github.com/openebs/api/pkg/apis/openebs.io/v1alpha1" + scheme "github.com/openebs/api/pkg/client/clientset/versioned/scheme" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + types "k8s.io/apimachinery/pkg/types" + watch "k8s.io/apimachinery/pkg/watch" + rest "k8s.io/client-go/rest" +) + +// UpgradeTasksGetter has a method to return a UpgradeTaskInterface. +// A group's client should implement this interface. +type UpgradeTasksGetter interface { + UpgradeTasks(namespace string) UpgradeTaskInterface +} + +// UpgradeTaskInterface has methods to work with UpgradeTask resources. +type UpgradeTaskInterface interface { + Create(*v1alpha1.UpgradeTask) (*v1alpha1.UpgradeTask, error) + Update(*v1alpha1.UpgradeTask) (*v1alpha1.UpgradeTask, error) + UpdateStatus(*v1alpha1.UpgradeTask) (*v1alpha1.UpgradeTask, error) + Delete(name string, options *v1.DeleteOptions) error + DeleteCollection(options *v1.DeleteOptions, listOptions v1.ListOptions) error + Get(name string, options v1.GetOptions) (*v1alpha1.UpgradeTask, error) + List(opts v1.ListOptions) (*v1alpha1.UpgradeTaskList, error) + Watch(opts v1.ListOptions) (watch.Interface, error) + Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1alpha1.UpgradeTask, err error) + UpgradeTaskExpansion +} + +// upgradeTasks implements UpgradeTaskInterface +type upgradeTasks struct { + client rest.Interface + ns string +} + +// newUpgradeTasks returns a UpgradeTasks +func newUpgradeTasks(c *OpenebsV1alpha1Client, namespace string) *upgradeTasks { + return &upgradeTasks{ + client: c.RESTClient(), + ns: namespace, + } +} + +// Get takes name of the upgradeTask, and returns the corresponding upgradeTask object, and an error if there is any. +func (c *upgradeTasks) Get(name string, options v1.GetOptions) (result *v1alpha1.UpgradeTask, err error) { + result = &v1alpha1.UpgradeTask{} + err = c.client.Get(). + Namespace(c.ns). + Resource("upgradetasks"). + Name(name). + VersionedParams(&options, scheme.ParameterCodec). + Do(). + Into(result) + return +} + +// List takes label and field selectors, and returns the list of UpgradeTasks that match those selectors. +func (c *upgradeTasks) List(opts v1.ListOptions) (result *v1alpha1.UpgradeTaskList, err error) { + var timeout time.Duration + if opts.TimeoutSeconds != nil { + timeout = time.Duration(*opts.TimeoutSeconds) * time.Second + } + result = &v1alpha1.UpgradeTaskList{} + err = c.client.Get(). + Namespace(c.ns). + Resource("upgradetasks"). + VersionedParams(&opts, scheme.ParameterCodec). + Timeout(timeout). + Do(). + Into(result) + return +} + +// Watch returns a watch.Interface that watches the requested upgradeTasks. +func (c *upgradeTasks) Watch(opts v1.ListOptions) (watch.Interface, error) { + var timeout time.Duration + if opts.TimeoutSeconds != nil { + timeout = time.Duration(*opts.TimeoutSeconds) * time.Second + } + opts.Watch = true + return c.client.Get(). + Namespace(c.ns). + Resource("upgradetasks"). + VersionedParams(&opts, scheme.ParameterCodec). + Timeout(timeout). + Watch() +} + +// Create takes the representation of a upgradeTask and creates it. Returns the server's representation of the upgradeTask, and an error, if there is any. +func (c *upgradeTasks) Create(upgradeTask *v1alpha1.UpgradeTask) (result *v1alpha1.UpgradeTask, err error) { + result = &v1alpha1.UpgradeTask{} + err = c.client.Post(). + Namespace(c.ns). + Resource("upgradetasks"). + Body(upgradeTask). + Do(). + Into(result) + return +} + +// Update takes the representation of a upgradeTask and updates it. Returns the server's representation of the upgradeTask, and an error, if there is any. +func (c *upgradeTasks) Update(upgradeTask *v1alpha1.UpgradeTask) (result *v1alpha1.UpgradeTask, err error) { + result = &v1alpha1.UpgradeTask{} + err = c.client.Put(). + Namespace(c.ns). + Resource("upgradetasks"). + Name(upgradeTask.Name). + Body(upgradeTask). + Do(). + Into(result) + return +} + +// UpdateStatus was generated because the type contains a Status member. +// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). + +func (c *upgradeTasks) UpdateStatus(upgradeTask *v1alpha1.UpgradeTask) (result *v1alpha1.UpgradeTask, err error) { + result = &v1alpha1.UpgradeTask{} + err = c.client.Put(). + Namespace(c.ns). + Resource("upgradetasks"). + Name(upgradeTask.Name). + SubResource("status"). + Body(upgradeTask). + Do(). + Into(result) + return +} + +// Delete takes name of the upgradeTask and deletes it. Returns an error if one occurs. +func (c *upgradeTasks) Delete(name string, options *v1.DeleteOptions) error { + return c.client.Delete(). + Namespace(c.ns). + Resource("upgradetasks"). + Name(name). + Body(options). + Do(). + Error() +} + +// DeleteCollection deletes a collection of objects. +func (c *upgradeTasks) DeleteCollection(options *v1.DeleteOptions, listOptions v1.ListOptions) error { + var timeout time.Duration + if listOptions.TimeoutSeconds != nil { + timeout = time.Duration(*listOptions.TimeoutSeconds) * time.Second + } + return c.client.Delete(). + Namespace(c.ns). + Resource("upgradetasks"). + VersionedParams(&listOptions, scheme.ParameterCodec). + Timeout(timeout). + Body(options). + Do(). + Error() +} + +// Patch applies the patch and returns the patched upgradeTask. +func (c *upgradeTasks) Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1alpha1.UpgradeTask, err error) { + result = &v1alpha1.UpgradeTask{} + err = c.client.Patch(pt). + Namespace(c.ns). + Resource("upgradetasks"). + SubResource(subresources...). + Name(name). + Body(data). + Do(). + Into(result) + return +} diff --git a/vendor/modules.txt b/vendor/modules.txt index 7f36bc5c..5a7eff7f 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -38,7 +38,7 @@ github.com/matttproud/golang_protobuf_extensions/pbutil github.com/modern-go/concurrent # github.com/modern-go/reflect2 v1.0.1 github.com/modern-go/reflect2 -# github.com/openebs/api v1.10.0-RC1.0.20200602151240-2b7d2bdbe1ef +# github.com/openebs/api v1.11.1-0.20200625121525-4ef7efa4b876 github.com/openebs/api/pkg/apis/cstor github.com/openebs/api/pkg/apis/cstor/v1 github.com/openebs/api/pkg/apis/openebs.io From 649bfc4fb806e420a3e42443bb9f56270d0e9c40 Mon Sep 17 00:00:00 2001 From: shubham Date: Mon, 29 Jun 2020 19:03:16 +0530 Subject: [PATCH 3/5] renamed imports for v1aplha1 apis Signed-off-by: shubham --- cmd/upgrade/executor/resource.go | 8 +++--- pkg/upgrade/upgrader/cstor_cspc.go | 6 ++-- pkg/upgrade/upgrader/cstor_cspi.go | 24 ++++++++-------- pkg/upgrade/upgrader/cstor_volume.go | 28 +++++++++---------- pkg/upgrade/upgrader/upgradetask.go | 42 ++++++++++++++-------------- 5 files changed, 54 insertions(+), 54 deletions(-) diff --git a/cmd/upgrade/executor/resource.go b/cmd/upgrade/executor/resource.go index 8521fadc..4eb3f4e9 100644 --- a/cmd/upgrade/executor/resource.go +++ b/cmd/upgrade/executor/resource.go @@ -23,7 +23,7 @@ import ( "k8s.io/client-go/rest" "k8s.io/klog" - apis "github.com/openebs/api/pkg/apis/openebs.io/v1alpha1" + v1Alpha1API "github.com/openebs/api/pkg/apis/openebs.io/v1alpha1" openebsclientset "github.com/openebs/api/pkg/client/clientset/versioned" "github.com/openebs/maya/pkg/util" cmdUtil "github.com/openebs/upgrade/cmd/util" @@ -87,7 +87,7 @@ func NewUpgradeResourceJob() *cobra.Command { } utaskObj.Status.Retries = utaskObj.Status.Retries + 1 if utaskObj.Status.Retries == backoffLimit { - utaskObj.Status.Phase = apis.UpgradeError + utaskObj.Status.Phase = v1Alpha1API.UpgradeError utaskObj.Status.CompletedTime = metav1.Now() } _, err = client.OpenebsV1alpha1().UpgradeTasks(openebsNamespace). @@ -101,7 +101,7 @@ func NewUpgradeResourceJob() *cobra.Command { if err != nil { util.Fatal(err.Error()) } - utaskObj.Status.Phase = apis.UpgradeSuccess + utaskObj.Status.Phase = v1Alpha1API.UpgradeSuccess utaskObj.Status.CompletedTime = metav1.Now() _, err = client.OpenebsV1alpha1().UpgradeTasks(openebsNamespace). Update(utaskObj) @@ -117,7 +117,7 @@ func NewUpgradeResourceJob() *cobra.Command { // InitializeFromUpgradeTaskResource will populate the UpgradeOptions from given UpgradeTask func (u *UpgradeOptions) InitializeFromUpgradeTaskResource( - upgradeTaskCRObj apis.UpgradeTask) error { + upgradeTaskCRObj v1Alpha1API.UpgradeTask) error { if len(strings.TrimSpace(u.openebsNamespace)) == 0 { return errors.Errorf("Cannot execute upgrade job: namespace is missing") diff --git a/pkg/upgrade/upgrader/cstor_cspc.go b/pkg/upgrade/upgrader/cstor_cspc.go index 08a03fc1..f1acc00b 100644 --- a/pkg/upgrade/upgrader/cstor_cspc.go +++ b/pkg/upgrade/upgrader/cstor_cspc.go @@ -20,7 +20,7 @@ import ( "time" cstor "github.com/openebs/api/pkg/apis/cstor/v1" - apis "github.com/openebs/api/pkg/apis/openebs.io/v1alpha1" + v1Alpha1API "github.com/openebs/api/pkg/apis/openebs.io/v1alpha1" "github.com/openebs/upgrade/pkg/upgrade/patch" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/klog" @@ -148,7 +148,7 @@ func (obj *CSPCPatch) Upgrade() error { } utaskObj.Status.Retries = utaskObj.Status.Retries + 1 if utaskObj.Status.Retries == backoffLimit { - utaskObj.Status.Phase = apis.UpgradeError + utaskObj.Status.Phase = v1Alpha1API.UpgradeError utaskObj.Status.CompletedTime = metav1.Now() } _, uerr = obj.OpenebsClientset.OpenebsV1alpha1().UpgradeTasks(obj.OpenebsNamespace). @@ -163,7 +163,7 @@ func (obj *CSPCPatch) Upgrade() error { if uerr != nil && isUpgradeTaskJob { return uerr } - utaskObj.Status.Phase = apis.UpgradeSuccess + utaskObj.Status.Phase = v1Alpha1API.UpgradeSuccess utaskObj.Status.CompletedTime = metav1.Now() _, uerr = obj.OpenebsClientset.OpenebsV1alpha1().UpgradeTasks(obj.OpenebsNamespace). Update(utaskObj) diff --git a/pkg/upgrade/upgrader/cstor_cspi.go b/pkg/upgrade/upgrader/cstor_cspi.go index 7a5747f1..518fa9be 100644 --- a/pkg/upgrade/upgrader/cstor_cspi.go +++ b/pkg/upgrade/upgrader/cstor_cspi.go @@ -20,7 +20,7 @@ import ( "time" cstor "github.com/openebs/api/pkg/apis/cstor/v1" - apis "github.com/openebs/api/pkg/apis/openebs.io/v1alpha1" + v1Alpha1API "github.com/openebs/api/pkg/apis/openebs.io/v1alpha1" "github.com/openebs/upgrade/pkg/upgrade/patch" "github.com/pkg/errors" appsv1 "k8s.io/api/apps/v1" @@ -33,7 +33,7 @@ type CSPIPatch struct { Namespace string Deploy *patch.Deployment CSPI *patch.CSPI - Utask *apis.UpgradeTask + Utask *v1Alpha1API.UpgradeTask *Client } @@ -112,13 +112,13 @@ func (obj *CSPIPatch) Upgrade() error { if uerr != nil && isUpgradeTaskJob { return uerr } - statusObj := apis.UpgradeDetailedStatuses{Step: apis.PreUpgrade} - statusObj.Phase = apis.StepWaiting + statusObj := v1Alpha1API.UpgradeDetailedStatuses{Step: v1Alpha1API.PreUpgrade} + statusObj.Phase = v1Alpha1API.StepWaiting obj.Utask, uerr = updateUpgradeDetailedStatus(obj.Utask, statusObj, obj.OpenebsNamespace, obj.Client) if uerr != nil && isUpgradeTaskJob { return uerr } - statusObj.Phase = apis.StepErrored + statusObj.Phase = v1Alpha1API.StepErrored msg, err := obj.Init() if err != nil { statusObj.Message = msg @@ -139,7 +139,7 @@ func (obj *CSPIPatch) Upgrade() error { } return errors.Wrap(err, msg) } - statusObj.Phase = apis.StepCompleted + statusObj.Phase = v1Alpha1API.StepCompleted statusObj.Message = "Pre-upgrade steps were successful" statusObj.Reason = "" obj.Utask, uerr = updateUpgradeDetailedStatus(obj.Utask, statusObj, obj.OpenebsNamespace, obj.Client) @@ -147,13 +147,13 @@ func (obj *CSPIPatch) Upgrade() error { return uerr } - statusObj = apis.UpgradeDetailedStatuses{Step: apis.PoolInstanceUpgrade} - statusObj.Phase = apis.StepWaiting + statusObj = v1Alpha1API.UpgradeDetailedStatuses{Step: v1Alpha1API.PoolInstanceUpgrade} + statusObj.Phase = v1Alpha1API.StepWaiting obj.Utask, uerr = updateUpgradeDetailedStatus(obj.Utask, statusObj, obj.OpenebsNamespace, obj.Client) if uerr != nil && isUpgradeTaskJob { return uerr } - statusObj.Phase = apis.StepErrored + statusObj.Phase = v1Alpha1API.StepErrored msg, err = obj.DeployUpgrade() if err != nil { statusObj.Message = msg @@ -184,7 +184,7 @@ func (obj *CSPIPatch) Upgrade() error { } return errors.Wrap(err, msg) } - statusObj.Phase = apis.StepCompleted + statusObj.Phase = v1Alpha1API.StepCompleted statusObj.Message = "Pre-upgrade steps were successful" statusObj.Reason = "" obj.Utask, uerr = updateUpgradeDetailedStatus(obj.Utask, statusObj, obj.OpenebsNamespace, obj.Client) @@ -197,8 +197,8 @@ func (obj *CSPIPatch) Upgrade() error { // Init initializes all the fields of the CSPIPatch func (obj *CSPIPatch) Init() (string, error) { var err error - statusObj := apis.UpgradeDetailedStatuses{Step: apis.PreUpgrade} - statusObj.Phase = apis.StepErrored + statusObj := v1Alpha1API.UpgradeDetailedStatuses{Step: v1Alpha1API.PreUpgrade} + statusObj.Phase = v1Alpha1API.StepErrored obj.Deploy = patch.NewDeployment( patch.WithDeploymentClient(obj.KubeClientset), ) diff --git a/pkg/upgrade/upgrader/cstor_volume.go b/pkg/upgrade/upgrader/cstor_volume.go index e4682c9c..6124ae08 100644 --- a/pkg/upgrade/upgrader/cstor_volume.go +++ b/pkg/upgrade/upgrader/cstor_volume.go @@ -20,7 +20,7 @@ import ( "time" cstor "github.com/openebs/api/pkg/apis/cstor/v1" - apis "github.com/openebs/api/pkg/apis/openebs.io/v1alpha1" + v1Alpha1API "github.com/openebs/api/pkg/apis/openebs.io/v1alpha1" "github.com/openebs/upgrade/pkg/upgrade/patch" "github.com/pkg/errors" appsv1 "k8s.io/api/apps/v1" @@ -37,7 +37,7 @@ type CStorVolumePatch struct { CV *patch.CV Deploy *patch.Deployment Service *patch.Service - Utask *apis.UpgradeTask + Utask *v1Alpha1API.UpgradeTask *Client } @@ -260,13 +260,13 @@ func (obj *CStorVolumePatch) Upgrade() error { if uerr != nil && isUpgradeTaskJob { return uerr } - statusObj := apis.UpgradeDetailedStatuses{Step: apis.PreUpgrade} - statusObj.Phase = apis.StepWaiting + statusObj := v1Alpha1API.UpgradeDetailedStatuses{Step: v1Alpha1API.PreUpgrade} + statusObj.Phase = v1Alpha1API.StepWaiting obj.Utask, uerr = updateUpgradeDetailedStatus(obj.Utask, statusObj, obj.OpenebsNamespace, obj.Client) if uerr != nil && isUpgradeTaskJob { return uerr } - statusObj.Phase = apis.StepErrored + statusObj.Phase = v1Alpha1API.StepErrored msg, err := obj.Init() if err != nil { statusObj.Message = msg @@ -287,7 +287,7 @@ func (obj *CStorVolumePatch) Upgrade() error { } return errors.Wrap(err, msg) } - statusObj.Phase = apis.StepCompleted + statusObj.Phase = v1Alpha1API.StepCompleted statusObj.Message = "Pre-upgrade steps were successful" statusObj.Reason = "" obj.Utask, uerr = updateUpgradeDetailedStatus(obj.Utask, statusObj, obj.OpenebsNamespace, obj.Client) @@ -295,13 +295,13 @@ func (obj *CStorVolumePatch) Upgrade() error { return uerr } - statusObj = apis.UpgradeDetailedStatuses{Step: apis.ReplicaUpgrade} - statusObj.Phase = apis.StepWaiting + statusObj = v1Alpha1API.UpgradeDetailedStatuses{Step: v1Alpha1API.ReplicaUpgrade} + statusObj.Phase = v1Alpha1API.StepWaiting obj.Utask, uerr = updateUpgradeDetailedStatus(obj.Utask, statusObj, obj.OpenebsNamespace, obj.Client) if uerr != nil && isUpgradeTaskJob { return uerr } - statusObj.Phase = apis.StepErrored + statusObj.Phase = v1Alpha1API.StepErrored res := *obj.ResourcePatch cvrList, err := obj.Client.OpenebsClientset.CstorV1(). CStorVolumeReplicas(obj.Namespace).List( @@ -337,20 +337,20 @@ func (obj *CStorVolumePatch) Upgrade() error { return errors.Wrap(err, msg) } } - statusObj.Phase = apis.StepCompleted + statusObj.Phase = v1Alpha1API.StepCompleted statusObj.Message = "Replica upgrade was successful" statusObj.Reason = "" obj.Utask, uerr = updateUpgradeDetailedStatus(obj.Utask, statusObj, obj.OpenebsNamespace, obj.Client) if uerr != nil && isUpgradeTaskJob { return uerr } - statusObj = apis.UpgradeDetailedStatuses{Step: apis.TargetUpgrade} - statusObj.Phase = apis.StepWaiting + statusObj = v1Alpha1API.UpgradeDetailedStatuses{Step: v1Alpha1API.TargetUpgrade} + statusObj.Phase = v1Alpha1API.StepWaiting obj.Utask, uerr = updateUpgradeDetailedStatus(obj.Utask, statusObj, obj.OpenebsNamespace, obj.Client) if uerr != nil && isUpgradeTaskJob { return uerr } - statusObj.Phase = apis.StepErrored + statusObj.Phase = v1Alpha1API.StepErrored msg, err = obj.CStorVolumeUpgrade() if err != nil { statusObj.Message = msg @@ -361,7 +361,7 @@ func (obj *CStorVolumePatch) Upgrade() error { } return errors.Wrap(err, msg) } - statusObj.Phase = apis.StepCompleted + statusObj.Phase = v1Alpha1API.StepCompleted statusObj.Message = "Target upgrade was successful" statusObj.Reason = "" obj.Utask, uerr = updateUpgradeDetailedStatus(obj.Utask, statusObj, obj.OpenebsNamespace, obj.Client) diff --git a/pkg/upgrade/upgrader/upgradetask.go b/pkg/upgrade/upgrader/upgradetask.go index 6597b586..481f8d9c 100644 --- a/pkg/upgrade/upgrader/upgradetask.go +++ b/pkg/upgrade/upgrader/upgradetask.go @@ -19,16 +19,16 @@ package upgrader import ( "os" - apis "github.com/openebs/api/pkg/apis/openebs.io/v1alpha1" + v1Alpha1API "github.com/openebs/api/pkg/apis/openebs.io/v1alpha1" "github.com/pkg/errors" k8serror "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) -func updateUpgradeDetailedStatus(utaskObj *apis.UpgradeTask, - uStatusObj apis.UpgradeDetailedStatuses, +func updateUpgradeDetailedStatus(utaskObj *v1Alpha1API.UpgradeTask, + uStatusObj v1Alpha1API.UpgradeDetailedStatuses, openebsNamespace string, client *Client, -) (*apis.UpgradeTask, error) { +) (*v1Alpha1API.UpgradeTask, error) { var err error if !isValidStatus(uStatusObj) { return nil, errors.Errorf( @@ -37,7 +37,7 @@ func updateUpgradeDetailedStatus(utaskObj *apis.UpgradeTask, ) } uStatusObj.LastUpdatedTime = metav1.Now() - if uStatusObj.Phase == apis.StepWaiting { + if uStatusObj.Phase == v1Alpha1API.StepWaiting { uStatusObj.StartTime = uStatusObj.LastUpdatedTime utaskObj.Status.UpgradeDetailedStatuses = append( utaskObj.Status.UpgradeDetailedStatuses, @@ -57,25 +57,25 @@ func updateUpgradeDetailedStatus(utaskObj *apis.UpgradeTask, } // isValidStatus is used to validate IsValidStatus -func isValidStatus(o apis.UpgradeDetailedStatuses) bool { +func isValidStatus(o v1Alpha1API.UpgradeDetailedStatuses) bool { if o.Step == "" { return false } if o.Phase == "" { return false } - if o.Message == "" && o.Phase != apis.StepWaiting { + if o.Message == "" && o.Phase != v1Alpha1API.StepWaiting { return false } - if o.Reason == "" && o.Phase == apis.StepErrored { + if o.Reason == "" && o.Phase == v1Alpha1API.StepErrored { return false } return true } // getOrCreateUpgradeTask fetches upgrade task if provided or creates a new upgradetask CR -func getOrCreateUpgradeTask(kind string, r *ResourcePatch, client *Client) (*apis.UpgradeTask, error) { - var utaskObj *apis.UpgradeTask +func getOrCreateUpgradeTask(kind string, r *ResourcePatch, client *Client) (*v1Alpha1API.UpgradeTask, error) { + var utaskObj *v1Alpha1API.UpgradeTask var err error if r.OpenebsNamespace == "" { return nil, errors.Errorf("missing openebsNamespace") @@ -107,11 +107,11 @@ func getOrCreateUpgradeTask(kind string, r *ResourcePatch, client *Client) (*api } if utaskObj.Status.StartTime.IsZero() { - utaskObj.Status.Phase = apis.UpgradeStarted + utaskObj.Status.Phase = v1Alpha1API.UpgradeStarted utaskObj.Status.StartTime = metav1.Now() } - utaskObj.Status.UpgradeDetailedStatuses = []apis.UpgradeDetailedStatuses{} + utaskObj.Status.UpgradeDetailedStatuses = []v1Alpha1API.UpgradeDetailedStatuses{} utaskObj, err = client.OpenebsClientset.OpenebsV1alpha1(). UpgradeTasks(r.OpenebsNamespace). Update(utaskObj) @@ -121,35 +121,35 @@ func getOrCreateUpgradeTask(kind string, r *ResourcePatch, client *Client) (*api return utaskObj, nil } -func buildUpgradeTask(kind string, r *ResourcePatch) *apis.UpgradeTask { +func buildUpgradeTask(kind string, r *ResourcePatch) *v1Alpha1API.UpgradeTask { // TODO builder - utaskObj := &apis.UpgradeTask{ + utaskObj := &v1Alpha1API.UpgradeTask{ ObjectMeta: metav1.ObjectMeta{ Namespace: r.OpenebsNamespace, }, - Spec: apis.UpgradeTaskSpec{ + Spec: v1Alpha1API.UpgradeTaskSpec{ FromVersion: r.From, ToVersion: r.To, ImageTag: r.ImageTag, ImagePrefix: r.BaseURL, }, - Status: apis.UpgradeTaskStatus{ - Phase: apis.UpgradeStarted, + Status: v1Alpha1API.UpgradeTaskStatus{ + Phase: v1Alpha1API.UpgradeStarted, StartTime: metav1.Now(), }, } switch kind { case "cstorpoolinstance": utaskObj.Name = "upgrade-cstor-cspi-" + r.Name - utaskObj.Spec.ResourceSpec = apis.ResourceSpec{ - CStorPoolInstance: &apis.CStorPoolInstance{ + utaskObj.Spec.ResourceSpec = v1Alpha1API.ResourceSpec{ + CStorPoolInstance: &v1Alpha1API.CStorPoolInstance{ CSPIName: r.Name, }, } case "cstorVolume": utaskObj.Name = "upgrade-cstor-csi-volume-" + r.Name - utaskObj.Spec.ResourceSpec = apis.ResourceSpec{ - CStorVolume: &apis.CStorVolume{ + utaskObj.Spec.ResourceSpec = v1Alpha1API.ResourceSpec{ + CStorVolume: &v1Alpha1API.CStorVolume{ PVName: r.Name, }, } From c49889674dd8e78a20be0b77a3cb313bc9edd9a1 Mon Sep 17 00:00:00 2001 From: shubham Date: Tue, 30 Jun 2020 10:06:48 +0530 Subject: [PATCH 4/5] fix success message for cspi Signed-off-by: shubham --- pkg/upgrade/upgrader/cstor_cspi.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/upgrade/upgrader/cstor_cspi.go b/pkg/upgrade/upgrader/cstor_cspi.go index 518fa9be..7a10dd16 100644 --- a/pkg/upgrade/upgrader/cstor_cspi.go +++ b/pkg/upgrade/upgrader/cstor_cspi.go @@ -185,7 +185,7 @@ func (obj *CSPIPatch) Upgrade() error { return errors.Wrap(err, msg) } statusObj.Phase = v1Alpha1API.StepCompleted - statusObj.Message = "Pre-upgrade steps were successful" + statusObj.Message = "Pool instance upgrade was successful" statusObj.Reason = "" obj.Utask, uerr = updateUpgradeDetailedStatus(obj.Utask, statusObj, obj.OpenebsNamespace, obj.Client) if uerr != nil && isUpgradeTaskJob { From 2279d74a335f788b05fe7ad4cdfe28bdd9747822 Mon Sep 17 00:00:00 2001 From: shubham Date: Thu, 2 Jul 2020 11:09:10 +0530 Subject: [PATCH 5/5] addressed review comments Signed-off-by: shubham --- cmd/upgrade/executor/cstor_cspc.go | 2 +- cmd/upgrade/executor/resource.go | 4 ++-- pkg/upgrade/upgrader/cstor_cspi.go | 2 +- pkg/upgrade/upgrader/cstor_volume.go | 4 ++-- pkg/upgrade/upgrader/register.go | 4 ++-- pkg/upgrade/upgrader/upgradetask.go | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/cmd/upgrade/executor/cstor_cspc.go b/cmd/upgrade/executor/cstor_cspc.go index a0aa5ed1..5edaa9bb 100644 --- a/cmd/upgrade/executor/cstor_cspc.go +++ b/cmd/upgrade/executor/cstor_cspc.go @@ -47,7 +47,7 @@ func NewUpgradeCStorCSPCJob() *cobra.Command { util.Fatal("failed to upgrade: no cspc name provided") } for _, name := range args { - options.resourceKind = "cstorpoolcluster" + options.resourceKind = "cstorPoolCluster" util.CheckErr(options.RunPreFlightChecks(cmd), util.Fatal) util.CheckErr(options.InitializeDefaults(cmd), util.Fatal) util.CheckErr(options.RunCStorCSPCUpgrade(cmd, name), util.Fatal) diff --git a/cmd/upgrade/executor/resource.go b/cmd/upgrade/executor/resource.go index 4eb3f4e9..5908986b 100644 --- a/cmd/upgrade/executor/resource.go +++ b/cmd/upgrade/executor/resource.go @@ -140,11 +140,11 @@ func (u *UpgradeOptions) InitializeFromUpgradeTaskResource( switch { case upgradeTaskCRObj.Spec.ResourceSpec.CStorPoolInstance != nil: - u.resourceKind = "cstorpoolinstance" + u.resourceKind = "cstorPoolInstance" u.name = upgradeTaskCRObj.Spec.ResourceSpec.CStorPoolInstance.CSPIName case upgradeTaskCRObj.Spec.ResourceSpec.CStorPoolCluster != nil: - u.resourceKind = "cstorpoolcluster" + u.resourceKind = "cstorPoolCluster" u.name = upgradeTaskCRObj.Spec.ResourceSpec.CStorPoolCluster.CSPCName case upgradeTaskCRObj.Spec.ResourceSpec.CStorVolume != nil: diff --git a/pkg/upgrade/upgrader/cstor_cspi.go b/pkg/upgrade/upgrader/cstor_cspi.go index 7a10dd16..01d2549e 100644 --- a/pkg/upgrade/upgrader/cstor_cspi.go +++ b/pkg/upgrade/upgrader/cstor_cspi.go @@ -105,7 +105,7 @@ func (obj *CSPIPatch) CSPIUpgrade() (string, error) { func (obj *CSPIPatch) Upgrade() error { var err, uerr error obj.Utask, err = getOrCreateUpgradeTask( - "cstorpoolinstance", + "cstorPoolInstance", obj.ResourcePatch, obj.Client, ) diff --git a/pkg/upgrade/upgrader/cstor_volume.go b/pkg/upgrade/upgrader/cstor_volume.go index 6124ae08..014f464d 100644 --- a/pkg/upgrade/upgrader/cstor_volume.go +++ b/pkg/upgrade/upgrader/cstor_volume.go @@ -134,11 +134,11 @@ func (obj *CStorVolumePatch) Init() (string, error) { } err = getCVDeployPatchData(obj) if err != nil { - return "failed to target deploy patch for volume" + obj.Name, err + return "failed to create target deploy patch for volume" + obj.Name, err } err = getCVServicePatchData(obj) if err != nil { - return "failed to target svc patch for volume" + obj.Name, err + return "failed to create target svc patch for volume" + obj.Name, err } return "", nil } diff --git a/pkg/upgrade/upgrader/register.go b/pkg/upgrade/upgrader/register.go index 3d52268d..cbdf9224 100644 --- a/pkg/upgrade/upgrader/register.go +++ b/pkg/upgrade/upgrader/register.go @@ -23,8 +23,8 @@ func (u *Upgrade) registerUpgrade(kind string, obj UpgradeOptions) *Upgrade { // RegisterAll ... func (u *Upgrade) RegisterAll() *Upgrade { - u.registerUpgrade("cstorpoolinstance", RegisterCstorPoolInstance) - u.registerUpgrade("cstorpoolcluster", RegisterCstorPoolCluster) + u.registerUpgrade("cstorPoolInstance", RegisterCstorPoolInstance) + u.registerUpgrade("cstorPoolCluster", RegisterCstorPoolCluster) u.registerUpgrade("cstorVolume", RegisterCstorVolume) // u.registerUpgrade("jivaVolume", RegisterJivaVolume) return u diff --git a/pkg/upgrade/upgrader/upgradetask.go b/pkg/upgrade/upgrader/upgradetask.go index 481f8d9c..6ae5d6d2 100644 --- a/pkg/upgrade/upgrader/upgradetask.go +++ b/pkg/upgrade/upgrader/upgradetask.go @@ -139,7 +139,7 @@ func buildUpgradeTask(kind string, r *ResourcePatch) *v1Alpha1API.UpgradeTask { }, } switch kind { - case "cstorpoolinstance": + case "cstorPoolInstance": utaskObj.Name = "upgrade-cstor-cspi-" + r.Name utaskObj.Spec.ResourceSpec = v1Alpha1API.ResourceSpec{ CStorPoolInstance: &v1Alpha1API.CStorPoolInstance{