-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Unable to create a pod using example YAML InputStream with client >=6.4 #4873
Comments
@oreillymj : Does it work if you modify your code like this? if (pod_resource_inputstream!=null) {
Pod pod = client.pods().load(pod_resource_inputstream).get();
if (pod != null) {
client.pods().inNamespace("test").resource(pod).create();
}
} So you're saying that |
yes, I've gone back and tested. I changed my code to test for the existence of the pod before trying to create it as with older (working) versions of the client I was getting exceptions trying to create a pod that already existed in the namespace. |
Since last release You can learn more about this in the release notes:
You should migrate to use this: client.pods().inNamespace("test").create(podresource.item());
// Or better
client.load(pod_resource_inputstream).inNamespace("test").create() |
Tested some suggestions above with 6.4.1 Using this code to check for an existing pod, as suggested above...
... results in..... Getting beyond that error using a hard-coded name check for the pod......
Gives the following exception 2023-02-14 11:23:54 - createPodFromInputStream()-> no existing pod, so create one Testing the other create option is successful.
Any calls to .get() triggers an exception, even though the code is valid and compiles. Also the error message |
The suggestions from Rohan are NOT OK, they are based on the same assumptions as yours. We changed the default behavior of |
Just for clarification:
This doesn't work? It seems that there might be some problem while parsing your YAML. Could you share it so we can try and reproduce? |
I am using the valid yaml from your repo here https://github.com/fabric8io/kubernetes-client/blob/master/kubernetes-examples/src/main/resources/test-pod.yaml From your suggestions in #4873 This works, but is using a deprecated method To be clear, this does not work It triggers this error |
We definitely need to check that one since it should work |
I can confirm that it does work.
This is different from the exception you were initially encountering. You need ensure that the inputstream you are passing to load is valid - hasn't already been read from or closed. |
Ah okay, I found what i was doing wrong... So my earlier (non-working) code was reading the stream, And even though I'd commented out non working code, I had read the Inputstream once into podresource.
So even though I was no longer using podresource in my code
I couldn't re-use/reload the Inputstream variable as follows.
The example here no longer works. |
Yes the get method needs to be changed to item. We can use this issue to address that. |
…se up to date code (fabric8io#4873) + Replace deprecated method calls with updated method calls + Replace load(..).get() with load(..).item() calls Signed-off-by: Rohan Kumar <rohaan@redhat.com>
…se up to date code (fabric8io#4873) + Replace deprecated method calls with updated method calls + Replace load(..).get() with load(..).item() calls Signed-off-by: Rohan Kumar <rohaan@redhat.com>
…se up to date code (fabric8io#4873) + Replace deprecated method calls with updated method calls + Replace load(..).get() with load(..).item() calls Signed-off-by: Rohan Kumar <rohaan@redhat.com>
…se up to date code (fabric8io#4873) + Replace deprecated method calls with updated method calls + Replace load(..).get() with load(..).item() calls Signed-off-by: Rohan Kumar <rohaan@redhat.com>
…se up to date code (#4873) + Replace deprecated method calls with updated method calls + Replace load(..).get() with load(..).item() calls Signed-off-by: Rohan Kumar <rohaan@redhat.com>
Describe the bug
Using client 6.4.1
While trying to create a pod from an Inputstream, I get the error below.
2023-02-13 16:39:26 - createPodFromInputStream()-> got resource from Inputstream
Exception in thread "main" io.fabric8.kubernetes.client.KubernetesClientException: name not specified for an operation requiring one.
at io.fabric8.kubernetes.client.dsl.internal.BaseOperation.requireFromServer(BaseOperation.java:182)
at io.fabric8.kubernetes.client.dsl.internal.BaseOperation.get(BaseOperation.java:142)
at io.fabric8.kubernetes.client.dsl.internal.BaseOperation.get(BaseOperation.java:93)
at Main.createPodFromInputStream(Main.java:616)
The code is again based on the examples ( PodCreateYamlEquivalent ), down to the yaml file for the pod.
The "test" namespace exists and I have permission to create pods in it.
Fabric8 Kubernetes Client version
6.4.1
Steps to reproduce
Expected behavior
I expect the nginx pod to be created in the test namespace.
Runtime
Kubernetes (vanilla)
Kubernetes API Server version
1.25.3@latest
Environment
Linux
Fabric8 Kubernetes Client Logs
Additional context
ClusterRole for test namespace
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
namespace: test
name: api-reader-role
rules:
resources: ["services", "pods", "deployments", "namespaces"]
verbs: ["get", "watch", "list", "create", "update", "patch", "delete"]
The text was updated successfully, but these errors were encountered: