/
kubelet.go
executable file
·37 lines (33 loc) · 982 Bytes
/
kubelet.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package kubernetes
import (
"fmt"
"net/http"
"github.com/ugorji/go/codec"
)
// Intentionally not using the full kubernetes library DS
// to make parsing faster and more tolerant to schema changes
type podList struct {
Items []struct {
Metadata struct {
UID string `json:"uid"`
} `json:"metadata"`
} `json:"items"`
}
// GetLocalPodUIDs obtains the UID of the pods run locally (it's just exported for testing)
var GetLocalPodUIDs = func(kubeletHost string) (map[string]struct{}, error) {
url := fmt.Sprintf("http://%s/pods/", kubeletHost)
resp, err := http.Get(url)
if err != nil {
return nil, err
}
defer resp.Body.Close()
var localPods podList
if err := codec.NewDecoder(resp.Body, &codec.JsonHandle{}).Decode(&localPods); err != nil {
return nil, err
}
result := make(map[string]struct{}, len(localPods.Items))
for _, pod := range localPods.Items {
result[pod.Metadata.UID] = struct{}{}
}
return result, nil
}