Skip to content

Commit

Permalink
added changes for avoiding 2 restarts when both version and cm changes (
Browse files Browse the repository at this point in the history
#506)

Signed-off-by: prabhaker24 <[email protected]>

Co-authored-by: prabhaker24 <[email protected]>
  • Loading branch information
Prabhaker24 and prabhaker24 authored Feb 10, 2021
1 parent 426029c commit 2daf478
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 6 deletions.
25 changes: 19 additions & 6 deletions pkg/controller/pravegacluster/pravegacluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,11 @@ func (r *ReconcilePravegaCluster) reconcileControllerConfigMap(p *pravegav1beta1
return err
}
//restarting controller pods
err = r.restartDeploymentPod(p)
if err != nil {
return err
if !r.checkVersionUpgradeTriggered(p) {
err = r.restartDeploymentPod(p)
if err != nil {
return err
}
}
}
}
Expand Down Expand Up @@ -274,15 +276,26 @@ func (r *ReconcilePravegaCluster) reconcileSegmentStoreConfigMap(p *pravegav1bet
return err
}
//restarting sts pods
err = r.restartStsPod(p)
if err != nil {
return err
if !r.checkVersionUpgradeTriggered(p) {
err = r.restartStsPod(p)
if err != nil {
return err
}
}
}
}
return nil
}

func (r *ReconcilePravegaCluster) checkVersionUpgradeTriggered(p *pravegav1beta1.PravegaCluster) bool {
currentPravegaCluster := &pravegav1beta1.PravegaCluster{}
err := r.client.Get(context.TODO(), types.NamespacedName{Name: p.Name, Namespace: p.Namespace}, currentPravegaCluster)
if err == nil && currentPravegaCluster.Status.CurrentVersion != p.Spec.Version {
return true
}
return false
}

func (r *ReconcilePravegaCluster) reconcilePdb(p *pravegav1beta1.PravegaCluster) (err error) {

err = r.reconcileControllerPdb(p)
Expand Down
22 changes: 22 additions & 0 deletions pkg/controller/pravegacluster/pravegacluster_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,28 @@ var _ = Describe("PravegaCluster Controller", func() {
})
})

Context("checking checkVersionUpgradeTriggered function", func() {
var (
ans1, ans2 bool
)
BeforeEach(func() {
client = fake.NewFakeClient(p)
r = &ReconcilePravegaCluster{client: client, scheme: s}
res, err = r.Reconcile(req)

ans1 = r.checkVersionUpgradeTriggered(p)
p.Spec.Version = "0.8.0"
ans2 = r.checkVersionUpgradeTriggered(p)
})
It("ans1 should be false", func() {
Ω(ans1).To(Equal(false))
})
It("ans2 should be true", func() {
Ω(ans2).To(Equal(true))
})

})

Context("reconcileFinalizers", func() {
BeforeEach(func() {
p.WithDefaults()
Expand Down

0 comments on commit 2daf478

Please sign in to comment.