From 1adbf389658f2e746c9c56754687b421d367e313 Mon Sep 17 00:00:00 2001 From: Adam Janikowski <12255597+ajanikow@users.noreply.github.com> Date: Thu, 20 Oct 2022 14:53:26 +0200 Subject: [PATCH] [Feature] Pod Scheduled condition (#1152) --- CHANGELOG.md | 1 + pkg/apis/deployment/v1/conditions.go | 2 ++ pkg/apis/deployment/v2alpha1/conditions.go | 2 ++ pkg/deployment/member/phase_updates.go | 1 + pkg/deployment/resources/pod_inspector.go | 19 +++++++++++++------ 5 files changed, 19 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 77e4843de..fed26afb1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ - (Bugfix) Fix Go routine leak - (Feature) Extend Pod Security context - (Improvement) Update DeploymentReplicationStatus on configuration error +- (Feature) Pod Scheduled condition ## [1.2.19](https://github.com/arangodb/kube-arangodb/tree/1.2.19) (2022-10-05) - (Bugfix) Prevent changes when UID is wrong diff --git a/pkg/apis/deployment/v1/conditions.go b/pkg/apis/deployment/v1/conditions.go index eacb6b7f5..10e90e4bb 100644 --- a/pkg/apis/deployment/v1/conditions.go +++ b/pkg/apis/deployment/v1/conditions.go @@ -41,6 +41,8 @@ const ( ConditionTypeStarted ConditionType = "Started" // ConditionTypeReachable indicates that the member is reachable. ConditionTypeReachable ConditionType = "Reachable" + // ConditionTypeScheduled indicates that the member primary pod is scheduled. + ConditionTypeScheduled ConditionType = "Scheduled" // ConditionTypeServing indicates that the member core services are running. ConditionTypeServing ConditionType = "Serving" // ConditionTypeActive indicates that the member server container started. diff --git a/pkg/apis/deployment/v2alpha1/conditions.go b/pkg/apis/deployment/v2alpha1/conditions.go index 8178cf82e..891e6c857 100644 --- a/pkg/apis/deployment/v2alpha1/conditions.go +++ b/pkg/apis/deployment/v2alpha1/conditions.go @@ -41,6 +41,8 @@ const ( ConditionTypeStarted ConditionType = "Started" // ConditionTypeReachable indicates that the member is reachable. ConditionTypeReachable ConditionType = "Reachable" + // ConditionTypeScheduled indicates that the member primary pod is scheduled. + ConditionTypeScheduled ConditionType = "Scheduled" // ConditionTypeServing indicates that the member core services are running. ConditionTypeServing ConditionType = "Serving" // ConditionTypeActive indicates that the member server container started. diff --git a/pkg/deployment/member/phase_updates.go b/pkg/deployment/member/phase_updates.go index 4156a8f9b..2d3760a35 100644 --- a/pkg/deployment/member/phase_updates.go +++ b/pkg/deployment/member/phase_updates.go @@ -84,6 +84,7 @@ func removeMemberConditionsMapFunc(m *api.MemberStatus) { m.Conditions.Remove(api.ConditionTypeReady) m.Conditions.Remove(api.ConditionTypeActive) m.Conditions.Remove(api.ConditionTypeStarted) + m.Conditions.Remove(api.ConditionTypeScheduled) m.Conditions.Remove(api.ConditionTypeReachable) m.Conditions.Remove(api.ConditionTypeServing) m.Conditions.Remove(api.ConditionTypeTerminated) diff --git a/pkg/deployment/resources/pod_inspector.go b/pkg/deployment/resources/pod_inspector.go index 99b31dcdd..ac8ba1f7e 100644 --- a/pkg/deployment/resources/pod_inspector.go +++ b/pkg/deployment/resources/pod_inspector.go @@ -360,12 +360,19 @@ func (r *Resources) InspectPods(ctx context.Context, cachedStatus inspectorInter } } - if k8sutil.IsPodNotScheduledFor(pod, podScheduleTimeout) { - // Pod cannot be scheduled for to long - log.Str("pod-name", pod.GetName()).Debug("Pod scheduling timeout") - podNamesWithScheduleTimeout = append(podNamesWithScheduleTimeout, pod.GetName()) - } else if !k8sutil.IsPodScheduled(pod) { - unscheduledPodNames = append(unscheduledPodNames, pod.GetName()) + if k8sutil.IsPodScheduled(pod) { + if memberStatus.Conditions.Update(api.ConditionTypeScheduled, true, "Pod is scheduled", "") { + updateMemberStatusNeeded = true + nextInterval = nextInterval.ReduceTo(recheckSoonPodInspectorInterval) + } + } else { + if k8sutil.IsPodNotScheduledFor(pod, podScheduleTimeout) { + // Pod cannot be scheduled for to long + log.Str("pod-name", pod.GetName()).Debug("Pod scheduling timeout") + podNamesWithScheduleTimeout = append(podNamesWithScheduleTimeout, pod.GetName()) + } else { + unscheduledPodNames = append(unscheduledPodNames, pod.GetName()) + } } if k8sutil.IsPodMarkedForDeletion(pod) {