Skip to content

Commit

Permalink
renamed imports for v1aplha1 apis
Browse files Browse the repository at this point in the history
Signed-off-by: shubham <[email protected]>
  • Loading branch information
shubham14bajpai committed Jun 29, 2020
1 parent b847b79 commit 649bfc4
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 54 deletions.
8 changes: 4 additions & 4 deletions cmd/upgrade/executor/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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).
Expand All @@ -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)
Expand All @@ -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")
Expand Down
6 changes: 3 additions & 3 deletions pkg/upgrade/upgrader/cstor_cspc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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).
Expand All @@ -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)
Expand Down
24 changes: 12 additions & 12 deletions pkg/upgrade/upgrader/cstor_cspi.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -33,7 +33,7 @@ type CSPIPatch struct {
Namespace string
Deploy *patch.Deployment
CSPI *patch.CSPI
Utask *apis.UpgradeTask
Utask *v1Alpha1API.UpgradeTask
*Client
}

Expand Down Expand Up @@ -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
Expand All @@ -139,21 +139,21 @@ 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)
if uerr != nil && isUpgradeTaskJob {
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
Expand Down Expand Up @@ -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)
Expand All @@ -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),
)
Expand Down
28 changes: 14 additions & 14 deletions pkg/upgrade/upgrader/cstor_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -37,7 +37,7 @@ type CStorVolumePatch struct {
CV *patch.CV
Deploy *patch.Deployment
Service *patch.Service
Utask *apis.UpgradeTask
Utask *v1Alpha1API.UpgradeTask
*Client
}

Expand Down Expand Up @@ -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
Expand All @@ -287,21 +287,21 @@ 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)
if uerr != nil && isUpgradeTaskJob {
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(
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down
42 changes: 21 additions & 21 deletions pkg/upgrade/upgrader/upgradetask.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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,
Expand All @@ -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")
Expand Down Expand Up @@ -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)
Expand All @@ -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,
},
}
Expand Down

0 comments on commit 649bfc4

Please sign in to comment.