Skip to content

Commit

Permalink
Added FieldSelector: status.phase=Running when looking for Pods. Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
cjimti committed Aug 12, 2019
1 parent 99e6407 commit 6a86353
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions cmd/kubefwd/services/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,23 +266,28 @@ func fwdServices(opts FwdServiceOpts) error {
selector := mapToSelectorStr(svc.Spec.Selector)

if selector == "" {
log.Warnf("WARNING: No backing pods for service %s in %s on cluster %s.\n", svc.Name, svc.Namespace, svc.ClusterName)
log.Warnf("WARNING: No Pod selector for service %s in %s on cluster %s.\n", svc.Name, svc.Namespace, svc.ClusterName)

continue
}

pods, err := opts.ClientSet.CoreV1().Pods(svc.Namespace).List(metav1.ListOptions{LabelSelector: selector})
listOpts := metav1.ListOptions{
LabelSelector: selector,
FieldSelector: "status.phase=Running",
}

pods, err := opts.ClientSet.CoreV1().Pods(svc.Namespace).List(listOpts)

if err != nil {
log.Warnf("WARNING: No pods found for %s: %s\n", selector, err.Error())
log.Warnf("WARNING: No Running Pods found for %s: %s\n", selector, err.Error())

// TODO: try again after a time

continue
}

if len(pods.Items) < 1 {
log.Warnf("WARNING: No pods returned for service %s in %s on cluster %s.\n", svc.Name, svc.Namespace, svc.ClusterName)
log.Warnf("WARNING: No Running Pods returned for service %s in %s on cluster %s.\n", svc.Name, svc.Namespace, svc.ClusterName)

// TODO: try again after a time

Expand Down

4 comments on commit 6a86353

@rshelby5
Copy link

@rshelby5 rshelby5 commented on 6a86353 Aug 19, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cjimti what version is this in now? And I use it like kubefwd svc -n service -l status.phase=Running correct?

@cjimti
Copy link
Member Author

@cjimti cjimti commented on 6a86353 Aug 19, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rshelby5 I'm not sure I understand the question. The -l allows you to specify any valid selector, for services.

@rshelby5
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cjimti What is the correct command to forward to only running pods?

@cjimti
Copy link
Member Author

@cjimti cjimti commented on 6a86353 Aug 19, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll need to look into this issue.

Please sign in to comment.