|
1 | 1 | package cocoonset |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "cmp" |
4 | 5 | "context" |
5 | 6 | "fmt" |
6 | 7 | "maps" |
@@ -332,22 +333,35 @@ func (r *Reconciler) applySuspend(ctx context.Context, classified classifiedPods |
332 | 333 | // CocoonHibernation status would still read Hibernated, and the user |
333 | 334 | // would observe a phantom-running pod. |
334 | 335 | // |
335 | | -// The cheap path (no in-flight CRs in the namespace) only walks the |
336 | | -// owned pods and skips ones whose hibernate annotation is already |
337 | | -// absent — PatchHibernateState(false) is a no-op there. |
| 336 | +// Fast path: the steady-state non-suspended CocoonSet has no pod |
| 337 | +// carrying the hibernate annotation, so we skip the CocoonHibernation |
| 338 | +// List entirely. One pass over classified.allByName collects the |
| 339 | +// hibernated subset; if it's empty we return without touching the |
| 340 | +// API. Otherwise we sort just that subset (for deterministic patch |
| 341 | +// order under test) and consult the CR list to decide which ones to |
| 342 | +// leave alone. |
338 | 343 | func (r *Reconciler) applyUnsuspend(ctx context.Context, namespace string, classified classifiedPods) error { |
| 344 | + var hibernated []*corev1.Pod |
| 345 | + for _, pod := range classified.allByName { |
| 346 | + if bool(meta.ReadHibernateState(pod)) { |
| 347 | + hibernated = append(hibernated, pod) |
| 348 | + } |
| 349 | + } |
| 350 | + if len(hibernated) == 0 { |
| 351 | + return nil |
| 352 | + } |
| 353 | + slices.SortFunc(hibernated, func(a, b *corev1.Pod) int { |
| 354 | + return cmp.Compare(a.Name, b.Name) |
| 355 | + }) |
| 356 | + |
339 | 357 | hibernatedByCR, err := r.podsHibernatedByCR(ctx, namespace) |
340 | 358 | if err != nil { |
341 | 359 | return err |
342 | 360 | } |
343 | | - for _, name := range slices.Sorted(maps.Keys(classified.allByName)) { |
| 361 | + for _, pod := range hibernated { |
344 | 362 | if ctxErr := ctx.Err(); ctxErr != nil { |
345 | 363 | return ctxErr |
346 | 364 | } |
347 | | - pod := classified.allByName[name] |
348 | | - if !bool(meta.ReadHibernateState(pod)) { |
349 | | - continue |
350 | | - } |
351 | 365 | if _, ownedByCR := hibernatedByCR[pod.Name]; ownedByCR { |
352 | 366 | continue |
353 | 367 | } |
|
0 commit comments