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 3 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
67 changes: 67 additions & 0 deletions pkg/upgrade/upgrader/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ import (

apis "github.com/openebs/maya/pkg/apis/openebs.io/upgrade/v1alpha1"
deploy "github.com/openebs/maya/pkg/kubernetes/deployment/appsv1/v1alpha1"
pod "github.com/openebs/maya/pkg/kubernetes/pod/v1alpha1"
templates "github.com/openebs/maya/pkg/upgrade/templates/v1"
utask "github.com/openebs/maya/pkg/upgrade/v1alpha2"
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 @@ -318,3 +320,68 @@ 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
}

func waitUntilPodsAreRunning(namespace, label string, rc int) error {
pods := &corev1.PodList{}
count := 0
var err error
// Wait for up to 5 minutes for deployment pods to reach desired replicaCount.
for i := 0; i < 60; i++ {
// GetPodRunningCount gives number of pods running currently
pods, err = podClient.
WithNamespace(namespace).
List(metav1.ListOptions{LabelSelector: label})
if err != nil {
return err
}
count = pod.
ListBuilderForAPIList(pods).
WithFilter(pod.IsRunning()).
List().
Len()
if count != rc {
time.Sleep(time.Second * 5)
} else {
break
}
}
if count != rc {
return errors.Errorf("expected running pods: %d, found: %d", rc, count)
}
return nil
}
Loading