diff --git a/pkg/controller/pravegacluster/pravegacluster_controller.go b/pkg/controller/pravegacluster/pravegacluster_controller.go index 48469ec28..08dc28b2e 100644 --- a/pkg/controller/pravegacluster/pravegacluster_controller.go +++ b/pkg/controller/pravegacluster/pravegacluster_controller.go @@ -280,6 +280,7 @@ func (r *ReconcilePravegaCluster) reconcileSegmentStoreConfigMap(p *pravegav1bet //restarting sts pods if !r.checkVersionUpgradeTriggered(p) && !segmentStorePortUpdated { err = r.restartStsPod(p) + if err != nil { return err } @@ -625,6 +626,23 @@ func (r *ReconcilePravegaCluster) deployController(p *pravegav1beta1.PravegaClus err = r.client.Create(context.TODO(), deployment) if err != nil && !errors.IsAlreadyExists(err) { return err + } else if errors.IsAlreadyExists(err) { + foundDeploy := &appsv1.Deployment{} + name := p.DeploymentNameForController() + err := r.client.Get(context.TODO(), + types.NamespacedName{Name: name, Namespace: p.Namespace}, foundDeploy) + if err != nil { + return err + } + + if !r.checkVersionUpgradeTriggered(p) && !r.isRollbackTriggered(p) { + foundDeploy.Spec.Template = deployment.Spec.Template + err = r.client.Update(context.TODO(), foundDeploy) + if err != nil { + return fmt.Errorf("failed to update deployment set: %v", err) + } + + } } return nil } @@ -650,19 +668,23 @@ func (r *ReconcilePravegaCluster) deploySegmentStore(p *pravegav1beta1.PravegaCl if err != nil { return err } - if statefulSet.Spec.Template.Spec.Containers[0].Ports[0].ContainerPort != sts.Spec.Template.Spec.Containers[0].Ports[0].ContainerPort { - sts.Spec.Template.Spec.Containers[0].Ports[0].ContainerPort = statefulSet.Spec.Template.Spec.Containers[0].Ports[0].ContainerPort - sts.Spec.Template.Spec.Containers[0].ReadinessProbe = statefulSet.Spec.Template.Spec.Containers[0].ReadinessProbe - sts.Spec.Template.Spec.Containers[0].LivenessProbe = statefulSet.Spec.Template.Spec.Containers[0].LivenessProbe + + if !r.checkVersionUpgradeTriggered(p) && !r.isRollbackTriggered(p) { + originalsts := sts.DeepCopy() + sts.Spec.Template = statefulSet.Spec.Template err = r.client.Update(context.TODO(), sts) if err != nil { return fmt.Errorf("failed to update stateful set: %v", err) } - err = r.restartStsPod(p) - if err != nil { - return err + + if !reflect.DeepEqual(originalsts.Spec.Template, sts.Spec.Template) { + err = r.restartStsPod(p) + if err != nil { + return err + } } } + owRefs := sts.GetOwnerReferences() if hasOldVersionOwnerReference(owRefs) { log.Printf("Deleting SSS STS as it has old version owner ref.") diff --git a/pkg/controller/pravegacluster/pravegacluster_controller_test.go b/pkg/controller/pravegacluster/pravegacluster_controller_test.go index b91a68be8..7d92400f1 100644 --- a/pkg/controller/pravegacluster/pravegacluster_controller_test.go +++ b/pkg/controller/pravegacluster/pravegacluster_controller_test.go @@ -397,6 +397,62 @@ var _ = Describe("PravegaCluster Controller", func() { }) }) + Context("checking updateStatefulset", func() { + var ( + err1 error + str1 string + ) + BeforeEach(func() { + + p.WithDefaults() + sts := &appsv1.StatefulSet{} + name := p.StatefulSetNameForSegmentstore() + foundPravega := &v1beta1.PravegaCluster{} + _ = client.Get(context.TODO(), req.NamespacedName, foundPravega) + foundPravega.Spec.Pravega.SegmentStoreServiceAccountName = "testsa" + client.Update(context.TODO(), foundPravega) + _, _ = r.Reconcile(req) + err1 = r.client.Get(context.TODO(), + types.NamespacedName{Name: name, Namespace: p.Namespace}, sts) + + str1 = fmt.Sprintf("%s", sts.Spec.Template.Spec.ServiceAccountName) + }) + It("should not give error", func() { + Ω(err1).Should(BeNil()) + }) + It("service account name should get updated correctly", func() { + Ω(str1).To(Equal("testsa")) + }) + }) + + Context("checking updateDeployment", func() { + var ( + err1 error + str1 string + ) + BeforeEach(func() { + + p.WithDefaults() + deploy := &appsv1.Deployment{} + name := p.DeploymentNameForController() + foundPravega := &v1beta1.PravegaCluster{} + _ = client.Get(context.TODO(), req.NamespacedName, foundPravega) + foundPravega.Spec.Pravega.ControllerServiceAccountName = "testsa" + client.Update(context.TODO(), foundPravega) + _, _ = r.Reconcile(req) + err1 = r.client.Get(context.TODO(), + types.NamespacedName{Name: name, Namespace: p.Namespace}, deploy) + + str1 = fmt.Sprintf("%s", deploy.Spec.Template.Spec.ServiceAccountName) + }) + It("should not give error", func() { + Ω(err1).Should(BeNil()) + }) + It("service account name should get updated correctly", func() { + Ω(str1).To(Equal("testsa")) + }) + }) + Context("checking checkVersionUpgradeTriggered function", func() { var ( ans1, ans2 bool diff --git a/pkg/test/e2e/e2eutil/pravegacluster_util.go b/pkg/test/e2e/e2eutil/pravegacluster_util.go index 13e35443c..fcdf8cdcd 100644 --- a/pkg/test/e2e/e2eutil/pravegacluster_util.go +++ b/pkg/test/e2e/e2eutil/pravegacluster_util.go @@ -909,6 +909,30 @@ func CheckConfigMapUpdated(t *testing.T, f *framework.Framework, ctx *framework. return nil } +// GetSts returns the sts +func GetSts(t *testing.T, f *framework.Framework, ctx *framework.TestCtx, stsName string) (*appsv1.StatefulSet, error) { + sts := &appsv1.StatefulSet{} + ns := "default" + err := f.Client.Get(goctx.TODO(), types.NamespacedName{Namespace: ns, Name: stsName}, sts) + if err != nil { + return nil, fmt.Errorf("sts doesnt exist: %v", err) + } + + return sts, nil +} + +// GetDeployment returns the deployment +func GetDeployment(t *testing.T, f *framework.Framework, ctx *framework.TestCtx, deployName string) (*appsv1.Deployment, error) { + deploy := &appsv1.Deployment{} + ns := "default" + err := f.Client.Get(goctx.TODO(), types.NamespacedName{Namespace: ns, Name: deployName}, deploy) + if err != nil { + return nil, fmt.Errorf("Deployment doesnt exist: %v", err) + } + + return deploy, nil +} + func RestartTier2(t *testing.T, f *framework.Framework, ctx *framework.TestCtx, namespace string) error { t.Log("restarting tier2 storage") tier2 := NewTier2(namespace) diff --git a/test/e2e/cmchanges_test.go b/test/e2e/cm_spec_changes_test.go similarity index 87% rename from test/e2e/cmchanges_test.go rename to test/e2e/cm_spec_changes_test.go index ce861b2a0..6e2abe686 100644 --- a/test/e2e/cmchanges_test.go +++ b/test/e2e/cm_spec_changes_test.go @@ -74,6 +74,8 @@ func testCMUpgradeCluster(t *testing.T) { pravega.Spec.Pravega.SegmentStoreJVMOptions = jvmOpts pravega.Spec.Pravega.Options["bookkeeper.bkAckQuorumSize"] = "2" pravega.Spec.Pravega.Options["pravegaservice.service.listener.port"] = "443" + pravega.Spec.Pravega.SegmentStoreServiceAccountName = "pravega-components" + pravega.Spec.Pravega.ControllerServiceAccountName = "pravega-components" //updating pravegacluster err = pravega_e2eutil.UpdatePravegaCluster(t, f, ctx, pravega) @@ -87,6 +89,15 @@ func testCMUpgradeCluster(t *testing.T) { pravega, err = pravega_e2eutil.GetPravegaCluster(t, f, ctx, pravega) g.Expect(err).NotTo(HaveOccurred()) + stsName := pravega.StatefulSetNameForSegmentstore() + sts, err1 := pravega_e2eutil.GetSts(t, f, ctx, stsName) + g.Expect(err1).NotTo(HaveOccurred()) + g.Expect(sts.Spec.Template.Spec.ServiceAccountName).To(Equal("pravega-components")) + + deployName := pravega.DeploymentNameForController() + deploy, err2 := pravega_e2eutil.GetDeployment(t, f, ctx, deployName) + g.Expect(err2).NotTo(HaveOccurred()) + g.Expect(deploy.Spec.Template.Spec.ServiceAccountName).To(Equal("pravega-components")) // Sleeping for 1 min before read/write data time.Sleep(60 * time.Second)