mirror of
https://github.com/kubernetes-sigs/prometheus-adapter.git
synced 2026-04-07 02:07:58 +00:00
Add vendor folder to git
This commit is contained in:
parent
66cf5eaafb
commit
183585f56f
6916 changed files with 2629581 additions and 1 deletions
4
vendor/github.com/directxman12/custom-metrics-boilerplate/.gitignore
generated
vendored
Normal file
4
vendor/github.com/directxman12/custom-metrics-boilerplate/.gitignore
generated
vendored
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
*.swp
|
||||
*~
|
||||
sample-main
|
||||
vendor
|
||||
26
vendor/github.com/directxman12/custom-metrics-boilerplate/CONTRIBUTING.md
generated
vendored
Normal file
26
vendor/github.com/directxman12/custom-metrics-boilerplate/CONTRIBUTING.md
generated
vendored
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
# Contributing guidelines
|
||||
|
||||
## How to become a contributor and submit your own code
|
||||
|
||||
### Contributor License Agreements
|
||||
|
||||
We'd love to accept your patches! Before we can take them, we have to jump a couple of legal hurdles.
|
||||
|
||||
Please fill out either the individual or corporate Contributor License Agreement (CLA).
|
||||
|
||||
* If you are an individual writing original source code and you're sure you own the intellectual property, then you'll need to sign an [individual CLA](https://identity.linuxfoundation.org/node/285/node/285/individual-signup).
|
||||
* If you work for a company that wants to allow you to contribute your work, then you'll need to sign a [corporate CLA](https://identity.linuxfoundation.org/node/285/organization-signup).
|
||||
|
||||
Follow either of the two links above to access the appropriate CLA and instructions for how to sign and return it. Once we receive it, we'll be able to accept your pull requests.
|
||||
|
||||
### Contributing A Patch
|
||||
|
||||
1. Submit an issue describing your proposed change to the repo in question.
|
||||
1. The [repo owners](OWNERS) will respond to your issue promptly.
|
||||
1. If your proposed change is accepted, and you haven't already done so, sign a Contributor License Agreement (see details above).
|
||||
1. Fork the desired repo, develop and test your code changes.
|
||||
1. Submit a pull request.
|
||||
|
||||
### Adding dependencies
|
||||
|
||||
If your patch depends on new packages, add that package with [`godep`](https://github.com/tools/godep). Follow the [instructions to add a dependency](https://github.com/kubernetes/kubernetes/blob/master/docs/devel/development.md#godep-and-dependency-management).
|
||||
201
vendor/github.com/directxman12/custom-metrics-boilerplate/LICENSE
generated
vendored
Normal file
201
vendor/github.com/directxman12/custom-metrics-boilerplate/LICENSE
generated
vendored
Normal file
|
|
@ -0,0 +1,201 @@
|
|||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "{}"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright {yyyy} {name of copyright owner}
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
56
vendor/github.com/directxman12/custom-metrics-boilerplate/README.md
generated
vendored
Normal file
56
vendor/github.com/directxman12/custom-metrics-boilerplate/README.md
generated
vendored
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
# Custom Metrics Adpater Server Boilerplate
|
||||
|
||||
## Purpose
|
||||
|
||||
This repository contains boilerplate code for setting up an implementation
|
||||
of the custom metrics API (https://github.com/kubernetes/metrics).
|
||||
|
||||
It includes the necessary boilerplate for setting up an implementation
|
||||
(generic API server setup, registration of resources, etc), plus a sample
|
||||
implementation backed by fake data.
|
||||
|
||||
## How to use this repository
|
||||
|
||||
In order to use this repository, you should vendor this repository at
|
||||
`github.com/directxman12/custom-metrics-boilerplate`, and implement the
|
||||
`"github.com/directxman12/custom-metrics-boilerplate/pkg/provider".CustomMetricsProvider`
|
||||
interface. You can then pass this to the main setup functions.
|
||||
|
||||
The `pkg/cmd` package contains the building blocks of the actual API
|
||||
server setup. You'll most likely want to wrap the existing options and
|
||||
flags setup to add your own flags for configuring your provider.
|
||||
|
||||
A sample implementation of this can be found in the file `sample-main.go`
|
||||
and `pkg/sample-cmd` directory. You'll want to have the equivalent files
|
||||
in your project.
|
||||
|
||||
### A note on Dependencies
|
||||
|
||||
You'll need to `glide install` dependencies before you can use this
|
||||
project.
|
||||
|
||||
## Compatibility
|
||||
|
||||
The APIs in this repository follow the standard guarantees for Kubernetes
|
||||
APIs, and will follow Kubernetes releases.
|
||||
|
||||
## Community, discussion, contribution, and support
|
||||
|
||||
Learn how to engage with the Kubernetes community on the [community
|
||||
page](http://kubernetes.io/community/).
|
||||
|
||||
You can reach the maintainers of this repository at:
|
||||
|
||||
- Slack: #sig-instrumention (on https://kubernetes.slack.com -- get an
|
||||
invite at slack.kubernetes.io)
|
||||
- Mailing List:
|
||||
https://groups.google.com/forum/#!forum/kubernetes-sig-instrumentation
|
||||
|
||||
### Code of Conduct
|
||||
|
||||
Participation in the Kubernetes community is governed by the [Kubernetes
|
||||
Code of Conduct](code-of-conduct.md).
|
||||
|
||||
### Contibution Guidelines
|
||||
|
||||
See [CONTRIBUTING.md](CONTRIBUTING.md) for more information.
|
||||
58
vendor/github.com/directxman12/custom-metrics-boilerplate/code-of-conduct.md
generated
vendored
Normal file
58
vendor/github.com/directxman12/custom-metrics-boilerplate/code-of-conduct.md
generated
vendored
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
## Kubernetes Community Code of Conduct
|
||||
|
||||
### Contributor Code of Conduct
|
||||
|
||||
As contributors and maintainers of this project, and in the interest of fostering
|
||||
an open and welcoming community, we pledge to respect all people who contribute
|
||||
through reporting issues, posting feature requests, updating documentation,
|
||||
submitting pull requests or patches, and other activities.
|
||||
|
||||
We are committed to making participation in this project a harassment-free experience for
|
||||
everyone, regardless of level of experience, gender, gender identity and expression,
|
||||
sexual orientation, disability, personal appearance, body size, race, ethnicity, age,
|
||||
religion, or nationality.
|
||||
|
||||
Examples of unacceptable behavior by participants include:
|
||||
|
||||
* The use of sexualized language or imagery
|
||||
* Personal attacks
|
||||
* Trolling or insulting/derogatory comments
|
||||
* Public or private harassment
|
||||
* Publishing other's private information, such as physical or electronic addresses,
|
||||
without explicit permission
|
||||
* Other unethical or unprofessional conduct.
|
||||
|
||||
Project maintainers have the right and responsibility to remove, edit, or reject
|
||||
comments, commits, code, wiki edits, issues, and other contributions that are not
|
||||
aligned to this Code of Conduct. By adopting this Code of Conduct, project maintainers
|
||||
commit themselves to fairly and consistently applying these principles to every aspect
|
||||
of managing this project. Project maintainers who do not follow or enforce the Code of
|
||||
Conduct may be permanently removed from the project team.
|
||||
|
||||
This code of conduct applies both within project spaces and in public spaces
|
||||
when an individual is representing the project or its community.
|
||||
|
||||
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting a Kubernetes maintainer, Sarah Novotny <sarahnovotny@google.com>, and/or Dan Kohn <dan@linuxfoundation.org>.
|
||||
|
||||
This Code of Conduct is adapted from the Contributor Covenant
|
||||
(http://contributor-covenant.org), version 1.2.0, available at
|
||||
http://contributor-covenant.org/version/1/2/0/
|
||||
|
||||
### Kubernetes Events Code of Conduct
|
||||
|
||||
Kubernetes events are working conferences intended for professional networking and collaboration in the
|
||||
Kubernetes community. Attendees are expected to behave according to professional standards and in accordance
|
||||
with their employer's policies on appropriate workplace behavior.
|
||||
|
||||
While at Kubernetes events or related social networking opportunities, attendees should not engage in
|
||||
discriminatory or offensive speech or actions regarding gender, sexuality, race, or religion. Speakers should
|
||||
be especially aware of these concerns.
|
||||
|
||||
The Kubernetes team does not condone any statements by speakers contrary to these standards. The Kubernetes
|
||||
team reserves the right to deny entrance and/or eject from an event (without refund) any individual found to
|
||||
be engaging in discriminatory or offensive speech or actions.
|
||||
|
||||
Please bring any concerns to to the immediate attention of Kubernetes event staff
|
||||
|
||||
|
||||
[]()
|
||||
494
vendor/github.com/directxman12/custom-metrics-boilerplate/glide.lock
generated
vendored
Normal file
494
vendor/github.com/directxman12/custom-metrics-boilerplate/glide.lock
generated
vendored
Normal file
|
|
@ -0,0 +1,494 @@
|
|||
hash: 807f261d8170be02e0c3802e4d005c334a04419a8b2e5f75d68498385202f5ff
|
||||
updated: 2017-06-07T14:38:39.211756323-04:00
|
||||
imports:
|
||||
- name: bitbucket.org/ww/goautoneg
|
||||
version: 75cd24fc2f2c2a2088577d12123ddee5f54e0675
|
||||
- name: github.com/beorn7/perks
|
||||
version: 3ac7bf7a47d159a033b107610db8a1b6575507a4
|
||||
subpackages:
|
||||
- quantile
|
||||
- name: github.com/coreos/etcd
|
||||
version: 20490caaf0dcd96bb4a95e40625559def8ef5b04
|
||||
subpackages:
|
||||
- alarm
|
||||
- auth
|
||||
- auth/authpb
|
||||
- client
|
||||
- clientv3
|
||||
- compactor
|
||||
- discovery
|
||||
- error
|
||||
- etcdserver
|
||||
- etcdserver/api
|
||||
- etcdserver/api/v2http
|
||||
- etcdserver/api/v2http/httptypes
|
||||
- etcdserver/api/v3rpc
|
||||
- etcdserver/api/v3rpc/rpctypes
|
||||
- etcdserver/auth
|
||||
- etcdserver/etcdserverpb
|
||||
- etcdserver/membership
|
||||
- etcdserver/stats
|
||||
- integration
|
||||
- lease
|
||||
- lease/leasehttp
|
||||
- lease/leasepb
|
||||
- mvcc
|
||||
- mvcc/backend
|
||||
- mvcc/mvccpb
|
||||
- pkg/adt
|
||||
- pkg/contention
|
||||
- pkg/cpuutil
|
||||
- pkg/crc
|
||||
- pkg/fileutil
|
||||
- pkg/httputil
|
||||
- pkg/idutil
|
||||
- pkg/ioutil
|
||||
- pkg/logutil
|
||||
- pkg/monotime
|
||||
- pkg/netutil
|
||||
- pkg/pathutil
|
||||
- pkg/pbutil
|
||||
- pkg/runtime
|
||||
- pkg/schedule
|
||||
- pkg/testutil
|
||||
- pkg/tlsutil
|
||||
- pkg/transport
|
||||
- pkg/types
|
||||
- pkg/wait
|
||||
- proxy/grpcproxy
|
||||
- proxy/grpcproxy/cache
|
||||
- raft
|
||||
- raft/raftpb
|
||||
- rafthttp
|
||||
- snap
|
||||
- snap/snappb
|
||||
- store
|
||||
- version
|
||||
- wal
|
||||
- wal/walpb
|
||||
- name: github.com/coreos/go-systemd
|
||||
version: 48702e0da86bd25e76cfef347e2adeb434a0d0a6
|
||||
subpackages:
|
||||
- daemon
|
||||
- journal
|
||||
- name: github.com/coreos/pkg
|
||||
version: fa29b1d70f0beaddd4c7021607cc3c3be8ce94b8
|
||||
subpackages:
|
||||
- capnslog
|
||||
- health
|
||||
- httputil
|
||||
- timeutil
|
||||
- name: github.com/davecgh/go-spew
|
||||
version: 5215b55f46b2b919f50a1df0eaa5886afe4e3b3d
|
||||
subpackages:
|
||||
- spew
|
||||
- name: github.com/docker/distribution
|
||||
version: cd27f179f2c10c5d300e6d09025b538c475b0d51
|
||||
subpackages:
|
||||
- digest
|
||||
- reference
|
||||
- name: github.com/elazarl/go-bindata-assetfs
|
||||
version: 3dcc96556217539f50599357fb481ac0dc7439b9
|
||||
- name: github.com/emicklei/go-restful
|
||||
version: ff4f55a206334ef123e4f79bbf348980da81ca46
|
||||
subpackages:
|
||||
- log
|
||||
- name: github.com/emicklei/go-restful-swagger12
|
||||
version: dcef7f55730566d41eae5db10e7d6981829720f6
|
||||
- name: github.com/evanphx/json-patch
|
||||
version: ba18e35c5c1b36ef6334cad706eb681153d2d379
|
||||
- name: github.com/ghodss/yaml
|
||||
version: 73d445a93680fa1a78ae23a5839bad48f32ba1ee
|
||||
- name: github.com/go-openapi/analysis
|
||||
version: b44dc874b601d9e4e2f6e19140e794ba24bead3b
|
||||
- name: github.com/go-openapi/jsonpointer
|
||||
version: 46af16f9f7b149af66e5d1bd010e3574dc06de98
|
||||
- name: github.com/go-openapi/jsonreference
|
||||
version: 13c6e3589ad90f49bd3e3bbe2c2cb3d7a4142272
|
||||
- name: github.com/go-openapi/loads
|
||||
version: 18441dfa706d924a39a030ee2c3b1d8d81917b38
|
||||
- name: github.com/go-openapi/spec
|
||||
version: 6aced65f8501fe1217321abf0749d354824ba2ff
|
||||
- name: github.com/go-openapi/swag
|
||||
version: 1d0bd113de87027671077d3c71eb3ac5d7dbba72
|
||||
- name: github.com/gogo/protobuf
|
||||
version: c0656edd0d9eab7c66d1eb0c568f9039345796f7
|
||||
subpackages:
|
||||
- proto
|
||||
- sortkeys
|
||||
- name: github.com/golang/glog
|
||||
version: 44145f04b68cf362d9c4df2182967c2275eaefed
|
||||
- name: github.com/golang/protobuf
|
||||
version: 4bd1920723d7b7c925de087aa32e2187708897f7
|
||||
subpackages:
|
||||
- jsonpb
|
||||
- proto
|
||||
- ptypes
|
||||
- ptypes/any
|
||||
- ptypes/duration
|
||||
- ptypes/timestamp
|
||||
- name: github.com/google/gofuzz
|
||||
version: 44d81051d367757e1c7c6a5a86423ece9afcf63c
|
||||
- name: github.com/googleapis/gnostic
|
||||
version: 68f4ded48ba9414dab2ae69b3f0d69971da73aa5
|
||||
subpackages:
|
||||
- OpenAPIv2
|
||||
- compiler
|
||||
- extensions
|
||||
- name: github.com/grpc-ecosystem/go-grpc-prometheus
|
||||
version: 2500245aa6110c562d17020fb31a2c133d737799
|
||||
- name: github.com/grpc-ecosystem/grpc-gateway
|
||||
version: 84398b94e188ee336f307779b57b3aa91af7063c
|
||||
subpackages:
|
||||
- runtime
|
||||
- runtime/internal
|
||||
- utilities
|
||||
- name: github.com/hashicorp/golang-lru
|
||||
version: a0d98a5f288019575c6d1f4bb1573fef2d1fcdc4
|
||||
subpackages:
|
||||
- simplelru
|
||||
- name: github.com/howeyc/gopass
|
||||
version: 3ca23474a7c7203e0a0a070fd33508f6efdb9b3d
|
||||
- name: github.com/imdario/mergo
|
||||
version: 6633656539c1639d9d78127b7d47c622b5d7b6dc
|
||||
- name: github.com/inconshreveable/mousetrap
|
||||
version: 76626ae9c91c4f2a10f34cad8ce83ea42c93bb75
|
||||
- name: github.com/juju/ratelimit
|
||||
version: 77ed1c8a01217656d2080ad51981f6e99adaa177
|
||||
- name: github.com/mailru/easyjson
|
||||
version: d5b7844b561a7bc640052f1b935f7b800330d7e0
|
||||
subpackages:
|
||||
- buffer
|
||||
- jlexer
|
||||
- jwriter
|
||||
- name: github.com/matttproud/golang_protobuf_extensions
|
||||
version: fc2b8d3a73c4867e51861bbdd5ae3c1f0869dd6a
|
||||
subpackages:
|
||||
- pbutil
|
||||
- name: github.com/pborman/uuid
|
||||
version: ca53cad383cad2479bbba7f7a1a05797ec1386e4
|
||||
- name: github.com/pkg/errors
|
||||
version: a22138067af1c4942683050411a841ade67fe1eb
|
||||
- name: github.com/prometheus/client_golang
|
||||
version: e51041b3fa41cece0dca035740ba6411905be473
|
||||
subpackages:
|
||||
- prometheus
|
||||
- name: github.com/prometheus/client_model
|
||||
version: fa8ad6fec33561be4280a8f0514318c79d7f6cb6
|
||||
subpackages:
|
||||
- go
|
||||
- name: github.com/prometheus/common
|
||||
version: ffe929a3f4c4faeaa10f2b9535c2b1be3ad15650
|
||||
subpackages:
|
||||
- expfmt
|
||||
- model
|
||||
- name: github.com/prometheus/procfs
|
||||
version: 454a56f35412459b5e684fd5ec0f9211b94f002a
|
||||
- name: github.com/PuerkitoBio/purell
|
||||
version: 8a290539e2e8629dbc4e6bad948158f790ec31f4
|
||||
- name: github.com/PuerkitoBio/urlesc
|
||||
version: 5bd2802263f21d8788851d5305584c82a5c75d7e
|
||||
- name: github.com/spf13/cobra
|
||||
version: f62e98d28ab7ad31d707ba837a966378465c7b57
|
||||
- name: github.com/spf13/pflag
|
||||
version: 9ff6c6923cfffbcd502984b8e0c80539a94968b7
|
||||
- name: github.com/ugorji/go
|
||||
version: ded73eae5db7e7a0ef6f55aace87a2873c5d2b74
|
||||
subpackages:
|
||||
- codec
|
||||
- name: golang.org/x/crypto
|
||||
version: d172538b2cfce0c13cee31e647d0367aa8cd2486
|
||||
subpackages:
|
||||
- bcrypt
|
||||
- blowfish
|
||||
- ssh/terminal
|
||||
- name: golang.org/x/net
|
||||
version: f2499483f923065a842d38eb4c7f1927e6fc6e6d
|
||||
subpackages:
|
||||
- context
|
||||
- html
|
||||
- html/atom
|
||||
- http2
|
||||
- http2/hpack
|
||||
- idna
|
||||
- internal/timeseries
|
||||
- lex/httplex
|
||||
- trace
|
||||
- websocket
|
||||
- name: golang.org/x/sys
|
||||
version: 8f0908ab3b2457e2e15403d3697c9ef5cb4b57a9
|
||||
subpackages:
|
||||
- unix
|
||||
- name: golang.org/x/text
|
||||
version: 2910a502d2bf9e43193af9d68ca516529614eed3
|
||||
subpackages:
|
||||
- cases
|
||||
- internal/tag
|
||||
- language
|
||||
- runes
|
||||
- secure/bidirule
|
||||
- secure/precis
|
||||
- transform
|
||||
- unicode/bidi
|
||||
- unicode/norm
|
||||
- width
|
||||
- name: google.golang.org/grpc
|
||||
version: 777daa17ff9b5daef1cfdf915088a2ada3332bf0
|
||||
subpackages:
|
||||
- codes
|
||||
- credentials
|
||||
- grpclog
|
||||
- internal
|
||||
- metadata
|
||||
- naming
|
||||
- peer
|
||||
- transport
|
||||
- name: gopkg.in/inf.v0
|
||||
version: 3887ee99ecf07df5b447e9b00d9c0b2adaa9f3e4
|
||||
- name: gopkg.in/natefinch/lumberjack.v2
|
||||
version: 20b71e5b60d756d3d2f80def009790325acc2b23
|
||||
- name: gopkg.in/yaml.v2
|
||||
version: 53feefa2559fb8dfa8d81baad31be332c97d6c77
|
||||
- name: k8s.io/apimachinery
|
||||
version: 2de00c78cb6d6127fb51b9531c1b3def1cbcac8c
|
||||
subpackages:
|
||||
- pkg/api/equality
|
||||
- pkg/api/errors
|
||||
- pkg/api/meta
|
||||
- pkg/api/resource
|
||||
- pkg/api/validation
|
||||
- pkg/api/validation/path
|
||||
- pkg/apimachinery
|
||||
- pkg/apimachinery/announced
|
||||
- pkg/apimachinery/registered
|
||||
- pkg/apis/meta/internalversion
|
||||
- pkg/apis/meta/v1
|
||||
- pkg/apis/meta/v1/unstructured
|
||||
- pkg/apis/meta/v1/validation
|
||||
- pkg/apis/meta/v1alpha1
|
||||
- pkg/conversion
|
||||
- pkg/conversion/queryparams
|
||||
- pkg/conversion/unstructured
|
||||
- pkg/fields
|
||||
- pkg/labels
|
||||
- pkg/openapi
|
||||
- pkg/runtime
|
||||
- pkg/runtime/schema
|
||||
- pkg/runtime/serializer
|
||||
- pkg/runtime/serializer/json
|
||||
- pkg/runtime/serializer/protobuf
|
||||
- pkg/runtime/serializer/recognizer
|
||||
- pkg/runtime/serializer/streaming
|
||||
- pkg/runtime/serializer/versioning
|
||||
- pkg/selection
|
||||
- pkg/types
|
||||
- pkg/util/cache
|
||||
- pkg/util/clock
|
||||
- pkg/util/diff
|
||||
- pkg/util/errors
|
||||
- pkg/util/framer
|
||||
- pkg/util/httpstream
|
||||
- pkg/util/intstr
|
||||
- pkg/util/json
|
||||
- pkg/util/mergepatch
|
||||
- pkg/util/net
|
||||
- pkg/util/rand
|
||||
- pkg/util/runtime
|
||||
- pkg/util/sets
|
||||
- pkg/util/strategicpatch
|
||||
- pkg/util/uuid
|
||||
- pkg/util/validation
|
||||
- pkg/util/validation/field
|
||||
- pkg/util/wait
|
||||
- pkg/util/yaml
|
||||
- pkg/version
|
||||
- pkg/watch
|
||||
- third_party/forked/golang/json
|
||||
- third_party/forked/golang/netutil
|
||||
- third_party/forked/golang/reflect
|
||||
- name: k8s.io/apiserver
|
||||
version: c809cf8581e1e44c6174bf5ab4415e6ee39965ca
|
||||
subpackages:
|
||||
- pkg/admission
|
||||
- pkg/admission/initializer
|
||||
- pkg/apis/apiserver
|
||||
- pkg/apis/apiserver/install
|
||||
- pkg/apis/apiserver/v1alpha1
|
||||
- pkg/authentication/authenticator
|
||||
- pkg/authentication/authenticatorfactory
|
||||
- pkg/authentication/group
|
||||
- pkg/authentication/request/anonymous
|
||||
- pkg/authentication/request/bearertoken
|
||||
- pkg/authentication/request/headerrequest
|
||||
- pkg/authentication/request/union
|
||||
- pkg/authentication/request/x509
|
||||
- pkg/authentication/serviceaccount
|
||||
- pkg/authentication/token/tokenfile
|
||||
- pkg/authentication/user
|
||||
- pkg/authorization/authorizer
|
||||
- pkg/authorization/authorizerfactory
|
||||
- pkg/authorization/union
|
||||
- pkg/endpoints
|
||||
- pkg/endpoints/discovery
|
||||
- pkg/endpoints/filters
|
||||
- pkg/endpoints/handlers
|
||||
- pkg/endpoints/handlers/negotiation
|
||||
- pkg/endpoints/handlers/responsewriters
|
||||
- pkg/endpoints/metrics
|
||||
- pkg/endpoints/openapi
|
||||
- pkg/endpoints/request
|
||||
- pkg/features
|
||||
- pkg/registry/generic
|
||||
- pkg/registry/generic/registry
|
||||
- pkg/registry/rest
|
||||
- pkg/server
|
||||
- pkg/server/filters
|
||||
- pkg/server/healthz
|
||||
- pkg/server/httplog
|
||||
- pkg/server/mux
|
||||
- pkg/server/openapi
|
||||
- pkg/server/options
|
||||
- pkg/server/routes
|
||||
- pkg/server/routes/data/swagger
|
||||
- pkg/server/storage
|
||||
- pkg/storage
|
||||
- pkg/storage/errors
|
||||
- pkg/storage/etcd
|
||||
- pkg/storage/etcd/metrics
|
||||
- pkg/storage/etcd/util
|
||||
- pkg/storage/etcd3
|
||||
- pkg/storage/names
|
||||
- pkg/storage/storagebackend
|
||||
- pkg/storage/storagebackend/factory
|
||||
- pkg/storage/value
|
||||
- pkg/util/feature
|
||||
- pkg/util/flag
|
||||
- pkg/util/flushwriter
|
||||
- pkg/util/logs
|
||||
- pkg/util/proxy
|
||||
- pkg/util/trace
|
||||
- pkg/util/trie
|
||||
- pkg/util/webhook
|
||||
- pkg/util/wsstream
|
||||
- plugin/pkg/authenticator/token/webhook
|
||||
- plugin/pkg/authorizer/webhook
|
||||
- name: k8s.io/client-go
|
||||
version: 450baa5d60f8d6a251c7682cb6f86e939b750b2d
|
||||
subpackages:
|
||||
- discovery
|
||||
- informers
|
||||
- informers/apps
|
||||
- informers/apps/v1beta1
|
||||
- informers/autoscaling
|
||||
- informers/autoscaling/v1
|
||||
- informers/autoscaling/v2alpha1
|
||||
- informers/batch
|
||||
- informers/batch/v1
|
||||
- informers/batch/v2alpha1
|
||||
- informers/certificates
|
||||
- informers/certificates/v1beta1
|
||||
- informers/core
|
||||
- informers/core/v1
|
||||
- informers/extensions
|
||||
- informers/extensions/v1beta1
|
||||
- informers/internalinterfaces
|
||||
- informers/policy
|
||||
- informers/policy/v1beta1
|
||||
- informers/rbac
|
||||
- informers/rbac/v1alpha1
|
||||
- informers/rbac/v1beta1
|
||||
- informers/settings
|
||||
- informers/settings/v1alpha1
|
||||
- informers/storage
|
||||
- informers/storage/v1
|
||||
- informers/storage/v1beta1
|
||||
- kubernetes
|
||||
- kubernetes/scheme
|
||||
- kubernetes/typed/apps/v1beta1
|
||||
- kubernetes/typed/authentication/v1
|
||||
- kubernetes/typed/authentication/v1beta1
|
||||
- kubernetes/typed/authorization/v1
|
||||
- kubernetes/typed/authorization/v1beta1
|
||||
- kubernetes/typed/autoscaling/v1
|
||||
- kubernetes/typed/autoscaling/v2alpha1
|
||||
- kubernetes/typed/batch/v1
|
||||
- kubernetes/typed/batch/v2alpha1
|
||||
- kubernetes/typed/certificates/v1beta1
|
||||
- kubernetes/typed/core/v1
|
||||
- kubernetes/typed/extensions/v1beta1
|
||||
- kubernetes/typed/policy/v1beta1
|
||||
- kubernetes/typed/rbac/v1alpha1
|
||||
- kubernetes/typed/rbac/v1beta1
|
||||
- kubernetes/typed/settings/v1alpha1
|
||||
- kubernetes/typed/storage/v1
|
||||
- kubernetes/typed/storage/v1beta1
|
||||
- listers/apps/v1beta1
|
||||
- listers/autoscaling/v1
|
||||
- listers/autoscaling/v2alpha1
|
||||
- listers/batch/v1
|
||||
- listers/batch/v2alpha1
|
||||
- listers/certificates/v1beta1
|
||||
- listers/core/v1
|
||||
- listers/extensions/v1beta1
|
||||
- listers/policy/v1beta1
|
||||
- listers/rbac/v1alpha1
|
||||
- listers/rbac/v1beta1
|
||||
- listers/settings/v1alpha1
|
||||
- listers/storage/v1
|
||||
- listers/storage/v1beta1
|
||||
- pkg/api
|
||||
- pkg/api/install
|
||||
- pkg/api/v1
|
||||
- pkg/api/v1/ref
|
||||
- pkg/apis/apps
|
||||
- pkg/apis/apps/v1beta1
|
||||
- pkg/apis/authentication
|
||||
- pkg/apis/authentication/v1
|
||||
- pkg/apis/authentication/v1beta1
|
||||
- pkg/apis/authorization
|
||||
- pkg/apis/authorization/v1
|
||||
- pkg/apis/authorization/v1beta1
|
||||
- pkg/apis/autoscaling
|
||||
- pkg/apis/autoscaling/v1
|
||||
- pkg/apis/autoscaling/v2alpha1
|
||||
- pkg/apis/batch
|
||||
- pkg/apis/batch/v1
|
||||
- pkg/apis/batch/v2alpha1
|
||||
- pkg/apis/certificates
|
||||
- pkg/apis/certificates/v1beta1
|
||||
- pkg/apis/extensions
|
||||
- pkg/apis/extensions/v1beta1
|
||||
- pkg/apis/policy
|
||||
- pkg/apis/policy/v1beta1
|
||||
- pkg/apis/rbac
|
||||
- pkg/apis/rbac/v1alpha1
|
||||
- pkg/apis/rbac/v1beta1
|
||||
- pkg/apis/settings
|
||||
- pkg/apis/settings/v1alpha1
|
||||
- pkg/apis/storage
|
||||
- pkg/apis/storage/v1
|
||||
- pkg/apis/storage/v1beta1
|
||||
- pkg/util
|
||||
- pkg/util/parsers
|
||||
- pkg/version
|
||||
- rest
|
||||
- rest/watch
|
||||
- tools/auth
|
||||
- tools/cache
|
||||
- tools/clientcmd
|
||||
- tools/clientcmd/api
|
||||
- tools/clientcmd/api/latest
|
||||
- tools/clientcmd/api/v1
|
||||
- tools/metrics
|
||||
- transport
|
||||
- util/cert
|
||||
- util/flowcontrol
|
||||
- util/homedir
|
||||
- util/integer
|
||||
- name: k8s.io/metrics
|
||||
version: fd2415bb9381a6731027b48a8c6b78f28e13f876
|
||||
subpackages:
|
||||
- pkg/apis/custom_metrics
|
||||
- pkg/apis/custom_metrics/install
|
||||
- pkg/apis/custom_metrics/v1alpha1
|
||||
testImports: []
|
||||
45
vendor/github.com/directxman12/custom-metrics-boilerplate/glide.yaml
generated
vendored
Normal file
45
vendor/github.com/directxman12/custom-metrics-boilerplate/glide.yaml
generated
vendored
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
package: github.com/directxman12/custom-metrics-boilerplate
|
||||
import:
|
||||
- package: github.com/emicklei/go-restful
|
||||
- package: github.com/spf13/cobra
|
||||
- package: k8s.io/apimachinery
|
||||
subpackages:
|
||||
- pkg/api/errors
|
||||
- pkg/api/meta
|
||||
- pkg/api/resource
|
||||
- pkg/apimachinery
|
||||
- pkg/apimachinery/announced
|
||||
- pkg/apimachinery/registered
|
||||
- pkg/apis/meta/internalversion
|
||||
- pkg/apis/meta/v1
|
||||
- pkg/conversion
|
||||
- pkg/labels
|
||||
- pkg/runtime
|
||||
- pkg/runtime/schema
|
||||
- pkg/runtime/serializer
|
||||
- pkg/util/errors
|
||||
- pkg/util/wait
|
||||
- pkg/version
|
||||
- package: k8s.io/apiserver
|
||||
subpackages:
|
||||
- pkg/endpoints
|
||||
- pkg/endpoints/handlers
|
||||
- pkg/endpoints/handlers/negotiation
|
||||
- pkg/endpoints/metrics
|
||||
- pkg/endpoints/request
|
||||
- pkg/registry/rest
|
||||
- pkg/server
|
||||
- pkg/server/options
|
||||
- pkg/util/logs
|
||||
- package: k8s.io/client-go
|
||||
subpackages:
|
||||
- kubernetes/scheme
|
||||
- kubernetes/typed/core/v1
|
||||
- pkg/api
|
||||
- pkg/api/install
|
||||
- rest
|
||||
- tools/clientcmd
|
||||
- package: k8s.io/metrics
|
||||
subpackages:
|
||||
- pkg/apis/custom_metrics
|
||||
- pkg/apis/custom_metrics/install
|
||||
106
vendor/github.com/directxman12/custom-metrics-boilerplate/pkg/apiserver/apiserver.go
generated
vendored
Normal file
106
vendor/github.com/directxman12/custom-metrics-boilerplate/pkg/apiserver/apiserver.go
generated
vendored
Normal file
|
|
@ -0,0 +1,106 @@
|
|||
/*
|
||||
Copyright 2017 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package apiserver
|
||||
|
||||
import (
|
||||
"k8s.io/apimachinery/pkg/apimachinery/announced"
|
||||
"k8s.io/apimachinery/pkg/apimachinery/registered"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
"k8s.io/apimachinery/pkg/runtime/serializer"
|
||||
"k8s.io/apimachinery/pkg/version"
|
||||
genericapiserver "k8s.io/apiserver/pkg/server"
|
||||
|
||||
"github.com/directxman12/custom-metrics-boilerplate/pkg/provider"
|
||||
"k8s.io/metrics/pkg/apis/custom_metrics/install"
|
||||
)
|
||||
|
||||
var (
|
||||
groupFactoryRegistry = make(announced.APIGroupFactoryRegistry)
|
||||
registry = registered.NewOrDie("")
|
||||
Scheme = runtime.NewScheme()
|
||||
Codecs = serializer.NewCodecFactory(Scheme)
|
||||
)
|
||||
|
||||
func init() {
|
||||
install.Install(groupFactoryRegistry, registry, Scheme)
|
||||
|
||||
// we need to add the options to empty v1
|
||||
// TODO fix the server code to avoid this
|
||||
metav1.AddToGroupVersion(Scheme, schema.GroupVersion{Version: "v1"})
|
||||
|
||||
// TODO: keep the generic API server from wanting this
|
||||
unversioned := schema.GroupVersion{Group: "", Version: "v1"}
|
||||
Scheme.AddUnversionedTypes(unversioned,
|
||||
&metav1.Status{},
|
||||
&metav1.APIVersions{},
|
||||
&metav1.APIGroupList{},
|
||||
&metav1.APIGroup{},
|
||||
&metav1.APIResourceList{},
|
||||
)
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
GenericConfig *genericapiserver.Config
|
||||
}
|
||||
|
||||
// CustomMetricsAdapterServer contains state for a Kubernetes cluster master/api server.
|
||||
type CustomMetricsAdapterServer struct {
|
||||
GenericAPIServer *genericapiserver.GenericAPIServer
|
||||
Provider provider.CustomMetricsProvider
|
||||
}
|
||||
|
||||
type completedConfig struct {
|
||||
*Config
|
||||
}
|
||||
|
||||
// Complete fills in any fields not set that are required to have valid data. It's mutating the receiver.
|
||||
func (c *Config) Complete() completedConfig {
|
||||
c.GenericConfig.Complete()
|
||||
|
||||
c.GenericConfig.Version = &version.Info{
|
||||
Major: "1",
|
||||
Minor: "0",
|
||||
}
|
||||
|
||||
return completedConfig{c}
|
||||
}
|
||||
|
||||
// SkipComplete provides a way to construct a server instance without config completion.
|
||||
func (c *Config) SkipComplete() completedConfig {
|
||||
return completedConfig{c}
|
||||
}
|
||||
|
||||
// New returns a new instance of CustomMetricsAdapterServer from the given config.
|
||||
func (c completedConfig) New(cmProvider provider.CustomMetricsProvider) (*CustomMetricsAdapterServer, error) {
|
||||
genericServer, err := c.Config.GenericConfig.SkipComplete().New(genericapiserver.EmptyDelegate) // completion is done in Complete, no need for a second time
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
s := &CustomMetricsAdapterServer{
|
||||
GenericAPIServer: genericServer,
|
||||
Provider: cmProvider,
|
||||
}
|
||||
|
||||
if err := s.InstallCustomMetricsAPI(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return s, nil
|
||||
}
|
||||
89
vendor/github.com/directxman12/custom-metrics-boilerplate/pkg/apiserver/cmapis.go
generated
vendored
Normal file
89
vendor/github.com/directxman12/custom-metrics-boilerplate/pkg/apiserver/cmapis.go
generated
vendored
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
/*
|
||||
Copyright 2017 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package apiserver
|
||||
|
||||
import (
|
||||
"k8s.io/apimachinery/pkg/apimachinery"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
genericapi "k8s.io/apiserver/pkg/endpoints"
|
||||
genericapiserver "k8s.io/apiserver/pkg/server"
|
||||
"k8s.io/apiserver/pkg/endpoints/discovery"
|
||||
|
||||
specificapi "github.com/directxman12/custom-metrics-boilerplate/pkg/apiserver/installer"
|
||||
"github.com/directxman12/custom-metrics-boilerplate/pkg/provider"
|
||||
metricstorage "github.com/directxman12/custom-metrics-boilerplate/pkg/registry/custom_metrics"
|
||||
"k8s.io/metrics/pkg/apis/custom_metrics"
|
||||
)
|
||||
|
||||
func (s *CustomMetricsAdapterServer) InstallCustomMetricsAPI() error {
|
||||
|
||||
groupMeta := registry.GroupOrDie(custom_metrics.GroupName)
|
||||
|
||||
preferredVersionForDiscovery := metav1.GroupVersionForDiscovery{
|
||||
GroupVersion: groupMeta.GroupVersion.String(),
|
||||
Version: groupMeta.GroupVersion.Version,
|
||||
}
|
||||
groupVersion := metav1.GroupVersionForDiscovery{
|
||||
GroupVersion: groupMeta.GroupVersion.String(),
|
||||
Version: groupMeta.GroupVersion.Version,
|
||||
}
|
||||
apiGroup := metav1.APIGroup{
|
||||
Name: groupMeta.GroupVersion.Group,
|
||||
Versions: []metav1.GroupVersionForDiscovery{groupVersion},
|
||||
PreferredVersion: preferredVersionForDiscovery,
|
||||
}
|
||||
|
||||
cmAPI := s.cmAPI(groupMeta, &groupMeta.GroupVersion)
|
||||
|
||||
if err := cmAPI.InstallREST(s.GenericAPIServer.Handler.GoRestfulContainer); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
s.GenericAPIServer.DiscoveryGroupManager.AddGroup(apiGroup)
|
||||
s.GenericAPIServer.Handler.GoRestfulContainer.Add(discovery.NewAPIGroupHandler(s.GenericAPIServer.Serializer, apiGroup).WebService())
|
||||
|
||||
return nil
|
||||
}
|
||||
func (s *CustomMetricsAdapterServer) cmAPI(groupMeta *apimachinery.GroupMeta, groupVersion *schema.GroupVersion) *specificapi.MetricsAPIGroupVersion {
|
||||
resourceStorage := metricstorage.NewREST(s.Provider)
|
||||
|
||||
return &specificapi.MetricsAPIGroupVersion{
|
||||
DynamicStorage: resourceStorage,
|
||||
APIGroupVersion: &genericapi.APIGroupVersion{
|
||||
Root: genericapiserver.APIGroupPrefix,
|
||||
GroupVersion: *groupVersion,
|
||||
|
||||
ParameterCodec: metav1.ParameterCodec,
|
||||
Serializer: Codecs,
|
||||
Creater: Scheme,
|
||||
Convertor: Scheme,
|
||||
UnsafeConvertor: runtime.UnsafeObjectConvertor(Scheme),
|
||||
Copier: Scheme,
|
||||
Typer: Scheme,
|
||||
Linker: groupMeta.SelfLinker,
|
||||
Mapper: groupMeta.RESTMapper,
|
||||
|
||||
Context: s.GenericAPIServer.RequestContextMapper(),
|
||||
MinRequestTimeout: s.GenericAPIServer.MinRequestTimeout(),
|
||||
OptionsExternalVersion: &schema.GroupVersion{Version: "v1"},
|
||||
|
||||
ResourceLister: provider.NewResourceLister(s.Provider),
|
||||
},
|
||||
}
|
||||
}
|
||||
329
vendor/github.com/directxman12/custom-metrics-boilerplate/pkg/apiserver/installer/apiserver_test.go
generated
vendored
Normal file
329
vendor/github.com/directxman12/custom-metrics-boilerplate/pkg/apiserver/installer/apiserver_test.go
generated
vendored
Normal file
|
|
@ -0,0 +1,329 @@
|
|||
/*
|
||||
Copyright 2017 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package installer
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"github.com/emicklei/go-restful"
|
||||
|
||||
"k8s.io/apimachinery/pkg/apimachinery/announced"
|
||||
"k8s.io/apimachinery/pkg/apimachinery/registered"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
"k8s.io/apimachinery/pkg/runtime/serializer"
|
||||
genericapiserver "k8s.io/apiserver/pkg/server"
|
||||
genericapi "k8s.io/apiserver/pkg/endpoints"
|
||||
"k8s.io/apimachinery/pkg/labels"
|
||||
"k8s.io/apiserver/pkg/endpoints/request"
|
||||
"k8s.io/apimachinery/pkg/apimachinery"
|
||||
"k8s.io/metrics/pkg/apis/custom_metrics/install"
|
||||
"k8s.io/metrics/pkg/apis/custom_metrics"
|
||||
cmv1alpha1 "k8s.io/metrics/pkg/apis/custom_metrics/v1alpha1"
|
||||
|
||||
"github.com/directxman12/custom-metrics-boilerplate/pkg/provider"
|
||||
metricstorage "github.com/directxman12/custom-metrics-boilerplate/pkg/registry/custom_metrics"
|
||||
|
||||
)
|
||||
|
||||
// defaultAPIServer exposes nested objects for testability.
|
||||
type defaultAPIServer struct {
|
||||
http.Handler
|
||||
container *restful.Container
|
||||
}
|
||||
|
||||
var (
|
||||
groupFactoryRegistry = make(announced.APIGroupFactoryRegistry)
|
||||
registry = registered.NewOrDie("")
|
||||
Scheme = runtime.NewScheme()
|
||||
Codecs = serializer.NewCodecFactory(Scheme)
|
||||
prefix = genericapiserver.APIGroupPrefix
|
||||
groupVersion schema.GroupVersion
|
||||
groupMeta *apimachinery.GroupMeta
|
||||
codec = Codecs.LegacyCodec()
|
||||
emptySet = labels.Set{}
|
||||
matchingSet = labels.Set{"foo": "bar"}
|
||||
)
|
||||
|
||||
func init() {
|
||||
install.Install(groupFactoryRegistry, registry, Scheme)
|
||||
|
||||
// we need to add the options to empty v1
|
||||
// TODO fix the server code to avoid this
|
||||
metav1.AddToGroupVersion(Scheme, schema.GroupVersion{Version: "v1"})
|
||||
|
||||
// TODO: keep the generic API server from wanting this
|
||||
unversioned := schema.GroupVersion{Group: "", Version: "v1"}
|
||||
Scheme.AddUnversionedTypes(unversioned,
|
||||
&metav1.Status{},
|
||||
&metav1.APIVersions{},
|
||||
&metav1.APIGroupList{},
|
||||
&metav1.APIGroup{},
|
||||
&metav1.APIResourceList{},
|
||||
)
|
||||
|
||||
groupMeta = registry.GroupOrDie(custom_metrics.GroupName)
|
||||
groupVersion = groupMeta.GroupVersion
|
||||
}
|
||||
|
||||
func extractBody(response *http.Response, object runtime.Object) error {
|
||||
defer response.Body.Close()
|
||||
body, err := ioutil.ReadAll(response.Body)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return runtime.DecodeInto(codec, body, object)
|
||||
}
|
||||
|
||||
func extractBodyString(response *http.Response) (string, error) {
|
||||
defer response.Body.Close()
|
||||
body, err := ioutil.ReadAll(response.Body)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return string(body), err
|
||||
}
|
||||
|
||||
func handle(prov provider.CustomMetricsProvider) http.Handler {
|
||||
container := restful.NewContainer()
|
||||
container.Router(restful.CurlyRouter{})
|
||||
mux := container.ServeMux
|
||||
resourceStorage := metricstorage.NewREST(prov)
|
||||
group := &MetricsAPIGroupVersion{
|
||||
DynamicStorage: resourceStorage,
|
||||
APIGroupVersion: &genericapi.APIGroupVersion{
|
||||
Root: prefix,
|
||||
GroupVersion: groupVersion,
|
||||
|
||||
ParameterCodec: metav1.ParameterCodec,
|
||||
Serializer: Codecs,
|
||||
Creater: Scheme,
|
||||
Convertor: Scheme,
|
||||
UnsafeConvertor: runtime.UnsafeObjectConvertor(Scheme),
|
||||
Copier: Scheme,
|
||||
Typer: Scheme,
|
||||
Linker: groupMeta.SelfLinker,
|
||||
Mapper: groupMeta.RESTMapper,
|
||||
|
||||
Context: request.NewRequestContextMapper(),
|
||||
OptionsExternalVersion: &schema.GroupVersion{Version: "v1"},
|
||||
|
||||
ResourceLister: provider.NewResourceLister(prov),
|
||||
},
|
||||
}
|
||||
|
||||
if err := group.InstallREST(container); err != nil {
|
||||
panic(fmt.Sprintf("unable to install container %s: %v", group.GroupVersion, err))
|
||||
}
|
||||
|
||||
return &defaultAPIServer{mux, container}
|
||||
}
|
||||
|
||||
type fakeProvider struct {
|
||||
rootValues map[string][]custom_metrics.MetricValue
|
||||
namespacedValues map[string][]custom_metrics.MetricValue
|
||||
rootSubsetCounts map[string]int
|
||||
namespacedSubsetCounts map[string]int
|
||||
metrics []provider.MetricInfo
|
||||
}
|
||||
|
||||
func (p *fakeProvider) GetRootScopedMetricByName(groupResource schema.GroupResource, name string, metricName string) (*custom_metrics.MetricValue, error) {
|
||||
metricId := groupResource.String()+"/"+name+"/"+metricName
|
||||
values, ok := p.rootValues[metricId]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("non-existant metric requested (id: %s)", metricId)
|
||||
}
|
||||
|
||||
return &values[0], nil
|
||||
}
|
||||
|
||||
func (p *fakeProvider) GetRootScopedMetricBySelector(groupResource schema.GroupResource, selector labels.Selector, metricName string) (*custom_metrics.MetricValueList, error) {
|
||||
metricId := groupResource.String()+"/*/"+metricName
|
||||
values, ok := p.rootValues[metricId]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("non-existant metric requested (id: %s)", metricId)
|
||||
}
|
||||
|
||||
var trimmedValues custom_metrics.MetricValueList
|
||||
|
||||
if trimmedCount, ok := p.rootSubsetCounts[metricId]; ok {
|
||||
trimmedValues = custom_metrics.MetricValueList{
|
||||
Items: make([]custom_metrics.MetricValue, 0, trimmedCount),
|
||||
}
|
||||
for i := range values {
|
||||
var lbls labels.Labels
|
||||
if i < trimmedCount {
|
||||
lbls = matchingSet
|
||||
} else {
|
||||
lbls = emptySet
|
||||
}
|
||||
if selector.Matches(lbls) {
|
||||
trimmedValues.Items = append(trimmedValues.Items, custom_metrics.MetricValue{})
|
||||
}
|
||||
}
|
||||
} else {
|
||||
trimmedValues = custom_metrics.MetricValueList{
|
||||
Items: values,
|
||||
}
|
||||
}
|
||||
|
||||
return &trimmedValues, nil
|
||||
}
|
||||
|
||||
func (p *fakeProvider) GetNamespacedMetricByName(groupResource schema.GroupResource, namespace string, name string, metricName string) (*custom_metrics.MetricValue, error) {
|
||||
metricId := namespace+"/"+groupResource.String()+"/"+name+"/"+metricName
|
||||
values, ok := p.namespacedValues[metricId]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("non-existant metric requested (id: %s)", metricId)
|
||||
}
|
||||
|
||||
return &values[0], nil
|
||||
}
|
||||
|
||||
func (p *fakeProvider) GetNamespacedMetricBySelector(groupResource schema.GroupResource, namespace string, selector labels.Selector, metricName string) (*custom_metrics.MetricValueList, error) {
|
||||
metricId := namespace+"/"+groupResource.String()+"/*/"+metricName
|
||||
values, ok := p.namespacedValues[metricId]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("non-existant metric requested (id: %s)", metricId)
|
||||
}
|
||||
|
||||
var trimmedValues custom_metrics.MetricValueList
|
||||
|
||||
if trimmedCount, ok := p.namespacedSubsetCounts[metricId]; ok {
|
||||
trimmedValues = custom_metrics.MetricValueList{
|
||||
Items: make([]custom_metrics.MetricValue, 0, trimmedCount),
|
||||
}
|
||||
for i := range values {
|
||||
var lbls labels.Labels
|
||||
if i < trimmedCount {
|
||||
lbls = matchingSet
|
||||
} else {
|
||||
lbls = emptySet
|
||||
}
|
||||
if selector.Matches(lbls) {
|
||||
trimmedValues.Items = append(trimmedValues.Items, custom_metrics.MetricValue{})
|
||||
}
|
||||
}
|
||||
} else {
|
||||
trimmedValues = custom_metrics.MetricValueList{
|
||||
Items: values,
|
||||
}
|
||||
}
|
||||
|
||||
return &trimmedValues, nil
|
||||
}
|
||||
|
||||
func (p *fakeProvider) ListAllMetrics() []provider.MetricInfo {
|
||||
return p.metrics
|
||||
}
|
||||
|
||||
func TestCustomMetricsAPI(t *testing.T) {
|
||||
totalNodesCount := 4
|
||||
totalPodsCount := 16
|
||||
matchingNodesCount := 2
|
||||
matchingPodsCount := 8
|
||||
|
||||
type T struct {
|
||||
Method string
|
||||
Path string
|
||||
Status int
|
||||
ExpectedCount int
|
||||
}
|
||||
cases := map[string]T{
|
||||
// checks which should fail
|
||||
"GET long prefix": {"GET", "/" + prefix + "/", http.StatusNotFound, 0},
|
||||
|
||||
"root GET missing storage": {"GET", "/" + prefix + "/" + groupVersion.Group + "/" + groupVersion.Version + "/blah", http.StatusNotFound, 0},
|
||||
|
||||
"namespaced GET long prefix": {"GET", "/" + prefix + "/", http.StatusNotFound, 0},
|
||||
"namespaced GET missing storage": {"GET", "/" + prefix + "/" + groupVersion.Group + "/" + groupVersion.Version + "/blah", http.StatusNotFound, 0},
|
||||
|
||||
"GET at root resource leaf": {"GET", "/" + prefix + "/" + groupVersion.Group + "/" + groupVersion.Version + "/nodes/foo", http.StatusNotFound, 0},
|
||||
"GET at namespaced resource leaft": {"GET", "/" + prefix + "/" + groupVersion.Group + "/" + groupVersion.Version + "/namespaces/ns/pods/bar", http.StatusNotFound, 0},
|
||||
|
||||
// Positive checks to make sure everything is wired correctly
|
||||
"GET for all nodes (root)": {"GET", "/" + prefix + "/" + groupVersion.Group + "/" + groupVersion.Version + "/nodes/*/some-metric", http.StatusOK, totalNodesCount},
|
||||
"GET for all pods (namespaced)": {"GET", "/" + prefix + "/" + groupVersion.Group + "/" + groupVersion.Version + "/namespaces/ns/pods/*/some-metric", http.StatusOK, totalPodsCount},
|
||||
"GET for namespace": {"GET", "/" + prefix + "/" + groupVersion.Group + "/" + groupVersion.Version + "/namespaces/ns/metrics/some-metric", http.StatusOK, 1},
|
||||
"GET for label selected nodes (root)": {"GET", "/" + prefix + "/" + groupVersion.Group + "/" + groupVersion.Version + "/nodes/*/some-metric?labelSelector=foo%3Dbar", http.StatusOK, matchingNodesCount},
|
||||
"GET for label selected pods (namespaced)": {"GET", "/" + prefix + "/" + groupVersion.Group + "/" + groupVersion.Version + "/namespaces/ns/pods/*/some-metric?labelSelector=foo%3Dbar", http.StatusOK, matchingPodsCount},
|
||||
"GET for single node (root)": {"GET", "/" + prefix + "/" + groupVersion.Group + "/" + groupVersion.Version + "/nodes/foo/some-metric", http.StatusOK, 1},
|
||||
"GET for single pod (namespaced)": {"GET", "/" + prefix + "/" + groupVersion.Group + "/" + groupVersion.Version + "/namespaces/ns/pods/foo/some-metric", http.StatusOK, 1},
|
||||
}
|
||||
|
||||
prov := &fakeProvider{
|
||||
rootValues: map[string][]custom_metrics.MetricValue{
|
||||
"nodes/*/some-metric": make([]custom_metrics.MetricValue, totalNodesCount),
|
||||
"nodes/foo/some-metric": make([]custom_metrics.MetricValue, 1),
|
||||
"namespaces/ns/some-metric": make([]custom_metrics.MetricValue, 1),
|
||||
},
|
||||
namespacedValues: map[string][]custom_metrics.MetricValue{
|
||||
"ns/pods/*/some-metric": make([]custom_metrics.MetricValue, totalPodsCount),
|
||||
"ns/pods/foo/some-metric": make([]custom_metrics.MetricValue, 1),
|
||||
},
|
||||
|
||||
rootSubsetCounts: map[string]int{
|
||||
"nodes/*/some-metric": matchingNodesCount,
|
||||
},
|
||||
namespacedSubsetCounts: map[string]int{
|
||||
"ns/pods/*/some-metric": matchingPodsCount,
|
||||
},
|
||||
}
|
||||
|
||||
server := httptest.NewServer(handle(prov))
|
||||
defer server.Close()
|
||||
client := http.Client{}
|
||||
for k, v := range cases {
|
||||
request, err := http.NewRequest(v.Method, server.URL+v.Path, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error (%s): %v", k, err)
|
||||
}
|
||||
|
||||
response, err := client.Do(request)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error (%s): %v", k, err)
|
||||
continue
|
||||
}
|
||||
|
||||
if response.StatusCode != v.Status {
|
||||
body, err := extractBodyString(response)
|
||||
bodyPart := body
|
||||
if err != nil {
|
||||
bodyPart = fmt.Sprintf("[error extracting body: %v]", err)
|
||||
}
|
||||
t.Errorf("Expected %d for %s (%s), Got %#v -- %s", v.Status, v.Method, k, response, bodyPart)
|
||||
continue
|
||||
}
|
||||
|
||||
if v.ExpectedCount > 0 {
|
||||
lst := &cmv1alpha1.MetricValueList{}
|
||||
if err := extractBody(response, lst); err != nil {
|
||||
t.Errorf("unexpected error (%s): %v", k, err)
|
||||
continue
|
||||
}
|
||||
if len(lst.Items) != v.ExpectedCount {
|
||||
t.Errorf("Expected %d items, got %d (%s): %#v", v.ExpectedCount, len(lst.Items), k, lst.Items)
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
476
vendor/github.com/directxman12/custom-metrics-boilerplate/pkg/apiserver/installer/installer.go
generated
vendored
Normal file
476
vendor/github.com/directxman12/custom-metrics-boilerplate/pkg/apiserver/installer/installer.go
generated
vendored
Normal file
|
|
@ -0,0 +1,476 @@
|
|||
/*
|
||||
Copyright 2017 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package installer
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
gpath "path"
|
||||
"reflect"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"k8s.io/apimachinery/pkg/api/meta"
|
||||
utilerrors "k8s.io/apimachinery/pkg/util/errors"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/conversion"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
"k8s.io/apiserver/pkg/endpoints"
|
||||
"k8s.io/apiserver/pkg/endpoints/handlers"
|
||||
"k8s.io/apiserver/pkg/endpoints/handlers/negotiation"
|
||||
"k8s.io/apiserver/pkg/endpoints/metrics"
|
||||
"k8s.io/apiserver/pkg/registry/rest"
|
||||
"k8s.io/apiserver/pkg/endpoints/request"
|
||||
"k8s.io/apiserver/pkg/endpoints/discovery"
|
||||
|
||||
"github.com/emicklei/go-restful"
|
||||
)
|
||||
|
||||
// NB: the contents of this file should mostly be a subset of the functionality
|
||||
// in "k8s.io/apiserver/pkg/endpoints". It would be nice to eventual figure out
|
||||
// a way to not have to recreate/copy a bunch of the structure from the normal API
|
||||
// installer, so that this trivially tracks changes to the main installer.
|
||||
|
||||
// MetricsAPIGroupVersion is similar to "k8s.io/apiserver/pkg/endpoints".APIGroupVersion,
|
||||
// except that it installs the metrics REST handlers, which use wildcard resources
|
||||
// and subresources.
|
||||
//
|
||||
// This basically only serves the limitted use case required by the metrics API server --
|
||||
// the only verb accepted is GET (and perhaps WATCH in the future).
|
||||
type MetricsAPIGroupVersion struct {
|
||||
DynamicStorage rest.Storage
|
||||
|
||||
*endpoints.APIGroupVersion
|
||||
}
|
||||
|
||||
// InstallDynamicREST registers the dynamic REST handlers into a restful Container.
|
||||
// It is expected that the provided path root prefix will serve all operations. Root MUST
|
||||
// NOT end in a slash. It should mirror InstallREST in the plain APIGroupVersion.
|
||||
func (g *MetricsAPIGroupVersion) InstallREST(container *restful.Container) error {
|
||||
installer := g.newDynamicInstaller()
|
||||
ws := installer.NewWebService()
|
||||
|
||||
registrationErrors := installer.Install(ws)
|
||||
lister := g.ResourceLister
|
||||
if lister == nil {
|
||||
return fmt.Errorf("must provide a dynamic lister for dynamic API groups")
|
||||
}
|
||||
versionDiscoveryHandler := discovery.NewAPIVersionHandler(g.Serializer, g.GroupVersion, lister)
|
||||
versionDiscoveryHandler.AddToWebService(ws)
|
||||
container.Add(ws)
|
||||
return utilerrors.NewAggregate(registrationErrors)
|
||||
}
|
||||
|
||||
// newDynamicInstaller is a helper to create the installer. It mirrors
|
||||
// newInstaller in APIGroupVersion.
|
||||
func (g *MetricsAPIGroupVersion) newDynamicInstaller() *MetricsAPIInstaller {
|
||||
prefix := gpath.Join(g.Root, g.GroupVersion.Group, g.GroupVersion.Version)
|
||||
installer := &MetricsAPIInstaller{
|
||||
group: g,
|
||||
prefix: prefix,
|
||||
minRequestTimeout: g.MinRequestTimeout,
|
||||
}
|
||||
|
||||
return installer
|
||||
}
|
||||
|
||||
// MetricsAPIInstaller is a specialized API installer for the metrics API.
|
||||
// It is intended to be fully compliant with the Kubernetes API server conventions,
|
||||
// but serves wildcard resource/subresource routes instead of hard-coded resources
|
||||
// and subresources.
|
||||
type MetricsAPIInstaller struct {
|
||||
group *MetricsAPIGroupVersion
|
||||
prefix string // Path prefix where API resources are to be registered.
|
||||
minRequestTimeout time.Duration
|
||||
|
||||
// TODO: do we want to embed a normal API installer here so we can serve normal
|
||||
// endpoints side by side with dynamic ones (from the same API group)?
|
||||
}
|
||||
|
||||
// Install installs handlers for API resources.
|
||||
func (a *MetricsAPIInstaller) Install(ws *restful.WebService) (errors []error) {
|
||||
errors = make([]error, 0)
|
||||
|
||||
err := a.registerResourceHandlers(a.group.DynamicStorage, ws)
|
||||
if err != nil {
|
||||
errors = append(errors, fmt.Errorf("error in registering custom metrics resource: %v", err))
|
||||
}
|
||||
|
||||
return errors
|
||||
}
|
||||
|
||||
// NewWebService creates a new restful webservice with the api installer's prefix and version.
|
||||
func (a *MetricsAPIInstaller) NewWebService() *restful.WebService {
|
||||
ws := new(restful.WebService)
|
||||
ws.Path(a.prefix)
|
||||
// a.prefix contains "prefix/group/version"
|
||||
ws.Doc("API at " + a.prefix)
|
||||
// Backwards compatibility, we accepted objects with empty content-type at V1.
|
||||
// If we stop using go-restful, we can default empty content-type to application/json on an
|
||||
// endpoint by endpoint basis
|
||||
ws.Consumes("*/*")
|
||||
mediaTypes, streamMediaTypes := negotiation.MediaTypesForSerializer(a.group.Serializer)
|
||||
ws.Produces(append(mediaTypes, streamMediaTypes...)...)
|
||||
ws.ApiVersion(a.group.GroupVersion.String())
|
||||
|
||||
return ws
|
||||
}
|
||||
|
||||
// registerResourceHandlers registers the resource handlers for custom metrics.
|
||||
// Compared to the normal installer, this plays fast and loose a bit, but should still
|
||||
// follow the API conventions.
|
||||
func (a *MetricsAPIInstaller) registerResourceHandlers(storage rest.Storage, ws *restful.WebService) error {
|
||||
context := a.group.Context
|
||||
|
||||
optionsExternalVersion := a.group.GroupVersion
|
||||
if a.group.OptionsExternalVersion != nil {
|
||||
optionsExternalVersion = *a.group.OptionsExternalVersion
|
||||
}
|
||||
|
||||
mapping, err := a.restMapping()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fqKindToRegister, err := a.getResourceKind(storage)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
kind := fqKindToRegister.Kind
|
||||
|
||||
lister := storage.(rest.Lister)
|
||||
list := lister.NewList()
|
||||
listGVKs, _, err := a.group.Typer.ObjectKinds(list)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
versionedListPtr, err := a.group.Creater.New(a.group.GroupVersion.WithKind(listGVKs[0].Kind))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
versionedList := indirectArbitraryPointer(versionedListPtr)
|
||||
|
||||
versionedListOptions, err := a.group.Creater.New(optionsExternalVersion.WithKind("ListOptions"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
ctxFn := func(req *http.Request) request.Context {
|
||||
if ctx, ok := context.Get(req); ok {
|
||||
return request.WithUserAgent(ctx, req.Header.Get("User-Agent"))
|
||||
}
|
||||
return request.WithUserAgent(request.NewContext(), req.Header.Get("User-Agent"))
|
||||
}
|
||||
|
||||
scope := mapping.Scope
|
||||
nameParam := ws.PathParameter("name", "name of the described resource").DataType("string")
|
||||
resourceParam := ws.PathParameter("resource", "the name of the resource").DataType("string")
|
||||
subresourceParam := ws.PathParameter("subresource", "the name of the subresource").DataType("string")
|
||||
|
||||
// metrics describing non-namespaced objects (e.g. nodes)
|
||||
rootScopedParams := []*restful.Parameter{
|
||||
resourceParam,
|
||||
nameParam,
|
||||
subresourceParam,
|
||||
}
|
||||
rootScopedPath := "{resource}/{name}/{subresource}"
|
||||
|
||||
// metrics describing namespaced objects (e.g. pods)
|
||||
namespaceParam := ws.PathParameter(scope.ArgumentName(), scope.ParamDescription()).DataType("string")
|
||||
namespacedParams := []*restful.Parameter{
|
||||
namespaceParam,
|
||||
resourceParam,
|
||||
nameParam,
|
||||
subresourceParam,
|
||||
}
|
||||
namespacedPath := scope.ParamName() + "/{" + scope.ArgumentName() + "}/{resource}/{name}/{subresource}"
|
||||
|
||||
namespaceSpecificPath := scope.ParamName() + "/{" + scope.ArgumentName() + "}/metrics/{name}"
|
||||
namespaceSpecificParams := []*restful.Parameter{
|
||||
namespaceParam,
|
||||
nameParam,
|
||||
}
|
||||
|
||||
mediaTypes, streamMediaTypes := negotiation.MediaTypesForSerializer(a.group.Serializer)
|
||||
allMediaTypes := append(mediaTypes, streamMediaTypes...)
|
||||
ws.Produces(allMediaTypes...)
|
||||
|
||||
reqScope := handlers.RequestScope{
|
||||
ContextFunc: ctxFn,
|
||||
Serializer: a.group.Serializer,
|
||||
ParameterCodec: a.group.ParameterCodec,
|
||||
Creater: a.group.Creater,
|
||||
Convertor: a.group.Convertor,
|
||||
Copier: a.group.Copier,
|
||||
Typer: a.group.Typer,
|
||||
UnsafeConvertor: a.group.UnsafeConvertor,
|
||||
|
||||
// TODO: This seems wrong for cross-group subresources. It makes an assumption that a subresource and its parent are in the same group version. Revisit this.
|
||||
Resource: a.group.GroupVersion.WithResource("*"),
|
||||
Subresource: "*",
|
||||
Kind: fqKindToRegister,
|
||||
|
||||
MetaGroupVersion: metav1.SchemeGroupVersion,
|
||||
}
|
||||
if a.group.MetaGroupVersion != nil {
|
||||
reqScope.MetaGroupVersion = *a.group.MetaGroupVersion
|
||||
}
|
||||
|
||||
// we need one path for namespaced resources, one for non-namespaced resources
|
||||
doc := "list custom metrics describing an object or objects"
|
||||
reqScope.Namer = MetricsNaming{
|
||||
handlers.ContextBasedNaming{
|
||||
GetContext: ctxFn,
|
||||
SelfLinker: a.group.Linker,
|
||||
ClusterScoped: true,
|
||||
SelfLinkPathPrefix: a.prefix + "/",
|
||||
},
|
||||
}
|
||||
|
||||
rootScopedHandler := metrics.InstrumentRouteFunc("LIST", "custom-metrics", restfulListResource(lister, nil, reqScope, false, a.minRequestTimeout))
|
||||
|
||||
// install the root-scoped route
|
||||
rootScopedRoute := ws.GET(rootScopedPath).To(rootScopedHandler).
|
||||
Doc(doc).
|
||||
Param(ws.QueryParameter("pretty", "If 'true', then the output is pretty printed.")).
|
||||
Operation("list"+kind).
|
||||
Produces(allMediaTypes...).
|
||||
Returns(http.StatusOK, "OK", versionedList).
|
||||
Writes(versionedList)
|
||||
if err := addObjectParams(ws, rootScopedRoute, versionedListOptions); err != nil {
|
||||
return err
|
||||
}
|
||||
addParams(rootScopedRoute, rootScopedParams)
|
||||
ws.Route(rootScopedRoute)
|
||||
|
||||
// install the namespace-scoped route
|
||||
reqScope.Namer = MetricsNaming{
|
||||
handlers.ContextBasedNaming{
|
||||
GetContext: ctxFn,
|
||||
SelfLinker: a.group.Linker,
|
||||
ClusterScoped: false,
|
||||
SelfLinkPathPrefix: gpath.Join(a.prefix, scope.ParamName()) + "/",
|
||||
},
|
||||
}
|
||||
namespacedHandler := metrics.InstrumentRouteFunc("LIST", "custom-metrics-namespaced", restfulListResource(lister, nil, reqScope, false, a.minRequestTimeout))
|
||||
namespacedRoute := ws.GET(namespacedPath).To(namespacedHandler).
|
||||
Doc(doc).
|
||||
Param(ws.QueryParameter("pretty", "If 'true', then the output is pretty printed.")).
|
||||
Operation("listNamespaced"+kind).
|
||||
Produces(allMediaTypes...).
|
||||
Returns(http.StatusOK, "OK", versionedList).
|
||||
Writes(versionedList)
|
||||
if err := addObjectParams(ws, namespacedRoute, versionedListOptions); err != nil {
|
||||
return err
|
||||
}
|
||||
addParams(namespacedRoute, namespacedParams)
|
||||
ws.Route(namespacedRoute)
|
||||
|
||||
// install the special route for metrics describing namespaces (last b/c we modify the context func)
|
||||
reqScope.ContextFunc = ctxFn
|
||||
reqScope.Namer = MetricsNaming{
|
||||
handlers.ContextBasedNaming{
|
||||
GetContext: ctxFn,
|
||||
SelfLinker: a.group.Linker,
|
||||
ClusterScoped: false,
|
||||
SelfLinkPathPrefix: gpath.Join(a.prefix, scope.ParamName()) + "/",
|
||||
},
|
||||
}
|
||||
namespaceSpecificHandler := metrics.InstrumentRouteFunc("LIST", "custom-metrics-for-namespace", restfulListResource(lister, nil, reqScope, false, a.minRequestTimeout))
|
||||
namespaceSpecificRoute := ws.GET(namespaceSpecificPath).To(namespaceSpecificHandler).
|
||||
Doc(doc).
|
||||
Param(ws.QueryParameter("pretty", "If 'true', then the output is pretty printed.")).
|
||||
Operation("read"+kind+"ForNamespace").
|
||||
Produces(allMediaTypes...).
|
||||
Returns(http.StatusOK, "OK", versionedList).
|
||||
Writes(versionedList)
|
||||
if err := addObjectParams(ws, namespaceSpecificRoute, versionedListOptions); err != nil {
|
||||
return err
|
||||
}
|
||||
addParams(namespaceSpecificRoute, namespaceSpecificParams)
|
||||
ws.Route(namespaceSpecificRoute)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// This magic incantation returns *ptrToObject for an arbitrary pointer
|
||||
func indirectArbitraryPointer(ptrToObject interface{}) interface{} {
|
||||
return reflect.Indirect(reflect.ValueOf(ptrToObject)).Interface()
|
||||
}
|
||||
|
||||
// getResourceKind returns the external group version kind registered for the given storage object.
|
||||
func (a *MetricsAPIInstaller) getResourceKind(storage rest.Storage) (schema.GroupVersionKind, error) {
|
||||
object := storage.New()
|
||||
fqKinds, _, err := a.group.Typer.ObjectKinds(object)
|
||||
if err != nil {
|
||||
return schema.GroupVersionKind{}, err
|
||||
}
|
||||
|
||||
// a given go type can have multiple potential fully qualified kinds. Find the one that corresponds with the group
|
||||
// we're trying to register here
|
||||
fqKindToRegister := schema.GroupVersionKind{}
|
||||
for _, fqKind := range fqKinds {
|
||||
if fqKind.Group == a.group.GroupVersion.Group {
|
||||
fqKindToRegister = a.group.GroupVersion.WithKind(fqKind.Kind)
|
||||
break
|
||||
}
|
||||
|
||||
// TODO: keep rid of extensions api group dependency here
|
||||
// This keeps it doing what it was doing before, but it doesn't feel right.
|
||||
if fqKind.Group == "extensions" && fqKind.Kind == "ThirdPartyResourceData" {
|
||||
fqKindToRegister = a.group.GroupVersion.WithKind(fqKind.Kind)
|
||||
}
|
||||
}
|
||||
if fqKindToRegister.Empty() {
|
||||
return schema.GroupVersionKind{}, fmt.Errorf("unable to locate fully qualified kind for %v: found %v when registering for %v", reflect.TypeOf(object), fqKinds, a.group.GroupVersion)
|
||||
}
|
||||
return fqKindToRegister, nil
|
||||
}
|
||||
|
||||
// restMapping returns rest mapper for the resource provided by DynamicStorage.
|
||||
func (a *MetricsAPIInstaller) restMapping() (*meta.RESTMapping, error) {
|
||||
// subresources must have parent resources, and follow the namespacing rules of their parent.
|
||||
// So get the storage of the resource (which is the parent resource in case of subresources)
|
||||
fqKindToRegister, err := a.getResourceKind(a.group.DynamicStorage)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to locate fully qualified kind for mapper resource for dynamic storage: %v", err)
|
||||
}
|
||||
return a.group.Mapper.RESTMapping(fqKindToRegister.GroupKind(), fqKindToRegister.Version)
|
||||
}
|
||||
|
||||
func addParams(route *restful.RouteBuilder, params []*restful.Parameter) {
|
||||
for _, param := range params {
|
||||
route.Param(param)
|
||||
}
|
||||
}
|
||||
|
||||
// addObjectParams converts a runtime.Object into a set of go-restful Param() definitions on the route.
|
||||
// The object must be a pointer to a struct; only fields at the top level of the struct that are not
|
||||
// themselves interfaces or structs are used; only fields with a json tag that is non empty (the standard
|
||||
// Go JSON behavior for omitting a field) become query parameters. The name of the query parameter is
|
||||
// the JSON field name. If a description struct tag is set on the field, that description is used on the
|
||||
// query parameter. In essence, it converts a standard JSON top level object into a query param schema.
|
||||
func addObjectParams(ws *restful.WebService, route *restful.RouteBuilder, obj interface{}) error {
|
||||
sv, err := conversion.EnforcePtr(obj)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
st := sv.Type()
|
||||
switch st.Kind() {
|
||||
case reflect.Struct:
|
||||
for i := 0; i < st.NumField(); i++ {
|
||||
name := st.Field(i).Name
|
||||
sf, ok := st.FieldByName(name)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
switch sf.Type.Kind() {
|
||||
case reflect.Interface, reflect.Struct:
|
||||
case reflect.Ptr:
|
||||
// TODO: This is a hack to let metav1.Time through. This needs to be fixed in a more generic way eventually. bug #36191
|
||||
if (sf.Type.Elem().Kind() == reflect.Interface || sf.Type.Elem().Kind() == reflect.Struct) && strings.TrimPrefix(sf.Type.String(), "*") != "metav1.Time" {
|
||||
continue
|
||||
}
|
||||
fallthrough
|
||||
default:
|
||||
jsonTag := sf.Tag.Get("json")
|
||||
if len(jsonTag) == 0 {
|
||||
continue
|
||||
}
|
||||
jsonName := strings.SplitN(jsonTag, ",", 2)[0]
|
||||
if len(jsonName) == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
var desc string
|
||||
if docable, ok := obj.(documentable); ok {
|
||||
desc = docable.SwaggerDoc()[jsonName]
|
||||
}
|
||||
route.Param(ws.QueryParameter(jsonName, desc).DataType(typeToJSON(sf.Type.String())))
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// TODO: this is incomplete, expand as needed.
|
||||
// Convert the name of a golang type to the name of a JSON type
|
||||
func typeToJSON(typeName string) string {
|
||||
switch typeName {
|
||||
case "bool", "*bool":
|
||||
return "boolean"
|
||||
case "uint8", "*uint8", "int", "*int", "int32", "*int32", "int64", "*int64", "uint32", "*uint32", "uint64", "*uint64":
|
||||
return "integer"
|
||||
case "float64", "*float64", "float32", "*float32":
|
||||
return "number"
|
||||
case "metav1.Time", "*metav1.Time":
|
||||
return "string"
|
||||
case "byte", "*byte":
|
||||
return "string"
|
||||
case "v1.DeletionPropagation", "*v1.DeletionPropagation":
|
||||
return "string"
|
||||
|
||||
// TODO: Fix these when go-restful supports a way to specify an array query param:
|
||||
// https://github.com/emicklei/go-restful/issues/225
|
||||
case "[]string", "[]*string":
|
||||
return "string"
|
||||
case "[]int32", "[]*int32":
|
||||
return "integer"
|
||||
|
||||
default:
|
||||
return typeName
|
||||
}
|
||||
}
|
||||
|
||||
// An interface to see if an object supports swagger documentation as a method
|
||||
type documentable interface {
|
||||
SwaggerDoc() map[string]string
|
||||
}
|
||||
|
||||
// MetricsNaming is similar to handlers.ContextBasedNaming, except that it handles
|
||||
// polymorphism over subresources.
|
||||
type MetricsNaming struct {
|
||||
handlers.ContextBasedNaming
|
||||
}
|
||||
|
||||
func (n MetricsNaming) GenerateLink(req *http.Request, obj runtime.Object) (uri string, err error) {
|
||||
requestInfo, ok := request.RequestInfoFrom(n.GetContext(req))
|
||||
if !ok {
|
||||
return "", fmt.Errorf("missing requestInfo")
|
||||
}
|
||||
|
||||
if requestInfo.Resource != "metrics" {
|
||||
n.SelfLinkPathSuffix += "/" + requestInfo.Subresource
|
||||
}
|
||||
|
||||
// since this is not a pointer receiver, it's ok to modify it here
|
||||
// (since we copy around every method call)
|
||||
if n.ClusterScoped {
|
||||
n.SelfLinkPathPrefix += requestInfo.Resource + "/"
|
||||
return n.ContextBasedNaming.GenerateLink(req, obj)
|
||||
}
|
||||
|
||||
return n.ContextBasedNaming.GenerateLink(req, obj)
|
||||
}
|
||||
|
||||
func restfulListResource(r rest.Lister, rw rest.Watcher, scope handlers.RequestScope, forceWatch bool, minRequestTimeout time.Duration) restful.RouteFunction {
|
||||
return func(req *restful.Request, res *restful.Response) {
|
||||
handlers.ListResource(r, rw, scope, forceWatch, minRequestTimeout)(res.ResponseWriter, req.Request)
|
||||
}
|
||||
}
|
||||
79
vendor/github.com/directxman12/custom-metrics-boilerplate/pkg/apiserver/installer/installer_test.go
generated
vendored
Normal file
79
vendor/github.com/directxman12/custom-metrics-boilerplate/pkg/apiserver/installer/installer_test.go
generated
vendored
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
/*
|
||||
Copyright 2017 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
package installer
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"testing"
|
||||
|
||||
"k8s.io/apimachinery/pkg/api/meta"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/client-go/pkg/api"
|
||||
|
||||
"github.com/emicklei/go-restful"
|
||||
)
|
||||
|
||||
type setTestSelfLinker struct {
|
||||
t *testing.T
|
||||
expectedSet string
|
||||
name string
|
||||
namespace string
|
||||
called bool
|
||||
err error
|
||||
}
|
||||
|
||||
func (s *setTestSelfLinker) Namespace(runtime.Object) (string, error) { return s.namespace, s.err }
|
||||
func (s *setTestSelfLinker) Name(runtime.Object) (string, error) { return s.name, s.err }
|
||||
func (s *setTestSelfLinker) SelfLink(runtime.Object) (string, error) { return "", s.err }
|
||||
func (s *setTestSelfLinker) SetSelfLink(obj runtime.Object, selfLink string) error {
|
||||
if e, a := s.expectedSet, selfLink; e != a {
|
||||
s.t.Errorf("expected '%v', got '%v'", e, a)
|
||||
}
|
||||
s.called = true
|
||||
return s.err
|
||||
}
|
||||
|
||||
func TestScopeNamingGenerateLink(t *testing.T) {
|
||||
selfLinker := &setTestSelfLinker{
|
||||
t: t,
|
||||
expectedSet: "/api/v1/namespaces/other/services/foo",
|
||||
name: "foo",
|
||||
namespace: "other",
|
||||
}
|
||||
s := scopeNaming{
|
||||
meta.RESTScopeNamespace,
|
||||
selfLinker,
|
||||
func(name, namespace, resource, subresource string) bytes.Buffer {
|
||||
return *bytes.NewBufferString("/api/v1/namespaces/" + namespace + "/services/" + name)
|
||||
},
|
||||
true,
|
||||
}
|
||||
service := &api.Service{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "foo",
|
||||
Namespace: "other",
|
||||
},
|
||||
TypeMeta: metav1.TypeMeta{
|
||||
Kind: "Service",
|
||||
},
|
||||
}
|
||||
_, err := s.GenerateLink(&restful.Request{}, service)
|
||||
if err != nil {
|
||||
t.Errorf("Unexpected error %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
87
vendor/github.com/directxman12/custom-metrics-boilerplate/pkg/cmd/server/start.go
generated
vendored
Normal file
87
vendor/github.com/directxman12/custom-metrics-boilerplate/pkg/cmd/server/start.go
generated
vendored
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
/*
|
||||
Copyright 2017 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package server
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
|
||||
genericapiserver "k8s.io/apiserver/pkg/server"
|
||||
genericoptions "k8s.io/apiserver/pkg/server/options"
|
||||
"github.com/directxman12/custom-metrics-boilerplate/pkg/apiserver"
|
||||
)
|
||||
|
||||
type CustomMetricsAdapterServerOptions struct {
|
||||
// genericoptions.ReccomendedOptions - EtcdOptions
|
||||
SecureServing *genericoptions.SecureServingOptions
|
||||
Authentication *genericoptions.DelegatingAuthenticationOptions
|
||||
Authorization *genericoptions.DelegatingAuthorizationOptions
|
||||
Features *genericoptions.FeatureOptions
|
||||
|
||||
StdOut io.Writer
|
||||
StdErr io.Writer
|
||||
}
|
||||
|
||||
func NewCustomMetricsAdapterServerOptions(out, errOut io.Writer) *CustomMetricsAdapterServerOptions {
|
||||
o := &CustomMetricsAdapterServerOptions{
|
||||
SecureServing: genericoptions.NewSecureServingOptions(),
|
||||
Authentication: genericoptions.NewDelegatingAuthenticationOptions(),
|
||||
Authorization: genericoptions.NewDelegatingAuthorizationOptions(),
|
||||
Features: genericoptions.NewFeatureOptions(),
|
||||
|
||||
StdOut: out,
|
||||
StdErr: errOut,
|
||||
}
|
||||
|
||||
return o
|
||||
}
|
||||
|
||||
func (o CustomMetricsAdapterServerOptions) Validate(args []string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *CustomMetricsAdapterServerOptions) Complete() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o CustomMetricsAdapterServerOptions) Config() (*apiserver.Config, error) {
|
||||
// TODO have a "real" external address (have an AdvertiseAddress?)
|
||||
if err := o.SecureServing.MaybeDefaultWithSelfSignedCerts("localhost", nil, []net.IP{net.ParseIP("127.0.0.1")}); err != nil {
|
||||
return nil, fmt.Errorf("error creating self-signed certificates: %v", err)
|
||||
}
|
||||
|
||||
serverConfig := genericapiserver.NewConfig(apiserver.Codecs)
|
||||
if err := o.SecureServing.ApplyTo(serverConfig); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := o.Authentication.ApplyTo(serverConfig); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := o.Authorization.ApplyTo(serverConfig); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// TODO: we can't currently serve swagger because we don't have a good way to dynamically update it
|
||||
// serverConfig.SwaggerConfig = genericapiserver.DefaultSwaggerConfig()
|
||||
|
||||
config := &apiserver.Config{
|
||||
GenericConfig: serverConfig,
|
||||
}
|
||||
return config, nil
|
||||
}
|
||||
77
vendor/github.com/directxman12/custom-metrics-boilerplate/pkg/provider/interfaces.go
generated
vendored
Normal file
77
vendor/github.com/directxman12/custom-metrics-boilerplate/pkg/provider/interfaces.go
generated
vendored
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
/*
|
||||
Copyright 2017 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package provider
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"k8s.io/apimachinery/pkg/labels"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
"k8s.io/metrics/pkg/apis/custom_metrics"
|
||||
)
|
||||
|
||||
// MetricInfo describes a metric for a particular
|
||||
// fully-qualified group resource.
|
||||
type MetricInfo struct {
|
||||
GroupResource schema.GroupResource
|
||||
Namespaced bool
|
||||
Metric string
|
||||
}
|
||||
|
||||
func (i MetricInfo) String() string {
|
||||
if i.Namespaced {
|
||||
return fmt.Sprintf("%s/%s(namespaced)", i.GroupResource.String(), i.Metric)
|
||||
} else {
|
||||
return fmt.Sprintf("%s/%s", i.GroupResource.String(), i.Metric)
|
||||
}
|
||||
}
|
||||
|
||||
// CustomMetricsProvider is a soruce of custom metrics
|
||||
// which is able to supply a list of available metrics,
|
||||
// as well as metric values themselves on demand.
|
||||
//
|
||||
// Note that group-resources are provided as GroupResources,
|
||||
// not GroupKinds. This is to allow flexibility on the part
|
||||
// of the implementor: implementors do not necessarily need
|
||||
// to be aware of all existing kinds and their corresponding
|
||||
// REST mappings in order to perform queries.
|
||||
//
|
||||
// For queries that use label selectors, it is up to the
|
||||
// implementor to decide how to make use of the label selector --
|
||||
// they may wish to query the main Kubernetes API server, or may
|
||||
// wish to simply make use of stored information in their TSDB.
|
||||
type CustomMetricsProvider interface {
|
||||
// GetRootScopedMetricByName fetches a particular metric for a particular root-scoped object.
|
||||
GetRootScopedMetricByName(groupResource schema.GroupResource, name string, metricName string) (*custom_metrics.MetricValue, error)
|
||||
|
||||
// GetRootScopedMetricByName fetches a particular metric for a set of root-scoped objects
|
||||
// matching the given label selector.
|
||||
GetRootScopedMetricBySelector(groupResource schema.GroupResource, selector labels.Selector, metricName string) (*custom_metrics.MetricValueList, error)
|
||||
|
||||
// GetNamespacedMetricByName fetches a particular metric for a particular namespaced object.
|
||||
GetNamespacedMetricByName(groupResource schema.GroupResource, namespace string, name string, metricName string) (*custom_metrics.MetricValue, error)
|
||||
|
||||
// GetNamespacedMetricByName fetches a particular metric for a set of namespaced objects
|
||||
// matching the given label selector.
|
||||
GetNamespacedMetricBySelector(groupResource schema.GroupResource, namespace string, selector labels.Selector, metricName string) (*custom_metrics.MetricValueList, error)
|
||||
|
||||
// ListAllMetrics provides a list of all available metrics at
|
||||
// the current time. Note that this is not allowed to return
|
||||
// an error, so it is reccomended that implementors cache and
|
||||
// periodically update this list, instead of querying every time.
|
||||
ListAllMetrics() []MetricInfo
|
||||
}
|
||||
48
vendor/github.com/directxman12/custom-metrics-boilerplate/pkg/provider/resource_lister.go
generated
vendored
Normal file
48
vendor/github.com/directxman12/custom-metrics-boilerplate/pkg/provider/resource_lister.go
generated
vendored
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
Copyright 2017 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package provider
|
||||
|
||||
import (
|
||||
"k8s.io/apiserver/pkg/endpoints/discovery"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
)
|
||||
|
||||
type customMetricsResourceLister struct {
|
||||
provider CustomMetricsProvider
|
||||
}
|
||||
|
||||
func NewResourceLister(provider CustomMetricsProvider) discovery.APIResourceLister {
|
||||
return &customMetricsResourceLister{
|
||||
provider: provider,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *customMetricsResourceLister) ListAPIResources() []metav1.APIResource {
|
||||
metrics := l.provider.ListAllMetrics()
|
||||
resources := make([]metav1.APIResource, len(metrics))
|
||||
|
||||
for i, metric := range metrics {
|
||||
resources[i] = metav1.APIResource{
|
||||
Name: metric.GroupResource.String()+"/"+metric.Metric,
|
||||
Namespaced: metric.Namespaced,
|
||||
Kind: "MetricValueList",
|
||||
Verbs: metav1.Verbs{"get"}, // TODO: support "watch"
|
||||
}
|
||||
}
|
||||
|
||||
return resources
|
||||
}
|
||||
128
vendor/github.com/directxman12/custom-metrics-boilerplate/pkg/registry/custom_metrics/reststorage.go
generated
vendored
Normal file
128
vendor/github.com/directxman12/custom-metrics-boilerplate/pkg/registry/custom_metrics/reststorage.go
generated
vendored
Normal file
|
|
@ -0,0 +1,128 @@
|
|||
/*
|
||||
Copyright 2017 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package apiserver
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
metainternalversion "k8s.io/apimachinery/pkg/apis/meta/internalversion"
|
||||
"k8s.io/apimachinery/pkg/labels"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
genericapirequest "k8s.io/apiserver/pkg/endpoints/request"
|
||||
"k8s.io/apiserver/pkg/registry/rest"
|
||||
"github.com/directxman12/custom-metrics-boilerplate/pkg/provider"
|
||||
"k8s.io/metrics/pkg/apis/custom_metrics"
|
||||
"k8s.io/apiserver/pkg/endpoints/request"
|
||||
)
|
||||
|
||||
type REST struct {
|
||||
cmProvider provider.CustomMetricsProvider
|
||||
}
|
||||
|
||||
var _ rest.Storage = &REST{}
|
||||
var _ rest.Lister = &REST{}
|
||||
|
||||
func NewREST(cmProvider provider.CustomMetricsProvider) *REST {
|
||||
return &REST{
|
||||
cmProvider: cmProvider,
|
||||
}
|
||||
}
|
||||
|
||||
// Implement Storage
|
||||
|
||||
func (r *REST) New() runtime.Object {
|
||||
return &custom_metrics.MetricValue{}
|
||||
}
|
||||
|
||||
// Implement Lister
|
||||
|
||||
func (r *REST) NewList() runtime.Object {
|
||||
return &custom_metrics.MetricValueList{}
|
||||
}
|
||||
|
||||
func (r *REST) List(ctx genericapirequest.Context, options *metainternalversion.ListOptions) (runtime.Object, error) {
|
||||
// populate the label selector, defaulting to all
|
||||
selector := labels.Everything()
|
||||
if options != nil && options.LabelSelector != nil {
|
||||
selector = options.LabelSelector
|
||||
}
|
||||
|
||||
// grab the name, if present, from the field selector list options
|
||||
// (this is how the list handler logic injects it)
|
||||
// (otherwise we'd have to write a custom list handler)
|
||||
name := "*"
|
||||
if options != nil && options.FieldSelector != nil {
|
||||
if nameMatch, required := options.FieldSelector.RequiresExactMatch("metadata.name"); required {
|
||||
name = nameMatch
|
||||
}
|
||||
}
|
||||
|
||||
namespace := genericapirequest.NamespaceValue(ctx)
|
||||
|
||||
requestInfo, ok := request.RequestInfoFrom(ctx)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unable to get resource and metric name from request")
|
||||
}
|
||||
|
||||
resourceRaw := requestInfo.Resource
|
||||
metricName := requestInfo.Subresource
|
||||
|
||||
groupResource := schema.ParseGroupResource(resourceRaw)
|
||||
|
||||
// handle metrics describing namespaces
|
||||
if namespace != "" && resourceRaw == "metrics" {
|
||||
// namespace-describing metrics have a path of /namespaces/$NS/metrics/$metric,
|
||||
groupResource = schema.GroupResource{Resource: "namespaces"}
|
||||
metricName = name
|
||||
name = namespace
|
||||
namespace = ""
|
||||
}
|
||||
|
||||
// handle namespaced and root metrics
|
||||
if name == "*" {
|
||||
return r.handleWildcardOp(namespace, groupResource, selector, metricName)
|
||||
} else {
|
||||
return r.handleIndividualOp(namespace, groupResource, name, metricName)
|
||||
}
|
||||
}
|
||||
|
||||
func (r *REST) handleIndividualOp(namespace string, groupResource schema.GroupResource, name string, metricName string) (*custom_metrics.MetricValueList, error) {
|
||||
var err error
|
||||
var singleRes *custom_metrics.MetricValue
|
||||
if namespace == "" {
|
||||
singleRes, err = r.cmProvider.GetRootScopedMetricByName(groupResource, name, metricName)
|
||||
} else {
|
||||
singleRes, err = r.cmProvider.GetNamespacedMetricByName(groupResource, namespace, name, metricName)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &custom_metrics.MetricValueList{
|
||||
Items: []custom_metrics.MetricValue{*singleRes},
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (r *REST) handleWildcardOp(namespace string, groupResource schema.GroupResource, selector labels.Selector, metricName string) (*custom_metrics.MetricValueList, error) {
|
||||
if namespace == "" {
|
||||
return r.cmProvider.GetRootScopedMetricBySelector(groupResource, selector, metricName)
|
||||
} else {
|
||||
return r.cmProvider.GetNamespacedMetricBySelector(groupResource, namespace, selector, metricName)
|
||||
}
|
||||
}
|
||||
180
vendor/github.com/directxman12/custom-metrics-boilerplate/pkg/sample-cmd/provider/provider.go
generated
vendored
Normal file
180
vendor/github.com/directxman12/custom-metrics-boilerplate/pkg/sample-cmd/provider/provider.go
generated
vendored
Normal file
|
|
@ -0,0 +1,180 @@
|
|||
/*
|
||||
Copyright 2017 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package provider
|
||||
|
||||
import (
|
||||
"time"
|
||||
"fmt"
|
||||
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
coreclient "k8s.io/client-go/kubernetes/typed/core/v1"
|
||||
"k8s.io/apimachinery/pkg/labels"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
apimeta "k8s.io/apimachinery/pkg/api/meta"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/metrics/pkg/apis/custom_metrics"
|
||||
"k8s.io/client-go/pkg/api"
|
||||
_ "k8s.io/client-go/pkg/api/install"
|
||||
"k8s.io/apimachinery/pkg/api/resource"
|
||||
"k8s.io/client-go/kubernetes/scheme"
|
||||
|
||||
"github.com/directxman12/custom-metrics-boilerplate/pkg/provider"
|
||||
)
|
||||
|
||||
type incrementalTestingProvider struct {
|
||||
client coreclient.CoreV1Interface
|
||||
|
||||
values map[provider.MetricInfo]int64
|
||||
}
|
||||
|
||||
func NewFakeProvider(client coreclient.CoreV1Interface) provider.CustomMetricsProvider {
|
||||
return &incrementalTestingProvider{
|
||||
client: client,
|
||||
values: make(map[provider.MetricInfo]int64),
|
||||
}
|
||||
}
|
||||
|
||||
func (p *incrementalTestingProvider) valueFor(groupResource schema.GroupResource, metricName string, namespaced bool) int64 {
|
||||
info := provider.MetricInfo{
|
||||
GroupResource: groupResource,
|
||||
Metric: metricName,
|
||||
Namespaced: namespaced,
|
||||
}
|
||||
|
||||
value := p.values[info]
|
||||
value += 1
|
||||
p.values[info] = value
|
||||
|
||||
return value
|
||||
}
|
||||
|
||||
func (p *incrementalTestingProvider) metricFor(value int64, groupResource schema.GroupResource, namespace string, name string, metricName string) (*custom_metrics.MetricValue, error) {
|
||||
group, err := api.Registry.Group(groupResource.Group)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
kind, err := api.Registry.RESTMapper().KindFor(groupResource.WithVersion(group.GroupVersion.Version))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &custom_metrics.MetricValue{
|
||||
DescribedObject: api.ObjectReference{
|
||||
APIVersion: groupResource.Group+"/"+runtime.APIVersionInternal,
|
||||
Kind: kind.Kind,
|
||||
Name: name,
|
||||
Namespace: namespace,
|
||||
},
|
||||
MetricName: metricName,
|
||||
Timestamp: metav1.Time{time.Now()},
|
||||
Value: *resource.NewMilliQuantity(value * 100, resource.DecimalSI),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (p *incrementalTestingProvider) metricsFor(totalValue int64, groupResource schema.GroupResource, metricName string, list runtime.Object) (*custom_metrics.MetricValueList, error) {
|
||||
if !apimeta.IsListType(list) {
|
||||
return nil, fmt.Errorf("returned object was not a list")
|
||||
}
|
||||
|
||||
res := make([]custom_metrics.MetricValue, 0)
|
||||
|
||||
err := apimeta.EachListItem(list, func(item runtime.Object) error {
|
||||
objMeta := item.(metav1.ObjectMetaAccessor).GetObjectMeta()
|
||||
value, err := p.metricFor(0, groupResource, objMeta.GetNamespace(), objMeta.GetName(), metricName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
res = append(res, *value)
|
||||
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for i := range res {
|
||||
res[i].Value = *resource.NewMilliQuantity(100 * totalValue / int64(len(res)), resource.DecimalSI)
|
||||
}
|
||||
|
||||
//return p.metricFor(value, groupResource, "", name, metricName)
|
||||
return &custom_metrics.MetricValueList{
|
||||
Items: res,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (p *incrementalTestingProvider) GetRootScopedMetricByName(groupResource schema.GroupResource, name string, metricName string) (*custom_metrics.MetricValue, error) {
|
||||
value := p.valueFor(groupResource, metricName, false)
|
||||
return p.metricFor(value, groupResource, "", name, metricName)
|
||||
}
|
||||
|
||||
|
||||
func (p *incrementalTestingProvider) GetRootScopedMetricBySelector(groupResource schema.GroupResource, selector labels.Selector, metricName string) (*custom_metrics.MetricValueList, error) {
|
||||
totalValue := p.valueFor(groupResource, metricName, false)
|
||||
|
||||
// TODO: work for objects not in core v1
|
||||
matchingObjectsRaw, err := p.client.RESTClient().Get().
|
||||
Resource(groupResource.Resource).
|
||||
VersionedParams(&metav1.ListOptions{LabelSelector: selector.String()}, scheme.ParameterCodec).
|
||||
Do().
|
||||
Get()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return p.metricsFor(totalValue, groupResource, metricName, matchingObjectsRaw)
|
||||
}
|
||||
|
||||
func (p *incrementalTestingProvider) GetNamespacedMetricByName(groupResource schema.GroupResource, namespace string, name string, metricName string) (*custom_metrics.MetricValue, error) {
|
||||
value := p.valueFor(groupResource, metricName, true)
|
||||
return p.metricFor(value, groupResource, namespace, name, metricName)
|
||||
}
|
||||
|
||||
func (p *incrementalTestingProvider) GetNamespacedMetricBySelector(groupResource schema.GroupResource, namespace string, selector labels.Selector, metricName string) (*custom_metrics.MetricValueList, error) {
|
||||
totalValue := p.valueFor(groupResource, metricName, true)
|
||||
|
||||
// TODO: work for objects not in core v1
|
||||
matchingObjectsRaw, err := p.client.RESTClient().Get().
|
||||
Namespace(namespace).
|
||||
Resource(groupResource.Resource).
|
||||
VersionedParams(&metav1.ListOptions{LabelSelector: selector.String()}, scheme.ParameterCodec).
|
||||
Do().
|
||||
Get()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return p.metricsFor(totalValue, groupResource, metricName, matchingObjectsRaw)
|
||||
}
|
||||
|
||||
func (p *incrementalTestingProvider) ListAllMetrics() []provider.MetricInfo {
|
||||
// TODO: maybe dynamically generate this?
|
||||
return []provider.MetricInfo{
|
||||
{
|
||||
GroupResource: schema.GroupResource{Group: "", Resource: "pods"},
|
||||
Metric: "packets-per-second",
|
||||
Namespaced: true,
|
||||
},
|
||||
{
|
||||
GroupResource: schema.GroupResource{Group: "", Resource: "services"},
|
||||
Metric: "connections-per-second",
|
||||
Namespaced: true,
|
||||
},
|
||||
{
|
||||
GroupResource: schema.GroupResource{Group: "", Resource: "namespaces"},
|
||||
Metric: "queue-length",
|
||||
Namespaced: false,
|
||||
},
|
||||
}
|
||||
}
|
||||
108
vendor/github.com/directxman12/custom-metrics-boilerplate/pkg/sample-cmd/server/start.go
generated
vendored
Normal file
108
vendor/github.com/directxman12/custom-metrics-boilerplate/pkg/sample-cmd/server/start.go
generated
vendored
Normal file
|
|
@ -0,0 +1,108 @@
|
|||
/*
|
||||
Copyright 2017 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package server
|
||||
|
||||
import (
|
||||
"io"
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"k8s.io/client-go/rest"
|
||||
"k8s.io/client-go/tools/clientcmd"
|
||||
coreclient "k8s.io/client-go/kubernetes/typed/core/v1"
|
||||
|
||||
"github.com/directxman12/custom-metrics-boilerplate/pkg/cmd/server"
|
||||
"github.com/directxman12/custom-metrics-boilerplate/pkg/sample-cmd/provider"
|
||||
)
|
||||
|
||||
// NewCommandStartMaster provides a CLI handler for 'start master' command
|
||||
func NewCommandStartSampleAdapterServer(out, errOut io.Writer, stopCh <-chan struct{}) *cobra.Command {
|
||||
baseOpts := server.NewCustomMetricsAdapterServerOptions(out, errOut)
|
||||
o := SampleAdapterServerOptions{
|
||||
CustomMetricsAdapterServerOptions: baseOpts,
|
||||
}
|
||||
|
||||
cmd := &cobra.Command{
|
||||
Short: "Launch the custom metrics API adapter server",
|
||||
Long: "Launch the custom metrics API adapter server",
|
||||
RunE: func(c *cobra.Command, args []string) error {
|
||||
if err := o.Complete(); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := o.Validate(args); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := o.RunCustomMetricsAdapterServer(stopCh); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
flags := cmd.Flags()
|
||||
o.SecureServing.AddFlags(flags)
|
||||
o.Authentication.AddFlags(flags)
|
||||
o.Authorization.AddFlags(flags)
|
||||
o.Features.AddFlags(flags)
|
||||
|
||||
flags.StringVar(&o.RemoteKubeConfigFile, "lister-kubeconfig", o.RemoteKubeConfigFile, ""+
|
||||
"kubeconfig file pointing at the 'core' kubernetes server with enough rights to list "+
|
||||
"any described objets")
|
||||
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
func (o SampleAdapterServerOptions) RunCustomMetricsAdapterServer(stopCh <-chan struct{}) error {
|
||||
config, err := o.Config()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var clientConfig *rest.Config
|
||||
if len(o.RemoteKubeConfigFile) > 0 {
|
||||
loadingRules := &clientcmd.ClientConfigLoadingRules{ExplicitPath: o.RemoteKubeConfigFile}
|
||||
loader := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(loadingRules, &clientcmd.ConfigOverrides{})
|
||||
|
||||
clientConfig, err = loader.ClientConfig()
|
||||
} else {
|
||||
clientConfig, err = rest.InClusterConfig()
|
||||
}
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to construct lister client config to initialize provider: %v", err)
|
||||
}
|
||||
|
||||
client, err := coreclient.NewForConfig(clientConfig)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to construct lister client to initialize provider: %v", err)
|
||||
}
|
||||
|
||||
cmProvider := provider.NewFakeProvider(client)
|
||||
|
||||
server, err := config.Complete().New(cmProvider)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return server.GenericAPIServer.PrepareRun().Run(stopCh)
|
||||
}
|
||||
|
||||
type SampleAdapterServerOptions struct {
|
||||
*server.CustomMetricsAdapterServerOptions
|
||||
|
||||
// RemoteKubeConfigFile is the config used to list pods from the master API server
|
||||
RemoteKubeConfigFile string
|
||||
}
|
||||
42
vendor/github.com/directxman12/custom-metrics-boilerplate/sample-main.go
generated
vendored
Normal file
42
vendor/github.com/directxman12/custom-metrics-boilerplate/sample-main.go
generated
vendored
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
Copyright 2016 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"os"
|
||||
"runtime"
|
||||
|
||||
"k8s.io/apimachinery/pkg/util/wait"
|
||||
"k8s.io/apiserver/pkg/util/logs"
|
||||
"github.com/directxman12/custom-metrics-boilerplate/pkg/sample-cmd/server"
|
||||
)
|
||||
|
||||
func main() {
|
||||
logs.InitLogs()
|
||||
defer logs.FlushLogs()
|
||||
|
||||
if len(os.Getenv("GOMAXPROCS")) == 0 {
|
||||
runtime.GOMAXPROCS(runtime.NumCPU())
|
||||
}
|
||||
|
||||
cmd := server.NewCommandStartSampleAdapterServer(os.Stdout, os.Stderr, wait.NeverStop)
|
||||
cmd.Flags().AddGoFlagSet(flag.CommandLine)
|
||||
if err := cmd.Execute(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue