-
Notifications
You must be signed in to change notification settings - Fork 200
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
refact(upgrade): scale down jiva target deploy before replica patch #1626
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,7 @@ import ( | |
templates "github.com/openebs/maya/pkg/upgrade/templates/v1" | ||
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" | ||
|
@@ -419,6 +420,45 @@ func (j *jivaVolumeOptions) preupgrade(pvName, openebsNamespace string) error { | |
return nil | ||
} | ||
|
||
func scaleDownTargetDeploy(name, namespace string) error { | ||
klog.Infof("Scaling down target deploy %s in %s namespace", name, namespace) | ||
deployObj, err := deployClient.WithNamespace(namespace).Get(name) | ||
if err != nil { | ||
return err | ||
} | ||
pvLabelKey := "openebs.io/persistent-volume" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we use existing variables here instead of new ones? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure. Will fix this in upcoming PRs. |
||
pvName := deployObj.Labels[pvLabelKey] | ||
controllerLabel := "openebs.io/controller=jiva-controller," + | ||
pvLabelKey + "=" + pvName | ||
var zero int32 | ||
deployObj.Spec.Replicas = &zero | ||
_, err = deployClient.WithNamespace(namespace).Update(deployObj) | ||
if err != nil { | ||
return err | ||
} | ||
podList := &corev1.PodList{} | ||
// Wait for up to 5 minutes targe pod to go away. | ||
shubham14bajpai marked this conversation as resolved.
Show resolved
Hide resolved
|
||
for i := 0; i < 60; i++ { | ||
shubham14bajpai marked this conversation as resolved.
Show resolved
Hide resolved
|
||
podList, err = podClient.WithNamespace(namespace).List( | ||
metav1.ListOptions{ | ||
LabelSelector: controllerLabel, | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
if len(podList.Items) > 0 { | ||
time.Sleep(time.Second * 5) | ||
} else { | ||
break | ||
} | ||
} | ||
// If pod is not deleted within 5 minutes return error. | ||
if len(podList.Items) > 0 { | ||
return errors.Errorf("target pod still present") | ||
} | ||
return nil | ||
} | ||
|
||
func (j *jivaVolumeOptions) replicaUpgrade(openebsNamespace string) error { | ||
var err, uerr error | ||
statusObj := utask.UpgradeDetailedStatuses{Step: utask.ReplicaUpgrade} | ||
|
@@ -429,6 +469,18 @@ func (j *jivaVolumeOptions) replicaUpgrade(openebsNamespace string) error { | |
} | ||
|
||
statusObj.Phase = utask.StepErrored | ||
|
||
err = scaleDownTargetDeploy(j.controllerObj.name, j.ns) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is populated before the patching is done in the preuprade step. https://github.com/openebs/maya/blob/4104241e9966c87bc3153d7dab9aedaba9f503ac/pkg/upgrade/upgrader/jiva_upgrade.go#L599 |
||
if err != nil { | ||
statusObj.Message = "failed to scale down target depoyment" | ||
statusObj.Reason = strings.Replace(err.Error(), ":", "", -1) | ||
j.utaskObj, uerr = updateUpgradeDetailedStatus(j.utaskObj, statusObj, openebsNamespace) | ||
if uerr != nil && isENVPresent { | ||
return uerr | ||
} | ||
return errors.Wrap(err, "failed to scale down target depoyment") | ||
} | ||
|
||
// replica patch | ||
err = patchReplica(j.replicaObj, j.ns) | ||
if err != nil { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[doubt]
replicas: 1
Is this where we scale down the target?, setting replica to 1.It would be better if the indentation changes were excluded, since it is generating a huge diff.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Scale down is performed via update before patching. the replica deployment
This is where scale up the target back again while patching the new image and labels.