Skip to content

Commit

Permalink
controllers: fixes tests after a221a77
Browse files Browse the repository at this point in the history
  • Loading branch information
f41gh7 committed May 26, 2023
1 parent 6cfa92e commit 0035922
Showing 1 changed file with 3 additions and 18 deletions.
21 changes: 3 additions & 18 deletions controllers/factory/k8stools/sts.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,31 +121,17 @@ func performRollingUpdateOnSts(ctx context.Context, wasRecreated bool, rclient c
neededPodCount = int(*sts.Spec.Replicas)
}
switch {
// case when number of replicas decreased
// sanity check, should help to catch possible bugs
case len(podList.Items) > neededPodCount:
var podCnt int
// filter deleted pods
for idx, pod := range podList.Items {
if !pod.DeletionTimestamp.IsZero() {
continue
}
podList.Items[idx] = pod
idx++
}
podList.Items = podList.Items[:podCnt]
l.Info("unexpected count of pods for sts, seems like configuration of stateful wasn't correct and kubernetes cannot create pod,"+
" check kubectl events to find out source of problem", "sts", sts.Name, "wantCount", neededPodCount, "actualCount", len(podList.Items), "namespace", ns)
// usual case when some param misconfigured
// or kubernetes for some reason cannot create pod
// it's better to fail fast
case len(podList.Items) < neededPodCount:
return fmt.Errorf("actual pod count: %d less then needed: %d, possible statefulset misconfiguration", len(podList.Items), neededPodCount)
}

// sanity check, should help to catch possible bugs
if len(podList.Items) != neededPodCount {
l.Info("unexpected count of pods for sts, seems like configuration of stateful wasn't correct and kubernetes cannot create pod,"+
" check kubectl events to find out source of problem", "sts", sts.Name, "wantCount", neededPodCount, "actualCount", len(podList.Items), "namespace", ns)
}

// first we must ensure, that already updated pods in ready status
// then we can update other pods
// if pod is not ready
Expand All @@ -160,7 +146,6 @@ func performRollingUpdateOnSts(ctx context.Context, wasRecreated bool, rclient c
} else {
for _, pod := range podList.Items {
podRev := pod.Labels[podRevisionLabel]

if podRev == stsVersion {
// wait for readiness only for not ready pods
if !PodIsReady(pod) {
Expand Down

0 comments on commit 0035922

Please sign in to comment.