Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kubectl: Use metrics-server for kubectl top commands #56206

Merged
merged 1 commit into from
Jan 23, 2018

Conversation

brancz
Copy link
Member

@brancz brancz commented Nov 22, 2017

What this PR does / why we need it:

This PR implements support for the kubectl top commands to use the metrics-server as an aggregated API, instead of requesting the metrics from heapster directly. If the metrics.k8s.io API is not served by the apiserver, then this still falls back to the previous behavior.

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):

Fixes #55489

Special notes for your reviewer:

As utilizing heapster as well as the v1alpha1 version of the metrics API is discouraged, I intentionally implemented the support very separated, so that once it is decided, that support is entirely removed, this will make it easy.

Release note:

Support metrics API in `kubectl top` commands.

/cc @kubernetes/sig-instrumentation-pr-reviews @DirectXMan12 @fgrzadkowski @piosz

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/instrumentation Categorizes an issue or PR as relevant to SIG Instrumentation. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Nov 22, 2017
@brancz
Copy link
Member Author

brancz commented Nov 22, 2017

/cc @kubernetes/sig-cli-maintainers

@fgrzadkowski
Copy link
Contributor

@piosz

@k8s-github-robot k8s-github-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 23, 2017
@k8s-github-robot k8s-github-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 23, 2017
@brancz
Copy link
Member Author

brancz commented Nov 23, 2017

/test pull-kubernetes-e2e-gce-device-plugin-gpu

Copy link
Contributor

@DirectXMan12 DirectXMan12 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

overall looks fine. I'd add a comment to the code about why the getNodeMetricsFromMetricsAPI isn't just implementing the same interface as the existing client (your logic makes sense, but you should probably leave a note).

Can you simplify the testing by using a fake metrics client instead of stubbing out the HTTP client?

fakeClient := f.tf.Client.(*fake.RESTClient)
clientset := metricsclientset.NewForConfigOrDie(f.tf.ClientConfig)

clientset.MetricsV1alpha1().RESTClient().(*restclient.RESTClient).Client = fakeClient.Client
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we've got fake clientsets generated for the metrics clients. Do you really need to do this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tried that and getting this error:

error: no kind "NodeMetricsList" is registered for version "metrics/v1beta1"

Any idea?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm... not off the top of my head. I'll have to try and reproduce locally

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll prepare a branch to share to show you what I mean.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what I did wrong there, but I managed to get it to work. Do you mind re-reviewing @DirectXMan12 ? :) (oh and happy new year! 🎉)

@rootfs
Copy link
Contributor

rootfs commented Nov 30, 2017

/unassign

@brancz
Copy link
Member Author

brancz commented Dec 10, 2017

Due to KubeCon and now vacation this was delayed a bit, but I'm hoping I will get back to it the week before Christmas.

@k8s-github-robot k8s-github-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Dec 14, 2017
@k8s-github-robot k8s-github-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Dec 26, 2017
@kubernetes kubernetes deleted a comment from k8s-github-robot Dec 26, 2017
@brancz
Copy link
Member Author

brancz commented Dec 31, 2017

/test pull-kubernetes-e2e-gce-device-plugin-gpu

@brancz
Copy link
Member Author

brancz commented Jan 2, 2018

Now using the fake metrics client in tests as suggested by @DirectXMan12. PTAL @fgrzadkowski @piosz @DirectXMan12 .

Copy link
Contributor

@DirectXMan12 DirectXMan12 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we're almost there. A couple more issues with the tests, and the discovery mechanics may need tweaking.

tf.Printer = &testPrinter{}
tf.Client = &fake.RESTClient{
NegotiatedSerializer: ns,
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if this is for discovery, this should be structured so that you can use a fake version of the discovery client to accomplish this. You should basically never have to use a fake HTTP client except for when simulating a Heapster response

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is, but the problem is that the underlying testFactory deeply integrates only with the fake rest client. My feeling is that changing that is out of scope for this PR, it would have a lot of impact on the kubectl code, and those changes would be much larger then the PR so far.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ack, we'll put that off until later.

if group.Name == metricsapi.GroupName {
metricsAPIAvailable = true
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might want to check version as well

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively, we could try the metrics API client out of the box, and then retrying with the Heapster client if it returns a NotFound error. I'm conflicted as to which is the correct approach

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes true, I'll make sure to add a version check.

@piosz piosz assigned piosz and DirectXMan12 and unassigned shiywang Jan 11, 2018
@piosz
Copy link
Member

piosz commented Jan 11, 2018

@kubernetes/kubectl-maintainers

@piosz
Copy link
Member

piosz commented Jan 11, 2018

/lgtm
Many thanks for doing this.
Apologies for the huge delay.

@soltysh
Copy link
Contributor

soltysh commented Jan 18, 2018

/retest

/assign @pwittrock
for approval

@k8s-github-robot k8s-github-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jan 22, 2018
@brancz
Copy link
Member Author

brancz commented Jan 23, 2018

/test pull-kubernetes-e2e-kops-aws

Copy link
Member

@piosz piosz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jan 23, 2018
@DirectXMan12
Copy link
Contributor

/lgtm

just waiting on someone from the kubectl owners.
ping @kubernetes/sig-cli-pr-reviews can someone take a look and approve?

@k8s-ci-robot k8s-ci-robot added the sig/cli Categorizes an issue or PR as relevant to SIG CLI. label Jan 23, 2018
@pwittrock
Copy link
Member

/approve no-issue

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: brancz, DirectXMan12, piosz, pwittrock, soltysh

Associated issue: #55489

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these OWNERS Files:

You can indicate your approval by writing /approve in a comment
You can cancel your approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jan 23, 2018
@k8s-github-robot
Copy link

Automatic merge from submit-queue (batch tested with PRs 56206, 58525). If you want to cherry-pick this change to another branch, please follow the instructions here.

@k8s-github-robot k8s-github-robot merged commit 3cbb62b into kubernetes:master Jan 23, 2018
@brancz brancz deleted the top-metrics-s branch January 23, 2018 21:21
olivierlemasle added a commit to olivierlemasle/kubernetes that referenced this pull request Aug 12, 2019
Since kubernetes#56206, `kubectl top` uses the Resource Metrics API (metrics.k8s.io)
and falls back to Heapster, which is deprecated. This commit updates the
description of command `kubectl top` to reflect this behavior.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/cli Categorizes an issue or PR as relevant to SIG CLI. sig/instrumentation Categorizes an issue or PR as relevant to SIG Instrumentation. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

kubectl top needs to use the actual metrics client
10 participants