Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Change the endpoint called by loadSpec #356

Merged
merged 7 commits into from
Nov 12, 2018

Conversation

ajpauwels
Copy link
Contributor

According to this Kubernetes doc:
https://kubernetes.io/docs/concepts/overview/kubernetes-api/#openapi-and-swagger-definitions

The /swagger* endpoints have been deprecated starting with v1.10.

This commit changes loadSpec to address this:

  1. Initially attempts to contact /openapi/v2 with Accept: application/json in order
    to get the swagger file via the new URL
  2. If that fails with a 404, attempts to contact swagger.json to support clusters which
    do not have the new endpoint

fixes #352

According to this Kubernetes doc:
https://kubernetes.io/docs/concepts/overview/kubernetes-api/#openapi-and-swagger-definitions

The `/swagger*` endpoints have been deprecated starting with v1.10.

This commit changes `loadSpec` to address this:
1. Initially attempts to contact `/openapi/v2` with `Accept: application/json` in order
   to get the swagger file via the new URL
2. If that fails with a 404, attempts to contact `swagger.json` to support clusters which
   do not have the new endpoint
If the response is a 404, the async call must be returned so that
execution of the first callback stops.
- Changed existing test to mock `/openapi/v2`
- Added new tests to check fallback-logic and error logic
Copy link
Contributor

@silasbw silasbw left a comment

Choose a reason for hiding this comment

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

Awesome! A few minor comments.

Sorry for the delay on the review. I've been on vacation the last week.

@@ -39,10 +39,19 @@ class Root extends Component {
*/
loadSpec() {
return new Promise((resolve, reject) => {
this.http.request('GET', { path: '/swagger.json' }, (err, res) => {
this.http.request('GET', { headers: { accept: 'application/json' }, path: '/openapi/v2' }, (err, res) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the headers required? I would expect https://github.com/godaddy/kubernetes-client/blob/master/lib/request.js#L147 to do that implicitly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right, it's unnecessary, I explicitly added it because the k8s docs (https://kubernetes.io/docs/concepts/overview/kubernetes-api/#openapi-and-swagger-definitions) use headers to differentiate between json and pb swaggers, but k8s also explicitly uses application/json if header is not set, will remove.

if (res.statusCode !== 200) {
return reject(new Error(`Failed to get swagger.json: ${res.statusCode}`));
if (res.statusCode === 404) {
return this.http.request('GET', { path: '/swagger.json' }, (err, res) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you run the linter? I think it will complain about aliasing here (e.g., err in the first callback and err here).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed err and res aliasing

- The 'accept' header defaults to 'application/json' on both the http
  lib and the kubernetes server, so no need to add it
- Aliased err and res objects were given different names
@ajpauwels
Copy link
Contributor Author

ajpauwels commented Nov 8, 2018

What's your policy on package-lock.json, looks like mine changed when I ran npm install.

Hope you had a good vacation!

@silasbw silasbw merged commit 8a5f5cb into godaddy:master Nov 12, 2018
@silasbw
Copy link
Contributor

silasbw commented Nov 12, 2018

Published this change with kubernetes-client@6.4.0. Thanks again @ajpauwels 🏅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Replace loadSpec URL to new OpenAPI spec
2 participants