Skip to content

Commit

Permalink
Filter failed pods
Browse files Browse the repository at this point in the history
  • Loading branch information
mhindery committed Jun 4, 2020
1 parent 8e5323c commit 3a5603f
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions pkg/fwdservice/fwdservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ func (svcFwd *ServiceFWD) String() string {
}

// GetPodsForService queries k8s and returns all pods backing this service
// which are eligible for portforwarding; exclude some pods which are in final/failure state.
func (svcfwd *ServiceFWD) GetPodsForService() []v1.Pod {
listOpts := metav1.ListOptions{LabelSelector: svcfwd.PodLabelSelector}

Expand All @@ -62,7 +63,15 @@ func (svcfwd *ServiceFWD) GetPodsForService() []v1.Pod {
return nil
}

return pods.Items
podsEligible := make([]v1.Pod, 0, len(pods.Items))

for _, pod := range pods.Items {
if pod.Status.Phase == v1.PodPending || pod.Status.Phase == v1.PodRunning {
podsEligible = append(podsEligible, pod)
}
}

return podsEligible
}

// SyncPodForwards selects one or all pods behind a service, and invokes the forwarding setup for that or those pod(s).
Expand All @@ -74,6 +83,7 @@ func (svcfwd *ServiceFWD) SyncPodForwards(force bool) {
log.Debugf("Skipping pods refresh for %s due to rate limiting", svcfwd)
return
}
defer func() { svcfwd.LastSyncedAt = time.Now() }()

k8sPods := svcfwd.GetPodsForService()

Expand Down Expand Up @@ -131,8 +141,6 @@ func (svcfwd *ServiceFWD) SyncPodForwards(force bool) {
}
}
}

svcfwd.LastSyncedAt = time.Now()
}

// LoopPodsToForward starts the portforwarding for each pod in the given list
Expand Down

0 comments on commit 3a5603f

Please sign in to comment.