isPodNeedingRollout checks if a given cluster instance needs a rollout by comparing its current state with its expected state defined inside the cluster struct. Arguments: - The status of a postgres cluster instance. - The cluster struct containing the desired state. Returns: - a rollout object
( ctx context.Context, pod *corev1.Pod, cluster *apiv1.Cluster, )
| 405 | // |
| 406 | // - a rollout object including whether a restart is required, and the reason |
| 407 | func isPodNeedingRollout( |
| 408 | ctx context.Context, |
| 409 | pod *corev1.Pod, |
| 410 | cluster *apiv1.Cluster, |
| 411 | ) rollout { |
| 412 | contextLogger := log.FromContext(ctx) |
| 413 | applyCheckers := func(checkers map[string]rolloutChecker) rollout { |
| 414 | for message, check := range checkers { |
| 415 | podRollout, err := check(ctx, pod, cluster) |
| 416 | if err != nil { |
| 417 | contextLogger.Error(err, "while checking if pod needs rollout") |
| 418 | continue |
| 419 | } |
| 420 | if podRollout.required { |
| 421 | if podRollout.reason == "" { |
| 422 | podRollout.reason = message |
| 423 | } |
| 424 | contextLogger.Info("Pod rollout required", "podName", pod.Name, "reason", podRollout.reason) |
| 425 | return podRollout |
| 426 | } |
| 427 | } |
| 428 | return rollout{} |
| 429 | } |
| 430 | |
| 431 | checkers := map[string]rolloutChecker{ |
| 432 | "pod has missing PVCs": checkHasMissingPVCs, |
| 433 | "pod projected volume is outdated": checkProjectedVolumeIsOutdated, |
| 434 | "pod image is outdated": checkPodImageIsOutdated, |
| 435 | "cluster has different restart annotation": checkClusterHasDifferentRestartAnnotation, |
| 436 | } |
| 437 | |
| 438 | podRollout := applyCheckers(checkers) |
| 439 | if podRollout.required { |
| 440 | return podRollout |
| 441 | } |
| 442 | |
| 443 | // If the cluster is annotated with `cnpg.io/reconcilePodSpec: disabled`, |
| 444 | // we avoid checking the PodSpec |
| 445 | if utils.IsPodSpecReconciliationDisabled(&cluster.ObjectMeta) { |
| 446 | return rollout{} |
| 447 | } |
| 448 | |
| 449 | // If the pod has a valid PodSpec annotation, that's the final check. |
| 450 | // If not, we should perform additional legacy checks |
| 451 | if hasValidPodSpec(pod) { |
| 452 | return applyCheckers(map[string]rolloutChecker{ |
| 453 | "PodSpec is outdated": checkPodSpecIsOutdated, |
| 454 | }) |
| 455 | } |
| 456 | |
| 457 | // These checks are subsumed by the PodSpec checker |
| 458 | checkers = map[string]rolloutChecker{ |
| 459 | "pod environment is outdated": checkPodEnvironmentIsOutdated, |
| 460 | "pod scheduler is outdated": checkSchedulerIsOutdated, |
| 461 | "pod needs updated topology": checkPodNeedsUpdatedTopology, |
| 462 | "pod bootstrap container is outdated": checkPodBootstrapImage, |
| 463 | } |
| 464 | podRollout = applyCheckers(checkers) |
no test coverage detected