Skip to content

Instantly share code, notes, and snippets.

@dennis-benzinger-hybris
Created October 15, 2021 14:52
Show Gist options
  • Save dennis-benzinger-hybris/270b996c1ba2104467a29b373624c817 to your computer and use it in GitHub Desktop.
Save dennis-benzinger-hybris/270b996c1ba2104467a29b373624c817 to your computer and use it in GitHub Desktop.
Issue #1930 in kubernetes-client/java: Yaml.load fails for custom resource definition with x-kubernetes-preserve-unknown-fields
import java.io.IOException;
import io.kubernetes.client.util.Yaml;
public class JavaClientBug {
public static void main(String... args) throws IOException {
Yaml.load("---\n" +
"apiVersion: apiextensions.k8s.io/v1\n" +
"kind: CustomResourceDefinition\n" +
"metadata:\n" +
" name: crd.java.client.bug\n" +
"spec:\n" +
" group: java.client.bug\n" +
" versions:\n" +
" - name: v1alpha1\n" +
" storage: true\n" +
" served: true\n" +
" schema:\n" +
" openAPIV3Schema:\n" +
" type: object\n" +
" x-kubernetes-preserve-unknown-fields: true\n" +
// This works but is incompatible with other K8s clients:
//" xKubernetesPreserveUnknownFields: true\n" +
" names:\n" +
" kind: myCrd\n" +
" listKind: myCrdList\n" +
" plural: myCrds\n" +
" shortNames:\n" +
" - myCrd\n" +
" singular: myCrd\n" +
" scope: Namespaced\n");
}
}
<?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>java-client-bug</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>io.kubernetes</groupId>
<artifactId>client-java</artifactId>
<version>11.0.2</version>
</dependency>
</dependencies>
</project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment