use of io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinition in project kubernetes-client by fabric8io.
the class ChildCRDTest method testCrd.
@Test
void testCrd() {
CustomResourceDefinition d = Serialization.unmarshal(getClass().getClassLoader().getResourceAsStream("META-INF/fabric8/children.acme.com-v1.yml"), CustomResourceDefinition.class);
assertNotNull(d);
assertEquals("Child", d.getSpec().getNames().getKind());
assertEquals("children", d.getSpec().getNames().getPlural());
assertEquals("Namespaced", d.getSpec().getScope());
assertTrue(d.getSpec().getVersions().stream().anyMatch(v -> v.getSubresources() != null));
}
use of io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinition in project kubernetes-client by fabric8io.
the class ZookeeperCustomResourceTest method testCrd.
@Test
void testCrd() {
CustomResourceDefinition d = Serialization.unmarshal(getClass().getClassLoader().getResourceAsStream("META-INF/fabric8/zookeepers.io.zookeeper-v1beta1.yml"), CustomResourceDefinition.class);
assertNotNull(d);
assertEquals("Zookeeper", d.getSpec().getNames().getKind());
assertEquals("zookeepers", d.getSpec().getNames().getPlural());
assertEquals("Namespaced", d.getSpec().getScope());
assertNotNull(d.getSpec().getSubresources());
assertEquals(".status.size", d.getSpec().getSubresources().getScale().getStatusReplicasPath());
assertEquals(".spec.size", d.getSpec().getSubresources().getScale().getSpecReplicasPath());
assertNotNull(d.getSpec().getSubresources().getStatus());
Optional<CustomResourceDefinitionVersion> v1 = d.getSpec().getVersions().stream().filter(v -> v.getName().equals("v1")).findFirst();
assertTrue(v1.isPresent());
v1.ifPresent(v -> {
// Let's check that version is marked as required
Object spec = v.getSchema().getOpenAPIV3Schema().getProperties().get("spec");
assertNotNull(spec);
JSONSchemaProps props = (JSONSchemaProps) spec;
List<String> required = props.getRequired();
assertTrue(required.contains("version"));
});
Optional<CustomResourceDefinitionVersion> v1alpha1 = d.getSpec().getVersions().stream().filter(v -> v.getName().equals("v1alpha1")).findFirst();
assertTrue(v1alpha1.isPresent());
v1.ifPresent(v -> {
// Let's check that version is marked as required
Object spec = v.getSchema().getOpenAPIV3Schema().getProperties().get("spec");
assertNotNull(spec);
JSONSchemaProps props = (JSONSchemaProps) spec;
List<String> required = props.getRequired();
assertTrue(required.contains("version"));
});
}
use of io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinition in project kubernetes-client by fabric8io.
the class CustomResourceV1Example method main.
@SuppressWarnings("java:S106")
public static void main(String... args) {
try (KubernetesClient kc = new KubernetesClientBuilder().build()) {
// @formatter:off
final CustomResourceDefinition crd = CustomResourceDefinitionContext.v1CRDFromCustomResourceType(Show.class).editSpec().editVersion(0).withNewSchema().withNewOpenAPIV3Schema().withTitle("Shows").withType("object").addToRequired("spec").addToProperties("spec", new JSONSchemaPropsBuilder().withType("object").addToProperties("name", new JSONSchemaPropsBuilder().withType("string").build()).addToProperties("score", new JSONSchemaPropsBuilder().withType("number").build()).build()).endOpenAPIV3Schema().endSchema().endVersion().endSpec().build();
// @formatter:on
kc.apiextensions().v1().customResourceDefinitions().createOrReplace(crd);
System.out.println("Created custom shows.example.com Kubernetes API");
final NonNamespaceOperation<Show, ShowList, Resource<Show>> shows = kc.customResources(Show.class, ShowList.class).inNamespace("default");
shows.list();
shows.createOrReplace(new Show("breaking-bad", new ShowSpec("Breaking Bad", 10)));
shows.createOrReplace(new Show("better-call-saul", new ShowSpec("Better call Saul", 8)));
shows.createOrReplace(new Show("the-wire", new ShowSpec("The Wire", 10)));
System.out.println("Added three shows");
shows.list().getItems().forEach(s -> System.out.printf(" - %s%n", s.getSpec().name));
final Show theWire = shows.withName("the-wire").fromServer().get();
System.out.printf("The Wire Score is: %s%n", theWire.getSpec().score);
}
}
use of io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinition in project kubernetes-client by fabric8io.
the class CRDLoadExample method main.
public static void main(String[] args) {
try (final KubernetesClient client = new KubernetesClientBuilder().build()) {
// List all Custom resources.
logger.info("Listing all current Custom Resource Definitions :");
CustomResourceDefinitionList crdList = client.apiextensions().v1beta1().customResourceDefinitions().list();
crdList.getItems().forEach(crd -> logger.info(crd.getMetadata().getName()));
// Creating a custom resource from yaml
CustomResourceDefinition aCustomResourceDefinition = client.apiextensions().v1beta1().customResourceDefinitions().load(CRDLoadExample.class.getResourceAsStream("/crd.yml")).get();
logger.info("Creating CRD...");
client.apiextensions().v1beta1().customResourceDefinitions().create(aCustomResourceDefinition);
logger.info("Updated Custom Resource Definitions: ");
client.apiextensions().v1beta1().customResourceDefinitions().list().getItems().forEach(crd -> logger.info(crd.getMetadata().getName()));
}
}
use of io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinition in project kubernetes-client by fabric8io.
the class ApprovalTest method testKeycloakCrd.
@Test
void testKeycloakCrd() {
// Arrange
CustomResourceDefinition crd = getCRD("keycloak-crd.yml");
// Act
List<WritableCRCompilationUnit> writables = runner.generate(crd, runner.getPackage("test.org"));
// Assert
assertEquals(1, writables.size());
assertThat(writables.size()).isEqualTo(1);
WritableCRCompilationUnit writable = writables.get(0);
List<String> underTest = new ArrayList<>();
List<GeneratorResult.ClassResult> crl = writable.getClassResults();
underTest.add(getJavaClass(crl, "Keycloak"));
underTest.add(getJavaClass(crl, "KeycloakSpec"));
underTest.add(getJavaClass(crl, "KeycloakStatus"));
Approvals.verifyAll("KeycloakJavaCr", underTest);
}
Aggregations