Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(upgrade): add support to migrate jiva volumes resources to openebs namespace #1646

Merged
merged 5 commits into from
Apr 6, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/upgrade/templates/v1/jiva_replica.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ var (
}
},
"spec": {
"replicas": 1,
"selector": {
"matchLabels":{
"openebs.io/persistent-volume": "{{.PVName}}",
Expand Down
53 changes: 53 additions & 0 deletions pkg/upgrade/upgrader/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
retry "github.com/openebs/maya/pkg/util/retry"
errors "github.com/pkg/errors"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
k8serror "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
types "k8s.io/apimachinery/pkg/types"
Expand Down Expand Up @@ -59,6 +60,23 @@ func getOpenEBSVersion(d *appsv1.Deployment) (string, error) {
return d.Labels["openebs.io/version"], nil
}

func checkOpenEBSVersion(d *appsv1.Deployment) (string, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this function be called isValidVersion? Also there is a message in this function about replica.

version, err := getOpenEBSVersion(d)
if err != nil {
return "", err
}
if (version != currentVersion) && (version != upgradeVersion) {
return "", errors.Errorf(
"replica %s version %s is neither %s nor %s\n",
d.Name,
version,
currentVersion,
upgradeVersion,
)
}
return version, nil
}

func patchDelpoyment(
deployName,
namespace string,
Expand Down Expand Up @@ -318,3 +336,38 @@ func buildUpgradeTask(kind, name, openebsNamespace string) *apis.UpgradeTask {
}
return utaskObj
}

func scaleDeploy(name, namespace, label string, rc int) error {
klog.Infof("Scaling deploy %s in %s namespace to %d", name, namespace, rc)
deployObj, err := deployClient.WithNamespace(namespace).Get(name)
if err != nil {
return err
}
replicas := int32(rc)
deployObj.Spec.Replicas = &replicas
_, err = deployClient.WithNamespace(namespace).Update(deployObj)
if err != nil {
return err
}
podList := &corev1.PodList{}
// Wait for up to 5 minutes for deployment pods to reach desired replicaCount.
for i := 0; i < 60; i++ {
podList, err := podClient.WithNamespace(namespace).List(
metav1.ListOptions{
LabelSelector: label,
})
if err != nil {
return err
}
if len(podList.Items) != rc {
time.Sleep(time.Second * 5)
} else {
break
}
}
// If number pods is not reached within 5 minutes return error.
if len(podList.Items) != rc {
return errors.Errorf("expected pods: %d, found: %d", rc, len(podList.Items))
}
return nil
}
Loading