Conversation
|
Nice! Could you try using https://github.com/ericchiang/k8s instead? It's way slimmer and should be more than enough for our use case. The interface is very similar so you shouldn't have to change many things. |
|
@zippolyte We're currently using the bloated k8s client in the metadata package, If the lightweight client works as expected, could you open another PR and use the new client for metadata too? (see https://github.com/DataDog/datadog-agent/blob/master/pkg/metadata/kubernetes/kubernetes.go) |
Based on feedback in #285 we can use a smaller library that pulls in significantly fewer dependencies. The only trade-off is that we need to use getters in function calls to avoid pointers everywhere because this is using older style protobuf generated code.
There was a problem hiding this comment.
This method queries the API server for the list of pods (see here). There may be a use case for it, but I think we should avoid doing this by default, otherwise we'll put some heavy load on the apiserver.
Maybe rename GetPodList to GetGlobalPodList, and add to the comment that this hits the apiserver so we should use it with caution?
For GetNodeInfo we likely don't need to use this method. We can connect to the local kubelet directly (by making sure users give the agent access to it in the config - we also have some dark magic here in case they don't, ping me if you need more details) and request /pods/ (maybe create a GetLocalPodList that does that)?. This gives you a list of locally running pods.
Once you have that list, you can pick whichever pod you want and extract spec.nodeName and spec.hostIP (just make sure the pod doesn't have spec.hostNetwork set to true or you won't find an IP address). So this gives you the same result but by only querying the local kubelet instead of the global store.
|
we merged #291 you might want to rebase there to resolve conflicts on glide yaml and lock file |
97e2125 to
4b689e8
Compare
8fb2cb5 to
9b01943
Compare
9b01943 to
95045ca
Compare
hkaj
left a comment
There was a problem hiding this comment.
that looks good to me, although I would like to test it. Let's build a test package where it's used
| } | ||
|
|
||
| // PerformKubeletQuery performs a GET query against kubelet and return the response body | ||
| // Supports auth |
masci
left a comment
There was a problem hiding this comment.
A couple of things to fix, then let's think about how could we test this (integration or system)
|
|
||
| // Try and find the hostname to query the kubelet | ||
| func locateKubelet(kubeletHost string, kubeletPort int) (string, error) { | ||
| host := os.Getenv("KUBERNETES_KUBELET_HOST") |
There was a problem hiding this comment.
Let's move this in a config option, we can always set it from the outside like DD_ KUBERNETES_KUBELET_HOST, this way seems more consistent to me
| host := os.Getenv("KUBERNETES_KUBELET_HOST") | ||
| var err error | ||
| if host == "" { | ||
| host = kubeletHost |
There was a problem hiding this comment.
Not sure an env var should take precedence over a function param.
Question: why NewKubeUtil takes the host as a param? If we want the caller to be able to set it, we should remove any local override. On the other end, if we want the caller to be agnostic of the host, let's remove the param from NewKubeUtil and access KUBERNETES_KUBELET_HOST from the settings (see previous comment) before passing it to locateKubelet
There was a problem hiding this comment.
I was trying to replicate the order of precedence that we had in the kube_util of agent 5, where we would pass an instance to this function that could have kubelet_host and kubelet_port set in it, and the env var would take precedence.
My idea was that the check using this would pass whatever was in its config to the function, and let the utility do its thing.
But yeah I agree this isn't really intuitive, and a config option seems better
| } | ||
| } | ||
|
|
||
| port := kubeletPort |
There was a problem hiding this comment.
I'd move this to a setting as well
|
|
||
| // PerformKubeletQuery performs a GET query against kubelet and return the response body | ||
| // Supports auth | ||
| func PerformKubeletQuery(url string) ([]byte, error) { |
There was a problem hiding this comment.
Not sure the module should export this func
There was a problem hiding this comment.
We'll need to run Kubelet queries from other places as well, so either we export this method and build the URL where it's needed, or we don't export it and all the queries we need to run will be triggered by new functions we'll add here as needed. Honestly not sure what's the best solution here.
There was a problem hiding this comment.
Maybe we should do both. I think concentrating wrapper functions here is part of the goal of the module itself but keeping this function exported might be a feature more than an issue. Let's keep it like this, ignore my comment.
masci
left a comment
There was a problem hiding this comment.
One last comment and we're there!
| // Kubelet constants | ||
| const ( | ||
| AuthTokenPath = "/var/run/secrets/kubernetes.io/serviceaccount/token" | ||
| DefaultHTTPKubeletPort = 10255 |
There was a problem hiding this comment.
could we set default port and host settings in init like we do for example here?
datadog-agent/pkg/metadata/scheduler.go
Line 17 in d9e459b
|
Curious if we want consistency on kubernetes vs k8s? Right now the meta provider is using |
|
I think we should consolidate package and settings names to |
|
We need integration tests for kubernetes, useful both for the util package and the k8s metadata collector. Let's merge this and do that in another PR. |
Bumps [golang.org/x/oauth2](https://github.com/golang/oauth2) from 0.33.0 to 0.34.0. - [Commits](golang/oauth2@v0.33.0...v0.34.0) --- updated-dependencies: - dependency-name: golang.org/x/oauth2 dependency-version: 0.34.0 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
What does this PR do?
Initial k8s util implementation