Skip to content

Instantly share code, notes, and snippets.

@dennis-benzinger-hybris
Created November 15, 2021 10:05
Show Gist options
  • Save dennis-benzinger-hybris/c432d62568d8d029e056dac5ff9c308a to your computer and use it in GitHub Desktop.
Save dennis-benzinger-hybris/c432d62568d8d029e056dac5ff9c308a to your computer and use it in GitHub Desktop.
Kubernetes Java client bug 1978
import io.kubernetes.client.openapi.models.V1CustomResourceValidation;
import io.kubernetes.client.openapi.models.V1CustomResourceValidationBuilder;
import io.kubernetes.client.openapi.models.V1JSONSchemaPropsBuilder;
public class JavaClientBug1978 {
public static void main(String... args) {
V1CustomResourceValidation crdValidation = new V1CustomResourceValidationBuilder()
.withOpenAPIV3Schema(new V1JSONSchemaPropsBuilder()
.withType("object")
// Does not exist:
//.withXKubernetesPreserveUnknwonFields(true)
.build()
// Doesn't work because `withOpenAPIV3Schema` doesn't copy the field:
.xKubernetesPreserveUnknownFields(true))
.build();
// Only this workaround helps:
//crdValidation.getOpenAPIV3Schema().setxKubernetesPreserveUnknownFields(true);
// Should print `true` but prints `null` (except if you uncomment the workaround above):
System.out.println(crdValidation.getOpenAPIV3Schema().getxKubernetesPreserveUnknownFields());
}
}
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>k8s-java-client-bug-1978</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>io.kubernetes</groupId>
<artifactId>client-java-api</artifactId>
<version>14.0.0</version>
</dependency>
<dependency>
<groupId>io.kubernetes</groupId>
<artifactId>client-java-api-fluent</artifactId>
<version>14.0.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<archive>
<manifest>
<mainClass>JavaClientBug1978</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment