This repository has been archived by the owner on Apr 20, 2021. It is now read-only.
forked from weaveworks/scope
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request weaveworks#2132 from weaveworks/2049-get-local-pod…
…s-from-kubelet Obtain local pods from kubelet
- Loading branch information
Showing
5 changed files
with
3,768 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
Oops, something went wrong.