Skip to content
This repository has been archived by the owner on Apr 20, 2021. It is now read-only.

Commit

Permalink
Merge pull request weaveworks#2132 from weaveworks/2049-get-local-pod…
Browse files Browse the repository at this point in the history
…s-from-kubelet

Obtain local pods from kubelet
  • Loading branch information
Alfonso Acosta authored Jan 19, 2017
2 parents 87c15a1 + c6f7bdc commit 87f1c0f
Show file tree
Hide file tree
Showing 5 changed files with 3,768 additions and 38 deletions.
38 changes: 38 additions & 0 deletions probe/kubernetes/kubelet.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package kubernetes

import (
"net/http"

"github.com/ugorji/go/codec"
)

// KubeletURL is just exported for testing
var KubeletURL = "http://localhost:10255"

// 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() (map[string]struct{}, error) {
resp, err := http.Get(KubeletURL + "/pods/")
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
}
Loading

0 comments on commit 87f1c0f

Please sign in to comment.