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

Issue 557: Many Pravega Spec parameters are still not updatable at runtime #561

Merged
merged 3 commits into from
Jul 13, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
36 changes: 29 additions & 7 deletions pkg/controller/pravegacluster/pravegacluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand All @@ -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)
SrishT marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return err
}
}
}

owRefs := sts.GetOwnerReferences()
if hasOldVersionOwnerReference(owRefs) {
log.Printf("Deleting SSS STS as it has old version owner ref.")
Expand Down
56 changes: 56 additions & 0 deletions pkg/controller/pravegacluster/pravegacluster_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 24 additions & 0 deletions pkg/test/e2e/e2eutil/pravegacluster_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 11 additions & 0 deletions test/e2e/cmchanges_test.go → test/e2e/cm_spec_changes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)

Expand Down