Skip to content

Commit

Permalink
Merge pull request #265 from chengyumeng/automated-cherry-pick-of-#25…
Browse files Browse the repository at this point in the history
…8-release-v1.3

Fix get pod info API bug that label should be a key not a map
  • Loading branch information
wilhelmguo authored Feb 12, 2019
2 parents e17663c + f7a4f0d commit 2dcd478
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
10 changes: 1 addition & 9 deletions src/backend/controllers/openapi/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down
18 changes: 18 additions & 0 deletions src/backend/resources/pod/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 2dcd478

Please sign in to comment.