kubernetes-client / java

Official Java client library for kubernetes
http://kubernetes.io/
Apache License 2.0
3.54k stars 1.88k forks source link

Yaml.load() doesn't appear to be supported in reflective class-loader environment #509

Closed johnlabarge closed 5 years ago

johnlabarge commented 5 years ago

See https://gist.github.com/johnlabarge/00105981f156811d612bb5aadce7dbfc

The output trying to run this example is: java.io.IOException: Missing kind in YAML file! at io.kubernetes.client.util.Yaml.modelMapper (Yaml.java:461) at io.kubernetes.client.util.Yaml.load (Yaml.java:184) at io.kubernetes.client.util.Yaml.load (Yaml.java:172) at io.kubernetes.client.examples.YamlExample.main (YamlExample.java:56) at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke (Method.java:498) at org.codehaus.mojo.exec.ExecJavaMojo$1.run (ExecJavaMojo.java:282) at java.lang.Thread.run (Thread.java:748)

This is because the generated pod file doesn't have an API entry. But even if it does, it will be lower case and not match the upper case format so that when it loads from the YAML there is no matching api. I'll supply another gist.

johnlabarge commented 5 years ago

https://gist.github.com/johnlabarge/2f533fa29605c8f0d7ea7154ff4397cd

brendandburns commented 5 years ago

you need a .withKind("pod") I think, I'll update the example.

brendandburns commented 5 years ago

Here's the unit test that validates that load works correctly.

https://github.com/kubernetes-client/java/blob/master/util/src/test/java/io/kubernetes/client/util/YamlTest.java#L85

johnlabarge commented 5 years ago

So this is the issue. I'm trying to use this client as part of a Jenkins plugin that is loaded via reflection. This causes some strange behavior with static initialization method initModelMap which expects the model classes to be available via classloader (imagine that). Still tracking down exact cause and trying to figure out a workaround.

johnlabarge commented 5 years ago

Duplicate of #474