(getRuntimeFn func(client.Client) (base.RuntimeInterface, error), masterStsNamespacedName types.NamespacedName)
| 32 | ) |
| 33 | |
| 34 | func (e *Helper) CheckAndSyncMasterStatus(getRuntimeFn func(client.Client) (base.RuntimeInterface, error), masterStsNamespacedName types.NamespacedName) (ready bool, err error) { |
| 35 | masterSts, err := kubeclient.GetStatefulSet(e.client, masterStsNamespacedName.Name, masterStsNamespacedName.Namespace) |
| 36 | if err != nil { |
| 37 | return |
| 38 | } |
| 39 | |
| 40 | err = retry.RetryOnConflict(retry.DefaultBackoff, func() error { |
| 41 | runtime, err := getRuntimeFn(e.client) |
| 42 | if err != nil { |
| 43 | return err |
| 44 | } |
| 45 | |
| 46 | oldStatus := runtime.GetStatus().DeepCopy() |
| 47 | statusToUpdate := runtime.GetStatus() |
| 48 | var expectReplicas int32 |
| 49 | if masterSts.Spec.Replicas != nil { |
| 50 | expectReplicas = *masterSts.Spec.Replicas |
| 51 | } else { |
| 52 | expectReplicas = 0 |
| 53 | } |
| 54 | |
| 55 | statusToUpdate.DesiredMasterNumberScheduled = expectReplicas |
| 56 | statusToUpdate.CurrentMasterNumberScheduled = masterSts.Status.Replicas |
| 57 | statusToUpdate.MasterNumberReady = masterSts.Status.ReadyReplicas |
| 58 | |
| 59 | phase := kubeclient.GetPhaseFromStatefulset(expectReplicas, *masterSts) |
| 60 | statusToUpdate.MasterPhase = phase |
| 61 | |
| 62 | var cond datav1alpha1.RuntimeCondition |
| 63 | if len(statusToUpdate.Conditions) == 0 { |
| 64 | statusToUpdate.Conditions = []datav1alpha1.RuntimeCondition{} |
| 65 | } |
| 66 | |
| 67 | // add masterInitCond to indicate master is initialized, this is idempotent because RuntimeMasterInitialized is a OnceActionType condition |
| 68 | masterInitCond := utils.NewRuntimeCondition(datav1alpha1.RuntimeMasterInitialized, datav1alpha1.RuntimeMasterInitializedReason, |
| 69 | "The master is initialized.", corev1.ConditionTrue) |
| 70 | statusToUpdate.Conditions = |
| 71 | utils.UpdateRuntimeCondition(statusToUpdate.Conditions, |
| 72 | masterInitCond) |
| 73 | |
| 74 | switch phase { |
| 75 | case datav1alpha1.RuntimePhaseReady: |
| 76 | ready = true |
| 77 | cond = utils.NewRuntimeCondition(datav1alpha1.RuntimeMasterReady, datav1alpha1.RuntimeMasterReadyReason, |
| 78 | "The master is ready.", corev1.ConditionTrue) |
| 79 | case datav1alpha1.RuntimePhasePartialReady: |
| 80 | ready = true |
| 81 | cond = utils.NewRuntimeCondition(datav1alpha1.RuntimeMasterReady, datav1alpha1.RuntimeMasterReadyReason, |
| 82 | "The master is partially ready.", corev1.ConditionTrue) |
| 83 | case datav1alpha1.RuntimePhaseNotReady: |
| 84 | ready = false |
| 85 | cond = utils.NewRuntimeCondition(datav1alpha1.RuntimeMasterReady, datav1alpha1.RuntimeMasterReadyReason, |
| 86 | "The master is not ready.", corev1.ConditionFalse) |
| 87 | } |
| 88 | |
| 89 | if len(cond.Type) != 0 { |
| 90 | statusToUpdate.Conditions = utils.UpdateRuntimeCondition(statusToUpdate.Conditions, cond) |
| 91 | } |
no test coverage detected