2323package resources
2424
2525import (
26+ "fmt"
27+ "time"
28+
2629 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil"
2730 "k8s.io/api/core/v1"
2831
3437 inspectedPodCounter = metrics .MustRegisterCounter ("deployment" , "inspected_pods" , "Number of pod inspections" )
3538)
3639
40+ const (
41+ podScheduleTimeout = time .Minute // How long we allow the schedule to take scheduling a pod.
42+ )
43+
3744// InspectPods lists all pods that belong to the given deployment and updates
3845// the member status of the deployment accordingly.
3946func (r * Resources ) InspectPods () error {
@@ -49,6 +56,8 @@ func (r *Resources) InspectPods() error {
4956 // Update member status from all pods found
5057 status := r .context .GetStatus ()
5158 apiObject := r .context .GetAPIObject ()
59+ var podNamesWithScheduleTimeout []string
60+ var unscheduledPodNames []string
5261 for _ , p := range pods {
5362 if k8sutil .IsArangoDBImageIDAndVersionPod (p ) {
5463 // Image ID pods are not relevant to inspect here
@@ -93,6 +102,13 @@ func (r *Resources) InspectPods() error {
93102 updateMemberStatusNeeded = true
94103 }
95104 }
105+ if k8sutil .IsPodNotScheduledFor (& p , podScheduleTimeout ) {
106+ // Pod cannot be scheduled for to long
107+ log .Debug ().Str ("pod-name" , p .GetName ()).Msg ("Pod scheduling timeout" )
108+ podNamesWithScheduleTimeout = append (podNamesWithScheduleTimeout , p .GetName ())
109+ } else if ! k8sutil .IsPodScheduled (& p ) {
110+ unscheduledPodNames = append (unscheduledPodNames , p .GetName ())
111+ }
96112 if updateMemberStatusNeeded {
97113 if err := status .Members .UpdateMemberStatus (memberStatus , group ); err != nil {
98114 return maskAny (err )
@@ -146,6 +162,22 @@ func (r *Resources) InspectPods() error {
146162 allMembersReady := status .Members .AllMembersReady ()
147163 status .Conditions .Update (api .ConditionTypeReady , allMembersReady , "" , "" )
148164
165+ // Update conditions
166+ if len (podNamesWithScheduleTimeout ) > 0 {
167+ if status .Conditions .Update (api .ConditionTypePodSchedulingFailure , true ,
168+ "Pods Scheduling Timeout" ,
169+ fmt .Sprintf ("The following pods cannot be scheduled: %v" , podNamesWithScheduleTimeout )) {
170+ r .context .CreateEvent (k8sutil .NewPodsSchedulingFailureEvent (podNamesWithScheduleTimeout , r .context .GetAPIObject ()))
171+ }
172+ } else if status .Conditions .IsTrue (api .ConditionTypePodSchedulingFailure ) &&
173+ len (unscheduledPodNames ) == 0 {
174+ if status .Conditions .Update (api .ConditionTypePodSchedulingFailure , false ,
175+ "Pods Scheduling Resolved" ,
176+ "No pod reports a scheduling timeout" ) {
177+ r .context .CreateEvent (k8sutil .NewPodsSchedulingResolvedEvent (r .context .GetAPIObject ()))
178+ }
179+ }
180+
149181 // Save status
150182 if err := r .context .UpdateStatus (status ); err != nil {
151183 return maskAny (err )
0 commit comments