-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Fix header handling for resource create requests #56
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
Closed
Closed
Changes from all commits
Commits
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
62 changes: 62 additions & 0 deletions
62
examples/src/main/java/io/kubernetes/client/examples/CreatePodExample.java
This file contains hidden or 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,62 @@ | ||
| /* | ||
| 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 io.kubernetes.client.examples; | ||
|
|
||
| import io.kubernetes.client.ApiClient; | ||
| import io.kubernetes.client.ApiException; | ||
| import io.kubernetes.client.Configuration; | ||
| import io.kubernetes.client.apis.CoreV1Api; | ||
| import io.kubernetes.client.models.V1Container; | ||
| import io.kubernetes.client.models.V1ObjectMeta; | ||
| import io.kubernetes.client.models.V1Pod; | ||
| import io.kubernetes.client.models.V1PodSpec; | ||
| import io.kubernetes.client.util.Config; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.Collections; | ||
|
|
||
| /** | ||
| * A simple example of how to use the Java API | ||
| * | ||
| * Easiest way to run this: | ||
| * mvn exec:java -Dexec.mainClass="io.kubernetes.client.examples.CreatePodExample" | ||
| * | ||
| * From inside $REPO_DIR/kubernetes | ||
| */ | ||
| public class CreatePodExample { | ||
| public static void main(String[] args) throws IOException, ApiException{ | ||
| ApiClient client = Config.defaultClient(); | ||
| Configuration.setDefaultApiClient(client); | ||
| String namespace = "default"; | ||
|
|
||
| V1Pod pod = new V1Pod(); | ||
| pod.setApiVersion("v1"); | ||
|
|
||
| V1ObjectMeta objectMeta = new V1ObjectMeta(); | ||
| objectMeta.setName("demo-pod-nginx"); | ||
| objectMeta.setNamespace(namespace); | ||
|
|
||
| pod.setMetadata(objectMeta); | ||
|
|
||
| V1PodSpec podSpec = new V1PodSpec(); | ||
| V1Container container = new V1Container(); | ||
| container.setImage("nginx"); | ||
| container.setName("nginx"); | ||
|
|
||
| podSpec.setContainers(Collections.singletonList(container)); | ||
| pod.setSpec(podSpec); | ||
|
|
||
| CoreV1Api api = new CoreV1Api(); | ||
| api.createNamespacedPod(namespace, pod, "false"); | ||
| } | ||
| } |
This file contains hidden or 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
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.
I don't think we can do this, we'll need to make this change in the upstream swagger-codegen and I don't think we can land it there.
The right thing to do is to fix the Kubernetes swagger to not have this.
Uh oh!
There was an error while loading. Please reload this page.
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.
We did this for python client. swagger-api/swagger-codegen#4152
I think it is a reasonable thing to do because swagger client prefers json and when content type is
*/*, that includes json.I also agree with this regardless of swagger-codegen fix.
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.
My read of the Kubernetes swagger was that it was declaring that it, as a server, accepts anything (
*/*). If this is true, it's up to the client to decide what it wants to send, and requires either swagger-codegen to be smarter about assigning content types or us as consumers of the generated code to be explicit in what we are sending. But of course, if Kubernetes only accepts json & yaml for example then the right fix is in the Kubernetes swagger.An alternative to modifying ApiClient in place is to subclass it and override this method to avoid having our changes overwritten by running codegen. Although - when I tested this against the autoupdate script it left my changes in place, so I'm not sure what's going on there.
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.
Ok, let's due the PR in upstream swagger-codegen. They've been great about quick turnaround in the past. Once that is merged, I'm happy to merge this PR.
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.
(and let me know if you need help with the PR, I've done a bunch of them myself)
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.
Sounds good.
And thanks - I've done one myself now too so this shouldn't be too bad.