Set the pod phase based on pod restart policy when provider failed (#361)
Update the resource manager to include the deleting pods in the GetPods function
This commit is contained in:
@@ -86,16 +86,14 @@ func (rm *ResourceManager) SetPods(pods *v1.PodList) {
|
||||
rm.Lock()
|
||||
defer rm.Unlock()
|
||||
|
||||
rm.pods = make(map[string]*v1.Pod, len(pods.Items))
|
||||
rm.configMapRef = make(map[string]int64, 0)
|
||||
rm.secretRef = make(map[string]int64, 0)
|
||||
rm.configMaps = make(map[string]*v1.ConfigMap, len(pods.Items))
|
||||
rm.secrets = make(map[string]*v1.Secret, len(pods.Items))
|
||||
|
||||
for k, p := range pods.Items {
|
||||
rm.pods[rm.getStoreKey(p.Namespace, p.Name)] = &pods.Items[k]
|
||||
|
||||
rm.incrementRefCounters(&p)
|
||||
podKey := rm.getStoreKey(p.Namespace, p.Name)
|
||||
if p.DeletionTimestamp != nil {
|
||||
rm.deletingPods[podKey] = &pods.Items[k]
|
||||
} else {
|
||||
rm.pods[podKey] = &pods.Items[k]
|
||||
rm.incrementRefCounters(&p)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -173,10 +171,13 @@ func (rm *ResourceManager) GetPods() []*v1.Pod {
|
||||
rm.RLock()
|
||||
defer rm.RUnlock()
|
||||
|
||||
pods := make([]*v1.Pod, 0, len(rm.pods))
|
||||
pods := make([]*v1.Pod, 0, len(rm.pods)+len(rm.deletingPods))
|
||||
for _, p := range rm.pods {
|
||||
pods = append(pods, p)
|
||||
}
|
||||
for _, p := range rm.deletingPods {
|
||||
pods = append(pods, p)
|
||||
}
|
||||
|
||||
return pods
|
||||
}
|
||||
|
||||
@@ -349,7 +349,11 @@ func (s *Server) reconcile(ctx context.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
if pod.DeletionTimestamp == nil && pod.Status.Phase != corev1.PodFailed && providerPod == nil {
|
||||
if providerPod == nil &&
|
||||
pod.DeletionTimestamp == nil &&
|
||||
pod.Status.Phase != corev1.PodSucceeded &&
|
||||
pod.Status.Phase != corev1.PodFailed &&
|
||||
pod.Status.Reason != PodStatusReason_ProviderFailed {
|
||||
logger.Debug("Creating pod")
|
||||
if err := s.createPod(ctx, pod); err != nil {
|
||||
logger.WithError(err).Error("Error creating pod")
|
||||
@@ -378,8 +382,13 @@ func (s *Server) createPod(ctx context.Context, pod *corev1.Pod) error {
|
||||
logger := log.G(ctx).WithField("pod", pod.Name)
|
||||
|
||||
if origErr := s.provider.CreatePod(ctx, pod); origErr != nil {
|
||||
podPhase := corev1.PodPending
|
||||
if pod.Spec.RestartPolicy == corev1.RestartPolicyNever {
|
||||
podPhase = corev1.PodFailed
|
||||
}
|
||||
|
||||
pod.ResourceVersion = "" // Blank out resource version to prevent object has been modified error
|
||||
pod.Status.Phase = corev1.PodFailed
|
||||
pod.Status.Phase = podPhase
|
||||
pod.Status.Reason = PodStatusReason_ProviderFailed
|
||||
pod.Status.Message = origErr.Error()
|
||||
|
||||
@@ -426,7 +435,9 @@ func (s *Server) updatePodStatuses(ctx context.Context) {
|
||||
// Update all the pods with the provider status.
|
||||
pods := s.resourceManager.GetPods()
|
||||
for _, pod := range pods {
|
||||
if pod.Status.Phase == corev1.PodSucceeded || (pod.Status.Phase == corev1.PodFailed && pod.Status.Reason == PodStatusReason_ProviderFailed) {
|
||||
if pod.Status.Phase == corev1.PodSucceeded ||
|
||||
pod.Status.Phase == corev1.PodFailed ||
|
||||
pod.Status.Reason == PodStatusReason_ProviderFailed {
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user