Closed danielfree closed 6 years ago
seems like something related with getTopLevelClasses() see https://github.com/google/guava/issues/2152 almost the same scenario as the next to last comment.
This was fixed by this PR:
https://github.com/kubernetes-client/java/pull/314
You can manually call the static method on the Yaml
object to do the right class-loading, or you can try updating to the 3.0.0-beta1
library...
@brendandburns The issue is solved after upgrading to 3.0.0-beta2, however it's only working when packaged as war and deployed in tomcat, but still not working when packaged as single jar and run as java -jar. For now I would just stick to war/tomcat. Thanks.
@danielfree, in your Spring Boot project you probably package your dependency JARs into the main JAR of your application (JAR in JAR) and use the Spring LaunchedURLClassLoader. The problem is that Guava doesn't understand JARs in JARs.
See https://github.com/spring-projects/spring-boot/issues/5338#issuecomment-192327258 for an alternative.
@danielfree, the easiest solution I've found is to tell Spring Boot that the io.kubernetes:client-java-api
JAR has to be unpacked from the main JAR at runtime (only the JAR, not the individual .class
files).
Here's an excerpt from my pom.xml
:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<!-- Enable io.kubernetes:client-java to find its model classes. -->
<requiresUnpack>
<dependency>
<groupId>io.kubernetes</groupId>
<artifactId>client-java-api</artifactId>
</dependency>
</requiresUnpack>
</configuration>
</plugin>
</plugins>
</build>
I encountered this problem in 6.0.1, and running strpingboot app in local IDE is normal ,but run in docker envrioment is found error.
my code:
obj = Yaml.load(readJarFile("templates/k8s/application/deployment.yaml"));
public String readJarFile(String classPath) throws IOException {
ClassPathResource resource = new ClassPathResource(classPath);
byte[] binaryData = FileCopyUtils.copyToByteArray(resource.getInputStream());
String yamlStr = new String(binaryData, StandardCharsets.UTF_8);
log.debug("[loadTemplate]:{},requestId -> {}",yamlStr,ServiceThreadLocal.getRequestId());
return yamlStr;
//return resource.getInputStream();
}
error :
java.io.IOException: Unknown apiVersionKind: apps/v1/Deployment known kinds are: {}
at io.kubernetes.client.util.Yaml.modelMapper(Yaml.java:491)
at io.kubernetes.client.util.Yaml.load(Yaml.java:185)
at io.kubernetes.client.util.Yaml.load(Yaml.java:162)
at )
@brendandburns
@brendandburns The issue is solved after upgrading to 3.0.0-beta2, however it's only working when packaged as war and deployed in tomcat, but still not working when packaged as single jar and run as java -jar. For now I would just stick to war/tomcat. Thanks.
@brendandburns The issue is solved after upgrading to 3.0.0-beta2, however it's only working when packaged as war and deployed in tomcat, but still not working when packaged as single jar and run as java -jar. For now I would just stick to war/tomcat. Thanks.
@danielfree
I found this error in 6.0.1
@danielfree, the easiest solution I've found is to tell Spring Boot that the
io.kubernetes:client-java-api
JAR has to be unpacked from the main JAR at runtime (only the JAR, not the individual.class
files).Here's an excerpt from my
pom.xml
:<build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <!-- Enable io.kubernetes:client-java to find its model classes. --> <requiresUnpack> <dependency> <groupId>io.kubernetes</groupId> <artifactId>client-java-api</artifactId> </dependency> </requiresUnpack> </configuration> </plugin> </plugins> </build>
The solution is effective !!
pom.xml :
I load a yml via
which runs fine in IntelliJ, but after package as spring boot single jar and run with java -jar, it gives the following error:
java.io.IOException: Unknown apiVersionKind: apps/v1beta1/Deployment known kinds are: {}
and it seems like the Yaml doesn't load anything into Map<String, Class<?>> classes