-
Notifications
You must be signed in to change notification settings - Fork 544
bump openapi version to support for k8s media types #1341
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
Merged
k8s-ci-robot
merged 7 commits into
kubernetes-client:release-1.x
from
davidgamero:davidgamero/bump-openapi-for-media-types
Nov 14, 2023
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d4862a4
regen with bumped openapi
davidgamero f1e230b
update patch examples
davidgamero 5c059cc
audit fix
davidgamero f3af15b
audit fix
davidgamero c17ff31
audit fix
davidgamero 7ce7322
Merge branch 'release-1.x' into davidgamero/bump-openapi-for-media-types
davidgamero 62e5ab1
comment feedback
davidgamero File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// in a real program use require('@kubernetes/client-node') | ||
import { | ||
CoreV1Api, | ||
RequestContext, | ||
ResponseContext, | ||
KubeConfig, | ||
createConfiguration, | ||
Configuration, | ||
ServerConfiguration, | ||
} from '../../../dist'; | ||
import { PromiseMiddlewareWrapper } from '../../../dist/gen/middleware'; | ||
|
||
const kc = new KubeConfig(); | ||
kc.loadFromDefault(); | ||
|
||
const k8sApi = kc.makeApiClient(CoreV1Api); | ||
|
||
k8sApi | ||
.listNamespacedPod({ | ||
namespace: 'default', | ||
}) | ||
.then((res) => { | ||
const patch = [ | ||
{ | ||
op: 'replace', | ||
path: '/metadata/labels', | ||
value: { | ||
foo: 'bar', | ||
}, | ||
}, | ||
]; | ||
const options = { headers: { 'Content-type': 'application/json-patch+json' } }; | ||
const headerPatchMiddleware = new PromiseMiddlewareWrapper({ | ||
pre: async (requestContext: RequestContext) => { | ||
requestContext.setHeaderParam('Content-type', 'application/json-patch+json'); | ||
return requestContext; | ||
}, | ||
post: async (responseContext: ResponseContext) => responseContext, | ||
}); | ||
const currentContext = kc.getCurrentContext(); | ||
const currentCluster = kc.getCluster(currentContext); | ||
if (currentCluster === undefined || currentCluster === null) { | ||
throw new Error('Cluster is undefined'); | ||
} | ||
const server = currentCluster.server; | ||
if (server === undefined) { | ||
throw new Error('Server is undefined'); | ||
} | ||
|
||
const baseServerConfig: ServerConfiguration<{}> = new ServerConfiguration<{}>(server, {}); | ||
const configuration: Configuration = createConfiguration({ | ||
middleware: [headerPatchMiddleware], | ||
baseServer: baseServerConfig, | ||
authMethods: { | ||
default: kc, | ||
}, | ||
}); | ||
|
||
const podName = res.items[0].metadata?.name; | ||
if (podName === undefined) { | ||
throw new Error('Pod name is undefined'); | ||
} | ||
k8sApi | ||
.patchNamespacedPod( | ||
{ | ||
name: podName, | ||
namespace: 'default', | ||
body: patch, | ||
}, | ||
configuration, | ||
) | ||
.then(() => { | ||
// tslint:disable-next-line:no-console | ||
console.log('Patched.'); | ||
}) | ||
.catch((err) => { | ||
// tslint:disable-next-line:no-console | ||
console.log('Error: ', err); | ||
}); | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
Requested Commit: 5555137b7926de2f501e091718ff72429b808220 | ||
Actual Commit: 5555137b7926de2f501e091718ff72429b808220 | ||
Requested Commit: 53289263d921e627cb05894c8477238dff48d62f | ||
Actual Commit: 53289263d921e627cb05894c8477238dff48d62f |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
7.0.0-SNAPSHOT | ||
7.2.0-SNAPSHOT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey, one question:
is it required to define both
pre
as well aspost
even if you do not do anything else than return the arguments like in your example withpost
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i can try removing them right now and let you know, but I had them to satisfy the typescript typings and show what was possible, not necessarily because they are needed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i don't see any default implementations of the pre/post methods, so they are most likely required for now, but we could easily add a wrapper that does default them or even a wrapper that makes middleware/configuration from a desired MIME media type since that's most of what we're after here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
update: you can skip the middleware altogether if you want to use the first supported content type which is
application/json-patch+json
, but for any other types you'll have to add it, but this is just a workaround for now, and the ergonomics will be greatly improved with config merging in the future :)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for explaining. I was just asking because I was curious :)
This is fine, especially as a workaround! 👍