Skip to content
Permalink
Browse files

Merge pull request #265 from chengyumeng/automated-cherry-pick-of-#25…

…8-release-v1.3

Fix get pod info API bug that label should be a key not a map
  • Loading branch information...
wilhelmguo committed Feb 12, 2019
2 parents e17663c + f7a4f0d commit 2dcd4785c18bcf859025f1940c76493f996757e9
Showing with 19 additions and 9 deletions.
  1. +1 −9 src/backend/controllers/openapi/pod.go
  2. +18 −0 src/backend/resources/pod/pod.go
@@ -5,8 +5,6 @@ import (
"net/http"
"strings"

"k8s.io/apimachinery/pkg/labels"

"github.com/Qihoo360/wayne/src/backend/client"
"github.com/Qihoo360/wayne/src/backend/models"
"github.com/Qihoo360/wayne/src/backend/models/response"
@@ -79,13 +77,7 @@ func (c *OpenAPIController) GetPodInfo() {
return
}

label, err := labels.ConvertSelectorToLabelsMap(params.LabelSelector)
if err != nil {
c.AddErrorAndResponse(fmt.Sprintf("Invalid LabelSelector parameter: %v!", err), http.StatusBadRequest)
return
}

pods, err := pod.ListPod(manager.CacheFactory, "", label)
pods, err := pod.ListPodByLabelKey(manager.CacheFactory, "", params.LabelSelector)
if err != nil {
logs.Error(fmt.Sprintf("Failed to parse metadata: %s", err.Error()))
c.AddErrorAndResponse(fmt.Sprintf("Maybe a problematic k8s cluster(%s)!", params.Cluster), http.StatusInternalServerError)
@@ -71,6 +71,24 @@ func ListKubePod(indexer *client.CacheFactory, namespace string, label map[strin
return pods, nil
}

func ListPodByLabelKey(indexer *client.CacheFactory, namespace string, label string) ([]*Pod, error) {
podSelector := map[string]string{}
podList, err := ListKubePod(indexer, namespace, podSelector)
if err != nil {
return nil, err
}
pods := make([]*Pod, 0)
for _, pod := range podList {
if pod.Labels[label] != "" {
pods = append(pods, &Pod{
Labels: pod.Labels,
PodIp: pod.Status.PodIP,
})
}
}
return pods, nil
}

func GetPodsByStatefulset(indexer *client.CacheFactory, namespace, name string) ([]*Pod, error) {
podSelector := map[string]string{"app": name}
pods, err := ListKubePod(indexer, namespace, podSelector)

0 comments on commit 2dcd478

Please sign in to comment.
You can’t perform that action at this time.