mirror of
https://gitee.com/devstar/devstar-devcontainer-operator
synced 2025-04-21 09:42:22 +00:00
Added Readiness Listener based on StatefulSet.Status.ReadyReplicas
This commit is contained in:
parent
1600db90da
commit
41654afce9
@ -98,6 +98,10 @@ type DevcontainerAppStatus struct {
|
|||||||
// NodePortAssigned 存储 DevcontainerApp CRD调度后集群分配的 NodePort
|
// NodePortAssigned 存储 DevcontainerApp CRD调度后集群分配的 NodePort
|
||||||
// +optional
|
// +optional
|
||||||
NodePortAssigned uint16 `json:"nodePortAssigned"`
|
NodePortAssigned uint16 `json:"nodePortAssigned"`
|
||||||
|
|
||||||
|
// Ready 标识 DevcontainerApp 管理的 Pod 的 Readiness Probe 是否达到就绪状态
|
||||||
|
// +optional
|
||||||
|
Ready bool `json:"ready"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// +kubebuilder:object:root=true
|
// +kubebuilder:object:root=true
|
||||||
|
@ -153,6 +153,9 @@ spec:
|
|||||||
nodePortAssigned:
|
nodePortAssigned:
|
||||||
description: NodePortAssigned 存储 DevcontainerApp CRD调度后集群分配的 NodePort
|
description: NodePortAssigned 存储 DevcontainerApp CRD调度后集群分配的 NodePort
|
||||||
type: integer
|
type: integer
|
||||||
|
ready:
|
||||||
|
description: Ready 标识 DevcontainerApp 管理的 Pod 的 Readiness Probe 是否达到就绪状态
|
||||||
|
type: boolean
|
||||||
type: object
|
type: object
|
||||||
type: object
|
type: object
|
||||||
served: true
|
served: true
|
||||||
|
@ -86,6 +86,23 @@ func (r *DevcontainerAppReconciler) Reconcile(ctx context.Context, req ctrl.Requ
|
|||||||
return ctrl.Result{}, err
|
return ctrl.Result{}, err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
// 若 StatefulSet.Status.readyReplicas 变化,则更新 DevcontainerApp.Status.Ready 域(mark/un-mark)
|
||||||
|
if statefulSetInNamespace.Status.ReadyReplicas > 0 {
|
||||||
|
app.Status.Ready = true
|
||||||
|
if err := r.Status().Update(ctx, app); err != nil {
|
||||||
|
logger.Error(err, "Failed to update DevcontainerApp.Status.Ready", "DevcontainerApp.Status.Ready", app.Status.Ready)
|
||||||
|
return ctrl.Result{}, err
|
||||||
|
}
|
||||||
|
logger.Info("DevContainer is now ready", "ReadyReplicas", statefulSetInNamespace.Status.ReadyReplicas)
|
||||||
|
} else {
|
||||||
|
app.Status.Ready = false
|
||||||
|
if err := r.Status().Update(ctx, app); err != nil {
|
||||||
|
logger.Error(err, "Failed to un-mark DevcontainerApp.Status.Ready", "DevcontainerApp.Status.Ready", app.Status.Ready)
|
||||||
|
return ctrl.Result{}, err
|
||||||
|
}
|
||||||
|
logger.Info("DevContainer is NOT ready", "ReadyReplicas", statefulSetInNamespace.Status.ReadyReplicas)
|
||||||
|
}
|
||||||
|
|
||||||
// 这里会反复触发更新
|
// 这里会反复触发更新
|
||||||
// 原因:在 SetupWithManager方法中,监听了 StatefulSet ,所以只要更新 StatefulSet 就会触发
|
// 原因:在 SetupWithManager方法中,监听了 StatefulSet ,所以只要更新 StatefulSet 就会触发
|
||||||
// 此处更新和 controllerManager 更新 StatefulSet 都会触发更新事件,导致循环触发
|
// 此处更新和 controllerManager 更新 StatefulSet 都会触发更新事件,导致循环触发
|
||||||
|
Loading…
Reference in New Issue
Block a user