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

Introduce types and clients for Metrics APIs #2

Merged
merged 5 commits into from
Feb 22, 2017

Conversation

DirectXMan12
Copy link
Contributor

This PR introduces types and clients for both the custom metrics API and the resource metrics API.

The resource metrics API uses autogenerated clients, while the custom metrics API, due the nature of it's URLs, uses a custom client.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Feb 20, 2017
@DirectXMan12
Copy link
Contributor Author

@piosz PTAL

@DirectXMan12
Copy link
Contributor Author

A couple of notes on this PR:

Generating the generated files requires kubernetes/repo-infra#7 (and needs to be placed in vendor).

I've tested this PR against my WIP copy of HPA v2 part III (use the custom metrics API, and also use the actual resource metrics API clients), so the code is at least sane enough to work properly (the bits required for the testing can be found at https://github.com/DirectXMan12/kubernetes/tree/feature/hpa-v2-use-cm-api and https://github.com/DirectXMan12/heapster/tree/feature/use-cm-types, which should turn into actual PRs shortly).

@kubernetes/sig-api-machinery-misc I wasn't sure how to avoid depending on k8s.io/client-go/pkg/api for the autogenerated clients -- a bunch of that autogenerated code seems to rely on api.{Scheme,etc} being a global. Any ideas there?

@piosz
Copy link
Member

piosz commented Feb 20, 2017

Can we split this PR into 2 separate ones: with custom metrics and metrics? Overall looks good for me, thought I'd like some from api-machinery team to take a look.

@piosz piosz self-assigned this Feb 20, 2017
@DirectXMan12
Copy link
Contributor Author

cc @kubernetes/sig-api-machinery-pr-reviews PTAL for general sanity

@deads2k
Copy link
Contributor

deads2k commented Feb 20, 2017

@kubernetes/sig-api-machinery-misc I wasn't sure how to avoid depending on k8s.io/client-go/pkg/api for the autogenerated clients -- a bunch of that autogenerated code seems to rely on api.{Scheme,etc} being a global. Any ideas there?

We have kubernetes/kubernetes#41486 open and lgtm'ed. Google US is out today, so we'll given Daniel a chance to take a look tomorrow.

@DirectXMan12
Copy link
Contributor Author

ack, I'll pull that into kubernetes/repo-infra#7 once it's merged, and then regen this PR

@DirectXMan12
Copy link
Contributor Author

This should be all set with regards to kubernetes/kubernetes#41486 -- I've regenerated with that code.

@DirectXMan12
Copy link
Contributor Author

After a quick glance-over from someone on @kubernetes/sig-api-machinery-pr-reviews, I'd like to get this merged so that the Kubernetes PRs depending on it can move forward

)

// GroupName is the group name use in this package
const GroupName = "custom-metrics"
Copy link
Contributor

Choose a reason for hiding this comment

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

group names should be domain qualified. This one looks like custom-metrics.metrics.k8s.io based on the repo name.


// +k8s:deepcopy-gen=package,register

package custom_metrics // import "k8s.io/metrics/pkg/apis/custom_metrics"
Copy link
Contributor

Choose a reason for hiding this comment

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

You'll need to specify a group name. See https://github.com/kubernetes/sample-apiserver/blob/master/pkg/apis/wardle/doc.go#L20 as an example.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

doesn't that tag only apply for generated clients? None-the-less, you're right, I should probably have it here.

)

// GroupName is the group name use in this package
const GroupName = "metrics"
Copy link
Contributor

Choose a reason for hiding this comment

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

domain qualify. "metrics.k8s.io" is legal for you if you want it.

Copy link
Contributor

Choose a reason for hiding this comment

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

domain qualify. "metrics.k8s.io" is legal for you if you want it.

But it could get really confusing when deciding if you're referring to a type or a group.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a pre-existing API, so it probably shouldn't change names, right?

Copy link
Contributor

Choose a reason for hiding this comment

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

This is a pre-existing API, so it probably shouldn't change names, right?

What version was your API? At an alpha or beta level, I'd consider cross registering and sunset the old.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it was alpha


// +genclient=true
// +resourceName=nodes
// +readonly=true
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't you need a "nonNamespaced" tag like here: https://github.com/kubernetes/kubernetes/blob/master/pkg/api/types.go#L2862 ?

Also, care to open an issue for us to add an example of this to the sample-apiserver?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, missed that tag (it wasn't present in the original types in Heapster). As for the resourceName and readonly tags, I have to submit a PR to get them into Kube's client-gen first probably, but yeah, I'll open an issue.

// Container name corresponding to the one from pod.spec.containers.
Name string
// The memory usage is the memory working set.
Usage api.ResourceList
Copy link
Contributor

Choose a reason for hiding this comment

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

Since you've done this, you'll need to be sure that you register the ResourceList and all transitive conversions and deep copies in the appropriate versions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ResourceList doesn't have a deepcopy, Resource has deepcopy as a method, ResourceList's conversion is marked copy-only, as is Resource's, which AFAICT, means it's not needed for nested conversions.

@deads2k
Copy link
Contributor

deads2k commented Feb 22, 2017

@DirectXMan12 DirectXMan12 force-pushed the feature/api-clients branch 2 times, most recently from dda58ab to fc35d23 Compare February 22, 2017 20:41
@DirectXMan12
Copy link
Contributor Author

Alright, I've addressed all the comments here, I believe (with the exception of cross-registering metrics, which we'll deal with later). I'm going to merge this so the dependent PRs can move forwards.

This commit includes non-generated custom metrics API types.
This commit updates the generated files for the custom metrics API.
This commit introduces the client for the custom metrics API.  The
API is written by hand, since the structure of the custom metrics API
does not lend itself to auto-generation.
This commit imports the resource metrics API types from Heapster.
The generated conversions and clients are in a separate commit.
This commit checks in the generated code (clientsets, informers,
listers, deepcopy, conversion, etc) that go with the resource metrics
API types.
@DirectXMan12 DirectXMan12 merged commit fd2415b into kubernetes:master Feb 22, 2017
@DirectXMan12 DirectXMan12 deleted the feature/api-clients branch February 22, 2017 21:53
k8s-github-robot pushed a commit to kubernetes/kubernetes that referenced this pull request Mar 1, 2017
Automatic merge from submit-queue

HPA Controller: Use Custom Metrics API

This commit switches over the HPA controller to use the custom metrics
API.  It also converts the HPA controller to use the generated client
in k8s.io/metrics for the resource metrics API.

In order to enable support, you must enable
`--horizontal-pod-autoscaler-use-rest-clients` on the
controller-manager, which will switch the HPA controller's MetricsClient
implementation over to use the standard rest clients for both custom
metrics and resource metrics.  This requires that at the least resource
metrics API is registered with kube-aggregator, and that the controller
manager is pointed at kube-aggregator.  For this to work, Heapster
must be serving the new-style API server (`--api-server=true`).

Before this merges, this will need kubernetes/metrics#2 to merge, and a godeps update to pull that in.
It's also semi-dependent on kubernetes-retired/heapster#1537, but that is not required in order for this to merge.

**Release note**:
```release-note
Allow the Horizontal Pod Autoscaler controller to talk to the metrics API and custom metrics API as standard APIs.
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants