Skip to content

Commit

Permalink
fix(deploy): use recreate strategy and 1 replica (#499) (#500)
Browse files Browse the repository at this point in the history
(cherry picked from commit ef81336)

Co-authored-by: Elliott Baron <ebaron@redhat.com>
  • Loading branch information
mergify[bot] and ebaron committed Nov 22, 2022
1 parent 95ea0e9 commit f054d82
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ const (

func NewDeploymentForCR(cr *operatorv1beta1.Cryostat, specs *ServiceSpecs, imageTags *ImageTags,
tls *TLSConfig, fsGroup int64, openshift bool) *appsv1.Deployment {
// Force one replica to avoid lock file and PVC contention
replicas := int32(1)
return &appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Name: cr.Name,
Expand Down Expand Up @@ -136,6 +138,10 @@ func NewDeploymentForCR(cr *operatorv1beta1.Cryostat, specs *ServiceSpecs, image
},
Spec: *NewPodForCR(cr, specs, imageTags, tls, fsGroup, openshift),
},
Replicas: &replicas,
Strategy: appsv1.DeploymentStrategy{
Type: appsv1.RecreateDeploymentStrategyType,
},
},
}
}
Expand Down
8 changes: 4 additions & 4 deletions internal/controllers/cryostat_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -500,10 +500,10 @@ func (r *CryostatReconciler) createOrUpdateDeployment(ctx context.Context, deplo
// Return error so deployment can be recreated
return errSelectorModified
}
// Set the replica count, if managed by the operator
if deployCopy.Spec.Replicas != nil {
deploy.Spec.Replicas = deployCopy.Spec.Replicas
}
// Set the replica count and update strategy
deploy.Spec.Replicas = deployCopy.Spec.Replicas
deploy.Spec.Strategy = deployCopy.Spec.Strategy

// Update pod template spec to propagate any changes from Cryostat CR
deploy.Spec.Template.Spec = deployCopy.Spec.Template.Spec
// Update pod template metadata
Expand Down
8 changes: 7 additions & 1 deletion internal/controllers/cryostat_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,8 @@ var _ = Describe("CryostatController", func() {

// Deployment Selector is immutable
Expect(deploy.Spec.Selector).To(Equal(oldDeploy.Spec.Selector))
Expect(deploy.Spec.Replicas).To(Equal(oldDeploy.Spec.Replicas))
Expect(deploy.Spec.Replicas).To(Equal(&[]int32{1}[0]))
Expect(deploy.Spec.Strategy).To(Equal(test.NewMainDeploymentStrategy()))
})
Context("with a different selector", func() {
BeforeEach(func() {
Expand Down Expand Up @@ -2578,6 +2579,9 @@ func (t *cryostatTestInput) checkMainDeployment() {
}))
Expect(metav1.IsControlledBy(deployment, cr)).To(BeTrue())
Expect(deployment.Spec.Selector).To(Equal(test.NewMainDeploymentSelector()))
Expect(deployment.Spec.Replicas).ToNot(BeNil())
Expect(*deployment.Spec.Replicas).To(Equal(int32(1)))
Expect(deployment.Spec.Strategy).To(Equal(test.NewMainDeploymentStrategy()))

// compare Pod template
t.checkMainPodTemplate(deployment, cr)
Expand Down Expand Up @@ -2669,7 +2673,9 @@ func (t *cryostatTestInput) checkReportsDeployment() {
}))
Expect(metav1.IsControlledBy(deployment, cr)).To(BeTrue())
Expect(deployment.Spec.Selector).To(Equal(test.NewReportsDeploymentSelector()))
Expect(deployment.Spec.Replicas).ToNot(BeNil())
Expect(*deployment.Spec.Replicas).To(Equal(t.reportReplicas))
Expect(deployment.Spec.Strategy).To(BeZero())

// compare Pod template
template := deployment.Spec.Template
Expand Down
6 changes: 6 additions & 0 deletions internal/test/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -1720,6 +1720,12 @@ func NewReportsDeploymentSelector() *metav1.LabelSelector {
}
}

func NewMainDeploymentStrategy() appsv1.DeploymentStrategy {
return appsv1.DeploymentStrategy{
Type: appsv1.RecreateDeploymentStrategyType,
}
}

func OtherDeployment() *appsv1.Deployment {
replicas := int32(2)
return &appsv1.Deployment{
Expand Down

0 comments on commit f054d82

Please sign in to comment.