Skip to content

Commit ce25688

Browse files
committed
Minor refactors and cleanup
1 parent a7b54bf commit ce25688

File tree

3 files changed

+17
-13
lines changed

3 files changed

+17
-13
lines changed

pkg/controller/controller.go

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,8 @@ func (c *M3DBController) handleClusterUpdate(cluster *myspec.M3DBCluster) error
522522

523523
replicas := *sts.Spec.Replicas
524524
ready := replicas == sts.Status.ReadyReplicas
525-
if sts.Status.UpdateRevision != "" {
525+
if sts.Status.UpdateRevision != "" &&
526+
sts.Spec.UpdateStrategy.Type == appsv1.RollingUpdateStatefulSetStrategyType {
526527
// If there is an update revision, ensure all pods are updated
527528
// otherwise there is a rollout in progress.
528529
// Note: This ensures there is no race condition between
@@ -537,6 +538,7 @@ func (c *M3DBController) handleClusterUpdate(cluster *myspec.M3DBCluster) error
537538

538539
if !ready {
539540
c.logger.Info("waiting for statefulset to be ready",
541+
zap.String("namespace", sts.Namespace),
540542
zap.String("name", sts.Name),
541543
zap.Int32("replicas", replicas),
542544
zap.Int32("readyReplicas", sts.Status.ReadyReplicas),
@@ -565,21 +567,19 @@ func (c *M3DBController) handleClusterUpdate(cluster *myspec.M3DBCluster) error
565567
// strategy, then move to the next statefulset. When using the OnDelete update
566568
// strategy, we still may want to restart nodes for this particular statefulset,
567569
// so don't continue yet.
568-
if !update && !cluster.Spec.OnDeleteUpdateStrategy {
570+
onDeleteUpdateStrategy :=
571+
actual.Spec.UpdateStrategy.Type == appsv1.OnDeleteStatefulSetStrategyType
572+
if !update && !onDeleteUpdateStrategy {
569573
continue
570574
}
571575

572576
if update {
573-
actual, err = c.applyStatefulSetUpdate(cluster, actual, expected)
577+
_, err = c.applyStatefulSetUpdate(cluster, actual, expected)
574578
if err != nil {
575579
c.logger.Error(err.Error())
576580
return err
577581
}
578-
// If using a RollingUpdate strategy, do not process the next statefulset.
579-
// We must wait for the kube controller to update the pods.
580-
if !cluster.Spec.OnDeleteUpdateStrategy {
581-
return nil
582-
}
582+
return nil
583583
}
584584

585585
// Using an OnDelete strategy, we have to update nodes if:
@@ -589,8 +589,8 @@ func (c *M3DBController) handleClusterUpdate(cluster *myspec.M3DBCluster) error
589589
// Therefore, always check to see if pods need to be updated and return from this loop
590590
// if the statefulset or pods were updated. If a rollout is finished or there has not
591591
// been a change, this call is a no-op.
592-
if cluster.Spec.OnDeleteUpdateStrategy {
593-
nodesUpdated, err := c.updateStatefulSetNodes(cluster, actual)
592+
if onDeleteUpdateStrategy {
593+
nodesUpdated, err := c.updateStatefulSetPods(cluster, actual)
594594
if err != nil {
595595
c.logger.Error("error performing update",
596596
zap.Error(err),
@@ -826,8 +826,8 @@ func (c *M3DBController) applyStatefulSetUpdate(
826826
return updated, nil
827827
}
828828

829-
// updateStatefulSetNodes returns true if it updates any pods
830-
func (c *M3DBController) updateStatefulSetNodes(
829+
// updateStatefulSetPods returns true if it updates any pods
830+
func (c *M3DBController) updateStatefulSetPods(
831831
cluster *myspec.M3DBCluster,
832832
sts *appsv1.StatefulSet,
833833
) (bool, error) {
@@ -1325,6 +1325,7 @@ func copyAnnotations(expected, actual *appsv1.StatefulSet) {
13251325
// updates.
13261326
if k == annotations.ParallelUpdate {
13271327
expected.Annotations[annotations.ParallelUpdateInProgress] = v
1328+
continue
13281329
}
13291330

13301331
if _, ok := expected.Annotations[k]; !ok {

pkg/controller/controller_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ func waitForStatefulSets(
232232
// we see all stateful sets that we expect and also be able to catch any extra stateful
233233
// sets that we don't.
234234
var (
235-
iters = math.Max(float64(2*len(opts.expectedStatefulSets)), 5)
235+
iters = math.Max(float64(2*len(opts.expectedStatefulSets)), 10)
236236
finalErr error
237237
podUpdateGroups [][]string
238238
)

pkg/k8sops/m3db/statefulset.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,9 @@ func NewBaseStatefulSet(ssName, isolationGroup string, cluster *myspec.M3DBClust
186186

187187
if cluster.Spec.OnDeleteUpdateStrategy {
188188
stsSpec.UpdateStrategy.Type = appsv1.OnDeleteStatefulSetStrategyType
189+
} else {
190+
// NB(nate); This is the default, but set anyway out of a healthy paranoia.
191+
stsSpec.UpdateStrategy.Type = appsv1.RollingUpdateStatefulSetStrategyType
189192
}
190193

191194
return &appsv1.StatefulSet{

0 commit comments

Comments
 (0)