Skip to content

Commit

Permalink
Simplify pod name matching
Browse files Browse the repository at this point in the history
Signed-off-by: Mathieu Champlon <mathieu.champlon@docker.com>
  • Loading branch information
mat007 committed May 15, 2018
1 parent 76e194e commit 1e6ea25
Showing 1 changed file with 22 additions and 21 deletions.
43 changes: 22 additions & 21 deletions cli/command/stack/kubernetes/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,34 +78,35 @@ func fetchPods(stackName string, pods corev1.PodInterface, f filters.Args) ([]ap
}
}
listOpts := metav1.ListOptions{LabelSelector: labels.SelectorForStack(stackName, services...)}
nodes := f.Get("node")
var result []apiv1.Pod
if len(nodes) == 0 {
podsList, err := pods.List(listOpts)
if err != nil {
return nil, err
}
result = podsList.Items
} else {
for _, n := range nodes {
listOpts.FieldSelector = "spec.nodeName=" + n
podsList, err := pods.List(listOpts)
if err != nil {
return nil, err
}
result = append(result, podsList.Items...)
}
podsList, err := pods.List(listOpts)
if err != nil {
return nil, err
}
// name filters is done client side for matching partials
for i := len(result) - 1; i >= 0; i-- {
fullName := stackNamePrefix + result[i].Name
if !f.FuzzyMatch("name", fullName) {
result = append(result[:i], result[i+1:]...)
nodes := f.Get("node")
for _, pod := range podsList.Items {
if filterPod(pod, nodes) &&
// name filter is done client side for matching partials
f.FuzzyMatch("name", stackNamePrefix+pod.Name) {

result = append(result, pod)
}
}
return result, nil
}

func filterPod(pod apiv1.Pod, nodes []string) bool {
if len(nodes) == 0 {
return true
}
for _, name := range nodes {
if pod.Spec.NodeName == name {
return true
}
}
return false
}

func getContainerImage(containers []apiv1.Container) string {
if len(containers) == 0 {
return ""
Expand Down

0 comments on commit 1e6ea25

Please sign in to comment.