Skip to content

Commit 2dcd478

Browse files
author
wilhelmguo
authored
Merge pull request Qihoo360#265 from chengyumeng/automated-cherry-pick-of-#258-release-v1.3
Fix get pod info API bug that label should be a key not a map
2 parents e17663c + f7a4f0d commit 2dcd478

2 files changed

Lines changed: 19 additions & 9 deletions

File tree

src/backend/controllers/openapi/pod.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ import (
55
"net/http"
66
"strings"
77

8-
"k8s.io/apimachinery/pkg/labels"
9-
108
"github.com/Qihoo360/wayne/src/backend/client"
119
"github.com/Qihoo360/wayne/src/backend/models"
1210
"github.com/Qihoo360/wayne/src/backend/models/response"
@@ -79,13 +77,7 @@ func (c *OpenAPIController) GetPodInfo() {
7977
return
8078
}
8179

82-
label, err := labels.ConvertSelectorToLabelsMap(params.LabelSelector)
83-
if err != nil {
84-
c.AddErrorAndResponse(fmt.Sprintf("Invalid LabelSelector parameter: %v!", err), http.StatusBadRequest)
85-
return
86-
}
87-
88-
pods, err := pod.ListPod(manager.CacheFactory, "", label)
80+
pods, err := pod.ListPodByLabelKey(manager.CacheFactory, "", params.LabelSelector)
8981
if err != nil {
9082
logs.Error(fmt.Sprintf("Failed to parse metadata: %s", err.Error()))
9183
c.AddErrorAndResponse(fmt.Sprintf("Maybe a problematic k8s cluster(%s)!", params.Cluster), http.StatusInternalServerError)

src/backend/resources/pod/pod.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,24 @@ func ListKubePod(indexer *client.CacheFactory, namespace string, label map[strin
7171
return pods, nil
7272
}
7373

74+
func ListPodByLabelKey(indexer *client.CacheFactory, namespace string, label string) ([]*Pod, error) {
75+
podSelector := map[string]string{}
76+
podList, err := ListKubePod(indexer, namespace, podSelector)
77+
if err != nil {
78+
return nil, err
79+
}
80+
pods := make([]*Pod, 0)
81+
for _, pod := range podList {
82+
if pod.Labels[label] != "" {
83+
pods = append(pods, &Pod{
84+
Labels: pod.Labels,
85+
PodIp: pod.Status.PodIP,
86+
})
87+
}
88+
}
89+
return pods, nil
90+
}
91+
7492
func GetPodsByStatefulset(indexer *client.CacheFactory, namespace, name string) ([]*Pod, error) {
7593
podSelector := map[string]string{"app": name}
7694
pods, err := ListKubePod(indexer, namespace, podSelector)

0 commit comments

Comments
 (0)