Skip to content

Commit

Permalink
feat(v2beta1): reduce the window period when blue-green deployment se…
Browse files Browse the repository at this point in the history
…rvices are unavailable.
  • Loading branch information
Rory-Z committed Aug 10, 2023
1 parent 8061e15 commit 286ea42
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 14 deletions.
23 changes: 17 additions & 6 deletions controllers/apps/v2beta1/emqx_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,23 @@ func newRequester(k8sClient client.Client, instance *appsv2beta1.EMQX) (innerReq
}

labels := instance.Spec.CoreTemplate.Labels
if instance.Status.CoreNodesStatus.CurrentRevision != "" {
labels = appsv2beta1.CloneAndAddLabel(
labels,
appsv2beta1.PodTemplateHashLabelKey,
instance.Status.CoreNodesStatus.CurrentRevision,
)
if instance.Status.IsConditionTrue(appsv2beta1.Available) {
if instance.Status.CoreNodesStatus.UpdateRevision != "" {
labels = appsv2beta1.CloneAndAddLabel(
labels,
appsv2beta1.PodTemplateHashLabelKey,
instance.Status.CoreNodesStatus.UpdateRevision,
)
}
} else {
if instance.Status.CoreNodesStatus.CurrentRevision != "" {
labels = appsv2beta1.CloneAndAddLabel(
labels,
appsv2beta1.PodTemplateHashLabelKey,
instance.Status.CoreNodesStatus.CurrentRevision,
)

}
}

podList := &corev1.PodList{}
Expand Down
30 changes: 22 additions & 8 deletions controllers/apps/v2beta1/update_pod_conditions.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ type updatePodConditions struct {
}

func (u *updatePodConditions) reconcile(ctx context.Context, instance *appsv2beta1.EMQX, r innerReq.RequesterInterface) subResult {
updateRs, _, _ := getReplicaSetList(ctx, u.Client, instance)
updateSts, _, _ := getStateFulSetList(ctx, u.Client, instance)
updateRs, currentRs, _ := getReplicaSetList(ctx, u.Client, instance)
updateSts, currentSts, _ := getStateFulSetList(ctx, u.Client, instance)

pods := &corev1.PodList{}
_ = u.Client.List(ctx, pods,
Expand All @@ -42,12 +42,26 @@ func (u *updatePodConditions) reconcile(ctx context.Context, instance *appsv2bet
LastTransitionTime: metav1.Now(),
}

if (updateSts != nil && controllerRef.UID == updateSts.UID) ||
(updateRs != nil && controllerRef.UID == updateRs.UID) {
for _, condition := range pod.Status.Conditions {
if condition.Type == corev1.ContainersReady && condition.Status == corev1.ConditionTrue {
onServingCondition.Status = u.checkInCluster(instance, r, pod)
break
if instance.Status.IsConditionTrue(appsv2beta1.Available) {
if (updateSts != nil && controllerRef.UID == updateSts.UID) ||
(updateRs != nil && controllerRef.UID == updateRs.UID) {
for _, condition := range pod.Status.Conditions {
if condition.Type == corev1.ContainersReady && condition.Status == corev1.ConditionTrue {
onServingCondition.Status = u.checkInCluster(instance, r, pod)
break
}
}
}
} else {
if (currentSts != nil && controllerRef.UID == currentSts.UID) ||
(currentRs != nil && controllerRef.UID == currentRs.UID) ||
(updateSts != nil && controllerRef.UID == updateSts.UID) ||
(updateRs != nil && controllerRef.UID == updateRs.UID) {
for _, condition := range pod.Status.Conditions {
if condition.Type == corev1.ContainersReady && condition.Status == corev1.ConditionTrue {
onServingCondition.Status = u.checkInCluster(instance, r, pod)
break
}
}
}
}
Expand Down

0 comments on commit 286ea42

Please sign in to comment.