use of io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinition in project kubernetes-client by fabric8io.
the class ApprovalTest method testCrontabCrd.
@Test
void testCrontabCrd() {
// Arrange
CustomResourceDefinition crd = getCRD("crontab-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, "CronTab"));
underTest.add(getJavaClass(crl, "CronTabSpec"));
underTest.add(getJavaClass(crl, "CronTabStatus"));
Approvals.verifyAll("CrontabJavaCr", underTest);
}
use of io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinition in project kubernetes-client by fabric8io.
the class ApprovalTest method testJokeCrd.
@Test
void testJokeCrd() {
// Arrange
CustomResourceDefinition crd = getCRD("jokerequests-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, "JokeRequest"));
underTest.add(getJavaClass(crl, "JokeRequestSpec"));
underTest.add(getJavaClass(crl, "JokeRequestStatus"));
Approvals.verifyAll("JokeRequestJavaCr", underTest);
}
use of io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinition in project kubernetes-client by fabric8io.
the class CRGeneratorRunner method runOnSingleSource.
private void runOnSingleSource(File source, File basePath) {
try (FileInputStream fis = new FileInputStream(source)) {
List<HasMetadata> resources = new ArrayList<>();
Object deserialized = Serialization.unmarshal(fis, Collections.emptyMap());
if (deserialized instanceof List) {
resources.addAll((List<HasMetadata>) deserialized);
} else {
resources.add((CustomResourceDefinition) deserialized);
}
resources.parallelStream().forEach(resource -> {
if (resource.getKind().toLowerCase(Locale.ROOT).equals("customresourcedefinition")) {
CustomResourceDefinition crd = (CustomResourceDefinition) resource;
String pkg = getPackage(crd.getSpec().getGroup());
List<WritableCRCompilationUnit> writables = generate(crd, pkg);
writables.parallelStream().forEach(w -> w.writeAllJavaClasses(basePath, pkg));
} else {
LOGGER.warn("Not generating nothing for resource of kind: " + resource.getKind());
}
});
} catch (FileNotFoundException e) {
throw new JavaGeneratorException("File " + source.getAbsolutePath() + " not found", e);
} catch (IOException e) {
throw new JavaGeneratorException("Exception reading " + source.getAbsolutePath(), e);
}
}
use of io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinition in project kubernetes-client by fabric8io.
the class GenericResourceIT method testGenericCustomResourceWithoutMetadata.
@Test
public void testGenericCustomResourceWithoutMetadata() {
CustomResourceDefinition crd1 = client.apiextensions().v1().customResourceDefinitions().createOrReplace(createCRD());
assertThat(crd1).isNotNull();
Awaitility.await().atMost(1, TimeUnit.MINUTES).until(() -> client.getApiResources("examples.fabric8.io/v1") != null);
GenericKubernetesResource itest = new GenericKubernetesResource();
itest.setKind("Itest");
itest.setApiVersion("examples.fabric8.io/v1");
itest.setMetadata(new ObjectMetaBuilder().withName("my-itest").build());
NamespaceableResource<GenericKubernetesResource> resource = client.resource(itest);
GenericKubernetesResource result = resource.createOrReplace();
assertNotNull(result);
// ensure the namespace can be manipulated
client.namespaces().create(new NamespaceBuilder().withNewMetadata().withName("x").endMetadata().build());
result = resource.inNamespace("x").createOrReplace();
assertEquals("x", result.getMetadata().getNamespace());
// ensure it can be loaded as a list
List<HasMetadata> created = client.load(new ByteArrayInputStream(Serialization.asYaml(itest).getBytes(StandardCharsets.UTF_8))).createOrReplace();
assertEquals(1, created.size());
}
use of io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinition in project kubernetes-client by fabric8io.
the class CustomResourceDefinitionIT method update.
@Test
public void update() {
// When
final CustomResourceDefinition result = client.apiextensions().v1().customResourceDefinitions().withName(name).edit(c -> new CustomResourceDefinitionBuilder(c).editSpec().editOrNewNames().addToShortNames("its").endNames().endSpec().build());
// Then
assertThat(result.getSpec().getNames().getShortNames()).containsExactlyInAnyOrder("its");
}
Aggregations