|
7 | 7 | "math" |
8 | 8 | "slices" |
9 | 9 | "strconv" |
10 | | - "strings" |
11 | 10 | "time" |
12 | 11 |
|
13 | 12 | "gopkg.in/yaml.v2" |
@@ -596,9 +595,7 @@ func (r *keeperReconciler) evaluateReplicaConditions() { |
596 | 595 | r.SetCondition(chctrl.ReplicaStartupCondition(errorIDs)) |
597 | 596 | r.SetCondition(chctrl.HealthyCondition(notReadyIDs)) |
598 | 597 | r.SetCondition(chctrl.ConfigSyncCondition(nil, notUpdatedIDs, nil)) |
599 | | - versionCond, versionEvents := keeperVersionSyncCondition(replicaVersions, len(notUpdatedIDs) > 0) |
600 | | - r.SetCondition(versionCond, versionEvents...) |
601 | | - r.evaluateUpgradeCondition(replicaVersions) |
| 598 | + r.evaluateVersionConditions(len(notUpdatedIDs) > 0) |
602 | 599 |
|
603 | 600 | // Ready condition — keeper-specific logic. |
604 | 601 | exists := len(r.ReplicaState) |
@@ -677,75 +674,38 @@ func (r *keeperReconciler) evaluateReplicaConditions() { |
677 | 674 | ) |
678 | 675 | } |
679 | 676 |
|
680 | | -func (r *keeperReconciler) evaluateUpgradeCondition(replicaVersions map[string]string) { |
681 | | - version, ok := keeperObservedVersion(replicaVersions) |
682 | | - if ok { |
683 | | - r.Cluster.Status.Version = version |
684 | | - } |
685 | | - |
686 | | - if r.Checker == nil || !ok { |
687 | | - meta.RemoveStatusCondition(r.Cluster.GetStatus().GetConditions(), v1.ConditionTypeVersionUpgraded) |
688 | | - return |
689 | | - } |
| 677 | +func (r *keeperReconciler) evaluateVersionConditions(isUpdating bool) { |
| 678 | + versionByReplica := map[string]string{} |
| 679 | + countByVersion := map[string]int{} |
| 680 | + commonVersion := "" |
690 | 681 |
|
691 | | - cond, event := chctrl.GetUpgradeCondition(*r.Checker, chctrl.VersionProbeResult{Version: version}, r.Cluster.Spec.UpgradeChannel) |
692 | | - r.SetCondition(cond, event...) |
693 | | -} |
694 | | - |
695 | | -func keeperVersionSyncCondition(replicaVersions map[string]string, isUpdating bool) (metav1.Condition, []chctrl.EventSpec) { |
696 | | - newCond := func(status metav1.ConditionStatus, reason v1.ConditionReason, message string) metav1.Condition { |
697 | | - return metav1.Condition{ |
698 | | - Type: v1.ConditionTypeVersionInSync, |
699 | | - Status: status, |
700 | | - Reason: reason, |
701 | | - Message: message, |
| 682 | + for i, s := range r.ReplicaState { |
| 683 | + if s.Status.Version != "" { |
| 684 | + versionByReplica[strconv.FormatInt(int64(i), 10)] = s.Status.Version |
| 685 | + countByVersion[s.Status.Version]++ |
| 686 | + commonVersion = s.Status.Version |
702 | 687 | } |
703 | 688 | } |
704 | 689 |
|
705 | | - if len(replicaVersions) == 0 { |
706 | | - return newCond(metav1.ConditionUnknown, v1.ConditionReasonVersionPending, "No Keeper replica version has been observed yet"), nil |
707 | | - } |
708 | | - |
709 | | - var observed []string |
710 | | - for id, version := range replicaVersions { |
711 | | - observed = append(observed, fmt.Sprintf("%s: %s", id, version)) |
| 690 | + // Record the version only when all observed replicas agree, otherwise keep the last known one. |
| 691 | + if len(countByVersion) == 1 { |
| 692 | + r.Cluster.Status.Version = commonVersion |
712 | 693 | } |
713 | 694 |
|
714 | | - if version, ok := keeperObservedVersion(replicaVersions); ok { |
715 | | - return newCond(metav1.ConditionTrue, v1.ConditionReasonVersionMatch, |
716 | | - "All observed Keeper replicas report version "+version), nil |
| 695 | + probe := chctrl.VersionProbeResult{ |
| 696 | + Version: r.Cluster.Status.Version, |
| 697 | + Pending: len(versionByReplica) == 0, |
717 | 698 | } |
718 | 699 |
|
719 | | - slices.Sort(observed) |
720 | | - cond := newCond(metav1.ConditionFalse, v1.ConditionReasonVersionMismatch, |
721 | | - "Keeper replica versions differ: "+strings.Join(observed, ", ")) |
722 | | - |
723 | | - if isUpdating { |
724 | | - return cond, nil |
725 | | - } |
726 | | - |
727 | | - return cond, []chctrl.EventSpec{{ |
728 | | - Type: corev1.EventTypeWarning, |
729 | | - Reason: v1.EventReasonVersionDiverge, |
730 | | - Action: v1.EventActionVersionCheck, |
731 | | - Message: cond.Message, |
732 | | - }} |
733 | | -} |
734 | | - |
735 | | -func keeperObservedVersion(replicaVersions map[string]string) (string, bool) { |
736 | | - var result string |
737 | | - for _, version := range replicaVersions { |
738 | | - if result == "" { |
739 | | - result = version |
740 | | - continue |
741 | | - } |
| 700 | + cond, event := chctrl.GetVersionSyncCondition(probe, versionByReplica, isUpdating) |
| 701 | + r.SetCondition(cond, event...) |
742 | 702 |
|
743 | | - if version != result { |
744 | | - return "", false |
745 | | - } |
| 703 | + if r.Checker != nil { |
| 704 | + cond, event = chctrl.GetUpgradeCondition(*r.Checker, probe, r.Cluster.Spec.UpgradeChannel) |
| 705 | + r.SetCondition(cond, event...) |
| 706 | + } else { |
| 707 | + meta.RemoveStatusCondition(r.Cluster.GetStatus().GetConditions(), v1.ConditionTypeVersionUpgraded) |
746 | 708 | } |
747 | | - |
748 | | - return result, result != "" |
749 | 709 | } |
750 | 710 |
|
751 | 711 | func (r *keeperReconciler) updateReplica(ctx context.Context, log ctrlutil.Logger, replicaID v1.KeeperReplicaID) (*ctrl.Result, error) { |
|
0 commit comments