From f6c56d51508237cc41dfa143abe2c922d878ea44 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 25 Apr 2024 06:28:45 +0200 Subject: [PATCH 01/11] chore(deps): bump org.apache.maven.plugins:maven-shade-plugin Bumps [org.apache.maven.plugins:maven-shade-plugin](https://github.com/apache/maven-shade-plugin) from 3.5.2 to 3.5.3. - [Release notes](https://github.com/apache/maven-shade-plugin/releases) - [Commits](https://github.com/apache/maven-shade-plugin/compare/maven-shade-plugin-3.5.2...maven-shade-plugin-3.5.3) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-shade-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- java-generator/cli/pom.xml | 2 +- pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/java-generator/cli/pom.xml b/java-generator/cli/pom.xml index a2597e6f0d6..85c7363777f 100644 --- a/java-generator/cli/pom.xml +++ b/java-generator/cli/pom.xml @@ -80,7 +80,7 @@ org.apache.maven.plugins maven-shade-plugin - 3.5.2 + 3.5.3 package diff --git a/pom.xml b/pom.xml index 602b62a18e5..5ba12d8e1cc 100644 --- a/pom.xml +++ b/pom.xml @@ -159,7 +159,7 @@ 3.2.4 3.1.0 3.6.1 - 3.5.2 + 3.5.3 3.1.1 3.6.1 3.12.0 From 8a19f1f47b16522cd1d9e8b617052f56cef1cd5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bernhard=20Str=C3=A4hle?= Date: Thu, 25 Apr 2024 16:04:53 +0200 Subject: [PATCH 02/11] fix(crd-generator): Sort required properties to ensure deterministic output --- CHANGELOG.md | 1 + .../fabric8/crd/generator/AbstractJsonSchema.java | 6 +++++- .../k8svalidations.samples.fabric8.io-v1.yml | 14 +++++++------- .../k8svalidations.samples.fabric8.io-v1beta1.yml | 14 +++++++------- 4 files changed, 20 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d7f12171c29..e788acd514c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ * Fix #5878: (java-generator) Update documentation to include dependencies * Fix #5867: (crd-generator) Imply schemaFrom via JsonFormat shape (SchemaFrom takes precedence) * Fix #5867: (java-generator) Add JsonFormat shape to date-time +* Fix #5954: (crd-generator) Sort required properties to ensure deterministic output #### Dependency Upgrade diff --git a/crd-generator/api/src/main/java/io/fabric8/crd/generator/AbstractJsonSchema.java b/crd-generator/api/src/main/java/io/fabric8/crd/generator/AbstractJsonSchema.java index 878d016b0b2..dc2e3d88ef5 100644 --- a/crd-generator/api/src/main/java/io/fabric8/crd/generator/AbstractJsonSchema.java +++ b/crd-generator/api/src/main/java/io/fabric8/crd/generator/AbstractJsonSchema.java @@ -400,7 +400,11 @@ private T internalFromImpl(TypeDef definition, LinkedHashMap vis .collect(Collectors.toList()); swaps.throwIfUnmatchedSwaps(); - return build(builder, required, validationRules, preserveUnknownFields); + + List sortedRequiredProperties = required.stream().sorted() + .collect(Collectors.toList()); + + return build(builder, sortedRequiredProperties, validationRules, preserveUnknownFields); } private Map indexPotentialAccessors(TypeDef definition) { diff --git a/crd-generator/api/src/test/resources/k8svalidations.samples.fabric8.io-v1.yml b/crd-generator/api/src/test/resources/k8svalidations.samples.fabric8.io-v1.yml index 5e147ccdcbd..0ae072eb120 100644 --- a/crd-generator/api/src/test/resources/k8svalidations.samples.fabric8.io-v1.yml +++ b/crd-generator/api/src/test/resources/k8svalidations.samples.fabric8.io-v1.yml @@ -123,18 +123,18 @@ spec: x-kubernetes-validations: - rule: self.startsWith('simple-') required: - - minReplicas - - onAttributeAndGetter - - replicas - deepLevel1 - - onAttributeAndClass - - simple + - maxReplicas + - minReplicas - multiple + - namePrefix - onAbstractClass + - onAttributeAndClass + - onAttributeAndGetter - onGetter - - maxReplicas - priority - - namePrefix + - replicas + - simple type: object x-kubernetes-validations: - fieldPath: .replicas diff --git a/crd-generator/api/src/test/resources/k8svalidations.samples.fabric8.io-v1beta1.yml b/crd-generator/api/src/test/resources/k8svalidations.samples.fabric8.io-v1beta1.yml index 868038a1294..ebfc174dd2d 100644 --- a/crd-generator/api/src/test/resources/k8svalidations.samples.fabric8.io-v1beta1.yml +++ b/crd-generator/api/src/test/resources/k8svalidations.samples.fabric8.io-v1beta1.yml @@ -123,18 +123,18 @@ spec: x-kubernetes-validations: - rule: self.startsWith('simple-') required: - - minReplicas - - onAttributeAndGetter - - replicas - deepLevel1 - - onAttributeAndClass - - simple + - maxReplicas + - minReplicas - multiple + - namePrefix - onAbstractClass + - onAttributeAndClass + - onAttributeAndGetter - onGetter - - maxReplicas - priority - - namePrefix + - replicas + - simple type: object x-kubernetes-validations: - fieldPath: .replicas From e6a5ebd502d70c5200d9fddcbabf670a23f9c8f7 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 26 Apr 2024 20:50:59 +0200 Subject: [PATCH 03/11] chore(deps-dev): bump org.bouncycastle:bc-fips from 1.0.2.4 to 1.0.2.5 Bumps org.bouncycastle:bc-fips from 1.0.2.4 to 1.0.2.5. --- updated-dependencies: - dependency-name: org.bouncycastle:bc-fips dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 5ba12d8e1cc..53cb5198cea 100644 --- a/pom.xml +++ b/pom.xml @@ -129,7 +129,7 @@ 2.7 2.2 1.78.1 - 1.0.2.4 + 1.0.2.5 1.0.7 1.26.1 2.16.1 From ee903c692f9bb44a0a337073b98750157e5c08e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bernhard=20Str=C3=A4hle?= Date: Wed, 24 Apr 2024 00:56:03 +0200 Subject: [PATCH 04/11] chore(crd-generator): Add approval tests for crd-generator --- crd-generator/api/pom.xml | 7 +- ...t.java => MultipleStoredVersionsTest.java} | 45 +-- .../AbstractCRDGeneratorApprovalTest.java | 143 +++++++++ .../CRDGeneratorApprovalNamer.java | 82 +++++ .../approvaltests/PackageSettings.java | 32 ++ ...otateds.samples.fabric8.io.v1.approved.yml | 78 +++++ ...ds.samples.fabric8.io.v1beta1.approved.yml | 78 +++++ .../annotated/AnnotatedApprovalTest.java | 34 +++ .../annotated/api/Annotated.java | 26 ++ .../annotated/api/AnnotatedSpec.java | 150 +++++++++ ...exkinds.samples.fabric8.io.v1.approved.yml | 199 ++++++++++++ ...ds.samples.fabric8.io.v1beta1.approved.yml | 199 ++++++++++++ .../complex/ComplexApprovalTest.java | 33 ++ .../approvaltests/complex/api/Complex.java | 28 ++ .../complex/api/ComplexSpec.java | 79 +++++ .../complex/api/ComplexStatus.java | 61 ++++ .../complex/api/ServiceConfiguration.java | 53 ++++ .../complex/api/StatefulSetConfiguration.java | 52 ++++ .../complex/api/k8s/ObjectMeta.java | 232 ++++++++++++++ .../complex/api/k8s/ServiceSpec.java | 286 ++++++++++++++++++ .../complex/api/k8s/StatefulSetSpec.java | 126 ++++++++ ...children.sample.fabric8.io.v1.approved.yml | 41 +++ ...ren.sample.fabric8.io.v1beta1.approved.yml | 41 +++ .../inherited/InheritedApprovalTest.java | 33 ++ .../approvaltests/inherited/api/Base.java | 25 ++ .../approvaltests/inherited/api/BaseSpec.java | 28 ++ .../inherited/api/BaseStatus.java | 23 ++ .../approvaltests/inherited/api/Child.java | 26 ++ .../inherited/api/ChildSpec.java | 24 ++ .../inherited/api/ChildStatus.java | 23 ++ ...ingjsons.sample.fabric8.io.v1.approved.yml | 38 +++ ...ons.sample.fabric8.io.v1beta1.approved.yml | 38 +++ .../approvaltests/json/JsonApprovalTest.java | 33 ++ .../json/api/ContainingJson.java | 26 ++ .../json/api/ContainingJsonSpec.java | 40 +++ .../generator/approvaltests/json/api/Foo.java | 38 +++ .../K8sValidationApprovalTest.java | 34 +++ ...dations.samples.fabric8.io.v1.approved.yml | 145 +++++++++ ...ns.samples.fabric8.io.v1beta1.approved.yml | 145 +++++++++ .../k8svalidation/api/K8sValidation.java | 35 +++ .../k8svalidation/api/K8sValidationSpec.java | 117 +++++++ .../api/K8sValidationStatus.java | 20 ++ ...ningmaps.sample.fabric8.io.v1.approved.yml | 85 ++++++ ...aps.sample.fabric8.io.v1beta1.approved.yml | 85 ++++++ .../approvaltests/map/MapApprovalTest.java | 33 ++ .../approvaltests/map/api/ContainingMaps.java | 34 +++ .../map/api/ContainingMapsSpec.java | 64 ++++ .../MultipleVersionsApprovalTest.java | 35 +++ ...ultiples.sample.fabric8.io.v1.approved.yml | 42 +++ ...les.sample.fabric8.io.v1beta1.approved.yml | 42 +++ .../multipleversions/api/v1/Multiple.java | 25 ++ .../api/v1/MultipleSpec.java} | 10 +- .../multipleversions/api/v2/Multiple.java | 25 ++ .../multipleversions/api/v2/MultipleSpec.java | 24 ++ .../nocyclic/NoCyclicApprovalTest.java | 33 ++ ...ocyclics.sample.fabric8.io.v1.approved.yml | 51 ++++ ...ics.sample.fabric8.io.v1beta1.approved.yml | 51 ++++ .../approvaltests/nocyclic/api/NoCyclic.java | 27 ++ .../nocyclic/api/NoCyclicSpec.java | 21 ++ .../nocyclic/api/NoCyclicStatus.java | 21 ++ .../approvaltests/nocyclic/api/Ref.java | 27 ++ pom.xml | 2 + 62 files changed, 3707 insertions(+), 26 deletions(-) rename crd-generator/api/src/test/java/io/fabric8/crd/generator/{CRDGeneratorExamplesTest.java => MultipleStoredVersionsTest.java} (54%) create mode 100644 crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/AbstractCRDGeneratorApprovalTest.java create mode 100644 crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalNamer.java create mode 100644 crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/PackageSettings.java create mode 100644 crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/annotated/AnnotatedApprovalTest.annotateds.samples.fabric8.io.v1.approved.yml create mode 100644 crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/annotated/AnnotatedApprovalTest.annotateds.samples.fabric8.io.v1beta1.approved.yml create mode 100644 crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/annotated/AnnotatedApprovalTest.java create mode 100644 crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/annotated/api/Annotated.java create mode 100644 crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/annotated/api/AnnotatedSpec.java create mode 100644 crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/ComplexApprovalTest.complexkinds.samples.fabric8.io.v1.approved.yml create mode 100644 crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/ComplexApprovalTest.complexkinds.samples.fabric8.io.v1beta1.approved.yml create mode 100644 crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/ComplexApprovalTest.java create mode 100644 crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/api/Complex.java create mode 100644 crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/api/ComplexSpec.java create mode 100644 crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/api/ComplexStatus.java create mode 100644 crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/api/ServiceConfiguration.java create mode 100644 crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/api/StatefulSetConfiguration.java create mode 100644 crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/api/k8s/ObjectMeta.java create mode 100644 crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/api/k8s/ServiceSpec.java create mode 100644 crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/api/k8s/StatefulSetSpec.java create mode 100644 crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/inherited/InheritedApprovalTest.children.sample.fabric8.io.v1.approved.yml create mode 100644 crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/inherited/InheritedApprovalTest.children.sample.fabric8.io.v1beta1.approved.yml create mode 100644 crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/inherited/InheritedApprovalTest.java create mode 100644 crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/inherited/api/Base.java create mode 100644 crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/inherited/api/BaseSpec.java create mode 100644 crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/inherited/api/BaseStatus.java create mode 100644 crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/inherited/api/Child.java create mode 100644 crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/inherited/api/ChildSpec.java create mode 100644 crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/inherited/api/ChildStatus.java create mode 100644 crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/json/JsonApprovalTest.containingjsons.sample.fabric8.io.v1.approved.yml create mode 100644 crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/json/JsonApprovalTest.containingjsons.sample.fabric8.io.v1beta1.approved.yml create mode 100644 crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/json/JsonApprovalTest.java create mode 100644 crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/json/api/ContainingJson.java create mode 100644 crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/json/api/ContainingJsonSpec.java create mode 100644 crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/json/api/Foo.java create mode 100644 crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/k8svalidation/K8sValidationApprovalTest.java create mode 100644 crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/k8svalidation/K8sValidationApprovalTest.k8svalidations.samples.fabric8.io.v1.approved.yml create mode 100644 crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/k8svalidation/K8sValidationApprovalTest.k8svalidations.samples.fabric8.io.v1beta1.approved.yml create mode 100644 crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/k8svalidation/api/K8sValidation.java create mode 100644 crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/k8svalidation/api/K8sValidationSpec.java create mode 100644 crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/k8svalidation/api/K8sValidationStatus.java create mode 100644 crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/map/MapApprovalTest.containingmaps.sample.fabric8.io.v1.approved.yml create mode 100644 crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/map/MapApprovalTest.containingmaps.sample.fabric8.io.v1beta1.approved.yml create mode 100644 crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/map/MapApprovalTest.java create mode 100644 crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/map/api/ContainingMaps.java create mode 100644 crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/map/api/ContainingMapsSpec.java create mode 100644 crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/multipleversions/MultipleVersionsApprovalTest.java create mode 100644 crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/multipleversions/MultipleVersionsApprovalTest.multiples.sample.fabric8.io.v1.approved.yml create mode 100644 crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/multipleversions/MultipleVersionsApprovalTest.multiples.sample.fabric8.io.v1beta1.approved.yml create mode 100644 crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/multipleversions/api/v1/Multiple.java rename crd-generator/api/src/test/java/io/fabric8/crd/generator/{ParallelCRDGeneratorExamplesTest.java => approvaltests/multipleversions/api/v1/MultipleSpec.java} (75%) create mode 100644 crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/multipleversions/api/v2/Multiple.java create mode 100644 crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/multipleversions/api/v2/MultipleSpec.java create mode 100644 crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/nocyclic/NoCyclicApprovalTest.java create mode 100644 crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/nocyclic/NoCyclicApprovalTest.nocyclics.sample.fabric8.io.v1.approved.yml create mode 100644 crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/nocyclic/NoCyclicApprovalTest.nocyclics.sample.fabric8.io.v1beta1.approved.yml create mode 100644 crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/nocyclic/api/NoCyclic.java create mode 100644 crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/nocyclic/api/NoCyclicSpec.java create mode 100644 crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/nocyclic/api/NoCyclicStatus.java create mode 100644 crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/nocyclic/api/Ref.java diff --git a/crd-generator/api/pom.xml b/crd-generator/api/pom.xml index 49574461d2f..280393fa40e 100644 --- a/crd-generator/api/pom.xml +++ b/crd-generator/api/pom.xml @@ -35,7 +35,7 @@ kubernetes-client-api compile - + com.fasterxml.jackson.module jackson-module-jsonSchema @@ -82,6 +82,11 @@ ${slf4j.version} test + + com.approvaltests + approvaltests + test + javax.validation validation-api diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/CRDGeneratorExamplesTest.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/MultipleStoredVersionsTest.java similarity index 54% rename from crd-generator/api/src/test/java/io/fabric8/crd/generator/CRDGeneratorExamplesTest.java rename to crd-generator/api/src/test/java/io/fabric8/crd/generator/MultipleStoredVersionsTest.java index 51a050b4aba..ef0adf3ef3a 100644 --- a/crd-generator/api/src/test/java/io/fabric8/crd/generator/CRDGeneratorExamplesTest.java +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/MultipleStoredVersionsTest.java @@ -15,27 +15,18 @@ */ package io.fabric8.crd.generator; -import io.fabric8.crd.example.k8svalidation.K8sValidation; import io.fabric8.crd.example.multiple.v2.MultipleSpec; import io.fabric8.kubernetes.client.CustomResource; import io.fabric8.kubernetes.model.annotation.Group; import io.fabric8.kubernetes.model.annotation.Version; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; -import java.io.IOException; +import java.io.File; -import static io.fabric8.crd.generator.CRDGeneratorAssertions.assertCRDOutputEquals; import static org.junit.jupiter.api.Assertions.assertThrows; -class CRDGeneratorExamplesTest { - - protected boolean parallelCRDGeneration; - - @Test - void multiple() throws IOException { - assertCRDOutputEquals(newCRDGenerator(), - io.fabric8.crd.example.multiple.v1.Multiple.class, io.fabric8.crd.example.multiple.v2.Multiple.class); - } +class MultipleStoredVersionsTest { @Group("sample.fabric8.io") @Version(value = "v3") @@ -43,20 +34,32 @@ public static class Multiple extends CustomResource { } @Test - void multipleStorage_thenFail() { - CRDGenerator crdGenerator = newCRDGenerator(); - assertThrows(IllegalStateException.class, () -> assertCRDOutputEquals(crdGenerator, - io.fabric8.crd.example.multiple.v2.Multiple.class, Multiple.class)); + void generateV1_expectException(@TempDir File tmpDir) { + test("v1", false, tmpDir); + } + + @Test + void generateV1beta1_expectException(@TempDir File tmpDir) { + test("v1beta1", false, tmpDir); } @Test - void k8sValidation() throws IOException { - assertCRDOutputEquals(newCRDGenerator(), K8sValidation.class); + void generateV1Parallel_expectException(@TempDir File tmpDir) { + test("v1", true, tmpDir); } - private CRDGenerator newCRDGenerator() { - return new CRDGenerator() - .withParallelGenerationEnabled(parallelCRDGeneration); + @Test + void generateV1beta1Parallel_expectException(@TempDir File tmpDir) { + test("v1beta1", true, tmpDir); } + private void test(String crdVersion, boolean parallel, File tmpDir) { + final CRDGenerator crdGenerator = new CRDGenerator() + .inOutputDir(tmpDir) + .withParallelGenerationEnabled(parallel) + .forCRDVersions(crdVersion) + .customResourceClasses(io.fabric8.crd.example.multiple.v2.Multiple.class, Multiple.class); + + assertThrows(IllegalStateException.class, crdGenerator::generate); + } } diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/AbstractCRDGeneratorApprovalTest.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/AbstractCRDGeneratorApprovalTest.java new file mode 100644 index 00000000000..16dfb0fc4e7 --- /dev/null +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/AbstractCRDGeneratorApprovalTest.java @@ -0,0 +1,143 @@ +package io.fabric8.crd.generator.approvaltests; + +/* + * Copyright (C) 2015 Red Hat, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import io.fabric8.crd.generator.CRDGenerationInfo; +import io.fabric8.crd.generator.CRDGenerator; +import io.fabric8.crd.generator.CRDInfo; +import io.fabric8.kubernetes.client.CustomResource; +import org.approvaltests.Approvals; +import org.approvaltests.approvers.ApprovalApprover; +import org.approvaltests.approvers.FileApprover; +import org.approvaltests.core.Options; +import org.approvaltests.namer.ApprovalNamer; +import org.approvaltests.writers.ApprovalTextWriter; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; + +import java.io.BufferedReader; +import java.io.File; +import java.io.IOException; +import java.io.InputStreamReader; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Comparator; +import java.util.Map; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +public abstract class AbstractCRDGeneratorApprovalTest { + + private static final String[] CRD_VERSIONS = new String[] { + "v1", "v1beta1" + }; + + protected abstract Class>[] crClasses(); + + protected abstract String[] expectedCRDs(); + + @BeforeAll + public void init() { + // Allow using the same approval files for this class multiple times (required for parallel testing) + String className = getClass().getName().replace('.', File.separatorChar); + FileApprover.tracker.addAllowedDuplicates(f -> f.contains(className)); + } + + @Test + public void test() { + test(false); + } + + @Test + public void testParallel() { + test(true); + } + + public void test(boolean parallel) { + Class>[] crClasses = crClasses(); + assertNotNull(crClasses); + assertTrue(crClasses.length > 0); + + final File outputDir; + try { + outputDir = Files.createTempDirectory("crd-").toFile(); + } catch (IOException e) { + fail("Could not create temp directory", e); + throw new RuntimeException(e); + } + + // generate actual CRDs + final CRDGenerationInfo crdGenerationInfo = new CRDGenerator() + .withParallelGenerationEnabled(parallel) + .inOutputDir(outputDir) + .customResourceClasses(crClasses) + .forCRDVersions(CRD_VERSIONS) + .detailedGenerate(); + + for (String crdName : expectedCRDs()) { + Map> crdDetails = crdGenerationInfo.getCRDDetailsPerNameAndVersion(); + Map crdInfos = crdDetails.get(crdName); + assertNotNull(crdInfos, "Could not find expected CRD " + crdName + + " in results. Found instead: " + crdDetails.keySet()); + for (String crdVersion : CRD_VERSIONS) { + CRDInfo crdInfo = crdInfos.get(crdVersion); + final File actualCRDFile = new File(crdInfo.getFilePath()); + String crdFileContent = readFile(actualCRDFile); + verify(crdName, crdVersion, crdFileContent); + } + } + + // only delete the generated files if the test is successful + deleteDirectory(outputDir); + } + + private void verify(String crdName, String crdVersion, String crdFileContent) { + ApprovalTextWriter writer = new ApprovalTextWriter(crdFileContent, new Options() + .forFile().withExtension(".yml")); + ApprovalNamer approvalNamer = new CRDGeneratorApprovalNamer(AbstractCRDGeneratorApprovalTest.class, getClass()) + .addAdditionalInformation(crdName) + .addAdditionalInformation(crdVersion); + ApprovalApprover approver = new FileApprover(writer, approvalNamer); + Approvals.verify(approver); + } + + private String readFile(File file) { + try { + return new BufferedReader(new InputStreamReader(Files.newInputStream(file.toPath()))) + .lines().collect(Collectors.joining("\n")); + } catch (IOException e) { + fail(e); + throw new RuntimeException(e); + } + } + + private void deleteDirectory(File dir) { + try (Stream fileStream = Files.walk(dir.toPath())) { + fileStream.sorted(Comparator.reverseOrder()) + .map(Path::toFile) + .forEach(File::delete); + } catch (IOException e) { + fail("Could not delete output directory", e); + } + } +} diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalNamer.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalNamer.java new file mode 100644 index 00000000000..04885a50f98 --- /dev/null +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalNamer.java @@ -0,0 +1,82 @@ +/* + * Copyright (C) 2015 Red Hat, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.fabric8.crd.generator.approvaltests; + +import com.spun.util.tests.StackTraceReflectionResult; +import com.spun.util.tests.TestUtils; +import org.approvaltests.namer.ApprovalNamer; +import org.approvaltests.namer.AttributeStackSelector; +import org.approvaltests.namer.NamerFactory; +import org.approvaltests.writers.Writer; + +import java.io.File; + +class CRDGeneratorApprovalNamer implements ApprovalNamer { + + private final String implementationClassName; + private final String baseDirectory; + private final String additionalInformation; + + public CRDGeneratorApprovalNamer(Class abstractClass, Class implementationClass) { + StackTraceReflectionResult info = TestUtils.getCurrentFileForMethod(new AttributeStackSelector()); + additionalInformation = NamerFactory.getAndClearAdditionalInformation(); + + String abstractClassPath = abstractClass.getPackage().getName().replace('.', File.separatorChar); + String implementationClassPath = implementationClass.getPackage().getName().replace('.', File.separatorChar); + this.implementationClassName = implementationClass.getSimpleName(); + + String abstractClassAbsolutePath = info.getSourceFile().getAbsolutePath(); + this.baseDirectory = abstractClassAbsolutePath.replace(abstractClassPath, + File.separatorChar + implementationClassPath); + } + + public CRDGeneratorApprovalNamer(String baseDirectory, + String implementationClassName, + String additionalInformation) { + this.baseDirectory = baseDirectory; + this.implementationClassName = implementationClassName; + this.additionalInformation = additionalInformation; + } + + @Override + public String getApprovalName() { + return String.format("%s%s", implementationClassName, additionalInformation); + } + + @Override + public String getSourceFilePath() { + String sub = NamerFactory.getSubdirectory(); + String subdirectory = sub != null && !sub.isEmpty() ? sub + File.separator : ""; + return baseDirectory + File.separator + subdirectory; + } + + @Override + public File getReceivedFile(String extensionWithDot) { + return new File( + getSourceFilePath() + File.separatorChar + getApprovalName() + Writer.received + extensionWithDot); + } + + @Override + public File getApprovedFile(String extensionWithDot) { + return new File( + getSourceFilePath() + File.separatorChar + getApprovalName() + Writer.approved + extensionWithDot); + } + + public ApprovalNamer addAdditionalInformation(String additionalInformation) { + return new CRDGeneratorApprovalNamer(this.baseDirectory, this.implementationClassName, + this.additionalInformation + "." + additionalInformation); + } +} diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/PackageSettings.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/PackageSettings.java new file mode 100644 index 00000000000..abccc6a6469 --- /dev/null +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/PackageSettings.java @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2015 Red Hat, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.fabric8.crd.generator.approvaltests; + +import org.approvaltests.core.ApprovalFailureReporter; +import org.approvaltests.reporters.QuietReporter; + +/** + * @see + * ApprovalTests - Best Configuration Practices + */ +public class PackageSettings { + /** + * Disable Diff-Reporter + */ + @SuppressWarnings("unused") + public static ApprovalFailureReporter UseReporter = new QuietReporter(); +} diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/annotated/AnnotatedApprovalTest.annotateds.samples.fabric8.io.v1.approved.yml b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/annotated/AnnotatedApprovalTest.annotateds.samples.fabric8.io.v1.approved.yml new file mode 100644 index 00000000000..2b8d292108a --- /dev/null +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/annotated/AnnotatedApprovalTest.annotateds.samples.fabric8.io.v1.approved.yml @@ -0,0 +1,78 @@ +# Generated by Fabric8 CRDGenerator, manual edits might get overwritten! +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + name: annotateds.samples.fabric8.io +spec: + group: samples.fabric8.io + names: + kind: Annotated + plural: annotateds + singular: annotated + scope: Cluster + versions: + - name: v1 + schema: + openAPIV3Schema: + properties: + spec: + properties: + anEnum: + enum: + - non + - oui + type: string + defaultValue: + default: my-value + type: string + defaultValue2: + default: my-value2 + type: string + emptySetter: + type: boolean + emptySetter2: + type: boolean + from-field: + description: from-field-description + type: string + from-getter: + description: from-getter-description + type: integer + kubernetesValidationRule: + type: string + x-kubernetes-validations: + - message: kubernetesValidationRule must start with prefix 'prefix-' + rule: self.startwith('prefix-') + kubernetesValidationRules: + type: string + x-kubernetes-validations: + - rule: first.rule + - rule: second.rule + - reason: FieldValueForbidden + rule: third.rule + max: + maximum: 5.0 + type: integer + min: + minimum: -5.0 + type: integer + nullable: + nullable: true + type: string + singleDigit: + pattern: "\\b[1-9]\\b" + type: string + sizedField: + type: integer + unnamed: + type: string + required: + - emptySetter + - emptySetter2 + - from-getter + type: object + status: + type: object + type: object + served: true + storage: true \ No newline at end of file diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/annotated/AnnotatedApprovalTest.annotateds.samples.fabric8.io.v1beta1.approved.yml b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/annotated/AnnotatedApprovalTest.annotateds.samples.fabric8.io.v1beta1.approved.yml new file mode 100644 index 00000000000..e520f1b0a8f --- /dev/null +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/annotated/AnnotatedApprovalTest.annotateds.samples.fabric8.io.v1beta1.approved.yml @@ -0,0 +1,78 @@ +# Generated by Fabric8 CRDGenerator, manual edits might get overwritten! +apiVersion: apiextensions.k8s.io/v1beta1 +kind: CustomResourceDefinition +metadata: + name: annotateds.samples.fabric8.io +spec: + group: samples.fabric8.io + names: + kind: Annotated + plural: annotateds + singular: annotated + scope: Cluster + validation: + openAPIV3Schema: + properties: + spec: + properties: + anEnum: + enum: + - non + - oui + type: string + defaultValue: + default: my-value + type: string + defaultValue2: + default: my-value2 + type: string + emptySetter: + type: boolean + emptySetter2: + type: boolean + from-field: + description: from-field-description + type: string + from-getter: + description: from-getter-description + type: integer + kubernetesValidationRule: + type: string + x-kubernetes-validations: + - message: kubernetesValidationRule must start with prefix 'prefix-' + rule: self.startwith('prefix-') + kubernetesValidationRules: + type: string + x-kubernetes-validations: + - rule: first.rule + - rule: second.rule + - reason: FieldValueForbidden + rule: third.rule + max: + maximum: 5.0 + type: integer + min: + minimum: -5.0 + type: integer + nullable: + nullable: true + type: string + singleDigit: + pattern: "\\b[1-9]\\b" + type: string + sizedField: + type: integer + unnamed: + type: string + required: + - emptySetter + - emptySetter2 + - from-getter + type: object + status: + type: object + type: object + versions: + - name: v1 + served: true + storage: true \ No newline at end of file diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/annotated/AnnotatedApprovalTest.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/annotated/AnnotatedApprovalTest.java new file mode 100644 index 00000000000..fd45bd7660a --- /dev/null +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/annotated/AnnotatedApprovalTest.java @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2015 Red Hat, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.fabric8.crd.generator.approvaltests.annotated; + +import io.fabric8.crd.generator.approvaltests.AbstractCRDGeneratorApprovalTest; +import io.fabric8.kubernetes.client.CustomResource; + +public class AnnotatedApprovalTest extends AbstractCRDGeneratorApprovalTest { + + protected Class>[] crClasses() { + return new Class[] { + io.fabric8.crd.generator.approvaltests.annotated.api.Annotated.class + }; + } + + protected String[] expectedCRDs() { + return new String[] { + "annotateds.samples.fabric8.io" + }; + } +} diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/annotated/api/Annotated.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/annotated/api/Annotated.java new file mode 100644 index 00000000000..cc2cc300612 --- /dev/null +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/annotated/api/Annotated.java @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2015 Red Hat, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.fabric8.crd.generator.approvaltests.annotated.api; + +import io.fabric8.kubernetes.client.CustomResource; +import io.fabric8.kubernetes.model.annotation.Group; +import io.fabric8.kubernetes.model.annotation.Version; + +@Group("samples.fabric8.io") +@Version("v1") +public class Annotated extends CustomResource { + +} diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/annotated/api/AnnotatedSpec.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/annotated/api/AnnotatedSpec.java new file mode 100644 index 00000000000..dd2dbc6dc61 --- /dev/null +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/annotated/api/AnnotatedSpec.java @@ -0,0 +1,150 @@ +/* + * Copyright (C) 2015 Red Hat, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.fabric8.crd.generator.approvaltests.annotated.api; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyDescription; +import io.fabric8.generator.annotation.Default; +import io.fabric8.generator.annotation.Max; +import io.fabric8.generator.annotation.Min; +import io.fabric8.generator.annotation.Nullable; +import io.fabric8.generator.annotation.Pattern; +import io.fabric8.generator.annotation.Required; +import io.fabric8.generator.annotation.ValidationRule; +import lombok.Data; + +@Data +public class AnnotatedSpec { + @JsonProperty("from-field") + @JsonPropertyDescription("from-field-description") + private String field; + private int foo; + @JsonProperty + private String unnamed; + private int min; + private int max; + private String singleDigit; + private String nullable; + private String defaultValue; + @Default("my-value2") + private String defaultValue2; + @Required + private boolean emptySetter; + @Required + private boolean emptySetter2; + private AnnotatedEnum anEnum; + @javax.validation.constraints.Min(0) // a non-string value attribute + private int sizedField; + + @JsonIgnore + private int ignoredFoo; + + private boolean ignoredBar; + + @ValidationRule(value = "self.startwith('prefix-')", message = "kubernetesValidationRule must start with prefix 'prefix-'") + private String kubernetesValidationRule; + + @ValidationRule("first.rule") + @ValidationRule("second.rule") + @ValidationRule(value = "third.rule", reason = "FieldValueForbidden") + private String kubernetesValidationRules; + + @JsonProperty("from-getter") + @JsonPropertyDescription("from-getter-description") + @Required + public int getFoo() { + return foo; + } + + public int getIgnoredFoo() { + return ignoredFoo; + } + + @JsonIgnore + public boolean getIgnoredBar() { + return ignoredBar; + } + + @Max(5.0) + public int getMax() { + return 1; + } + + @Min(-5) + public int getMin() { + return 1; + } + + @Pattern("\\b[1-9]\\b") + public String getSingleDigit() { + return "1"; + } + + @Nullable + public String getNullable() { + return null; + } + + @Default("my-value") + public String getDefaultValue() { + return "foo"; + } + + @JsonProperty + public void setEmptySetter(boolean emptySetter) { + this.emptySetter = emptySetter; + } + + @JsonProperty + public void setEmptySetter2(boolean emptySetter2) { + this.emptySetter2 = emptySetter2; + } + + public enum AnnotatedEnum { + non("N"), + @JsonProperty("oui") + es("O"), + @JsonIgnore + Maybe("Maybe"); + + private final String abbreviation; + + AnnotatedEnum(String abbreviation) { + this.abbreviation = abbreviation; + } + + public String getAbbreviation() { + return abbreviation; + } + + public static AnnotatedEnum SIM = es; + + public AnotherEnum one = AnotherEnum.ONE; + + public AnotherEnum getOne() { + return one; + } + + public void setOne(AnotherEnum one) { + this.one = one; + } + } + + public enum AnotherEnum { + ONE + } +} diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/ComplexApprovalTest.complexkinds.samples.fabric8.io.v1.approved.yml b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/ComplexApprovalTest.complexkinds.samples.fabric8.io.v1.approved.yml new file mode 100644 index 00000000000..7a3ca65680e --- /dev/null +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/ComplexApprovalTest.complexkinds.samples.fabric8.io.v1.approved.yml @@ -0,0 +1,199 @@ +# Generated by Fabric8 CRDGenerator, manual edits might get overwritten! +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + name: complexkinds.samples.fabric8.io +spec: + group: samples.fabric8.io + names: + kind: ComplexKind + plural: complexkinds + singular: complexkind + scope: Namespaced + versions: + - additionalPrinterColumns: + - jsonPath: .status.message + name: Message + priority: 0 + type: string + - jsonPath: .status.state + name: State + priority: 0 + type: string + name: v1 + schema: + openAPIV3Schema: + properties: + spec: + properties: + actuatorPort: + type: integer + configMapName: + type: string + metricsPath: + type: string + metricsPort: + type: integer + services: + items: + properties: + metadata: + description: The metadata of this Service + properties: + annotations: + additionalProperties: + type: string + type: object + creationTimestamp: + type: string + deletionGracePeriodSeconds: + type: integer + deletionTimestamp: + type: string + finalizers: + items: + type: string + type: array + generateName: + type: string + generation: + type: integer + labels: + additionalProperties: + type: string + type: object + name: + type: string + namespace: + type: string + resourceVersion: + type: string + selfLink: + type: string + uid: + type: string + type: object + spec: + description: The spec of this Service + nullable: true + properties: + allocateLoadBalancerNodePorts: + type: boolean + clusterIP: + type: string + clusterIPs: + items: + type: string + type: array + externalIPs: + items: + type: string + type: array + externalName: + type: string + externalTrafficPolicy: + type: string + healthCheckNodePort: + type: integer + internalTrafficPolicy: + type: string + ipFamilies: + items: + type: string + type: array + ipFamilyPolicy: + type: string + loadBalancerClass: + type: string + loadBalancerIP: + type: string + loadBalancerSourceRanges: + items: + type: string + type: array + publishNotReadyAddresses: + type: boolean + selector: + additionalProperties: + type: string + type: object + sessionAffinity: + type: string + type: + type: string + type: object + type: object + type: array + statefulSet: + properties: + metadata: + description: The metadata of this StatefulSet + properties: + annotations: + additionalProperties: + type: string + type: object + creationTimestamp: + type: string + deletionGracePeriodSeconds: + type: integer + deletionTimestamp: + type: string + finalizers: + items: + type: string + type: array + generateName: + type: string + generation: + type: integer + labels: + additionalProperties: + type: string + type: object + name: + type: string + namespace: + type: string + resourceVersion: + type: string + selfLink: + type: string + uid: + type: string + type: object + spec: + description: The spec of this StatefulSet + properties: + minReadySeconds: + type: integer + podManagementPolicy: + type: string + replicas: + type: integer + revisionHistoryLimit: + type: integer + serviceName: + type: string + type: object + type: object + type: object + status: + properties: + message: + type: string + state: + enum: + - CREATED + - ERROR + - ROLLING_UPDATE + - RUNNING + - SCALING + - STARTING + type: string + type: object + type: object + served: true + storage: true + subresources: + status: {} diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/ComplexApprovalTest.complexkinds.samples.fabric8.io.v1beta1.approved.yml b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/ComplexApprovalTest.complexkinds.samples.fabric8.io.v1beta1.approved.yml new file mode 100644 index 00000000000..5aa1169b6a2 --- /dev/null +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/ComplexApprovalTest.complexkinds.samples.fabric8.io.v1beta1.approved.yml @@ -0,0 +1,199 @@ +# Generated by Fabric8 CRDGenerator, manual edits might get overwritten! +apiVersion: apiextensions.k8s.io/v1beta1 +kind: CustomResourceDefinition +metadata: + name: complexkinds.samples.fabric8.io +spec: + additionalPrinterColumns: + - JSONPath: .status.message + name: Message + priority: 0 + type: string + - JSONPath: .status.state + name: State + priority: 0 + type: string + group: samples.fabric8.io + names: + kind: ComplexKind + plural: complexkinds + singular: complexkind + scope: Namespaced + subresources: + status: {} + validation: + openAPIV3Schema: + properties: + spec: + properties: + actuatorPort: + type: integer + configMapName: + type: string + metricsPath: + type: string + metricsPort: + type: integer + services: + items: + properties: + metadata: + description: The metadata of this Service + properties: + annotations: + additionalProperties: + type: string + type: object + creationTimestamp: + type: string + deletionGracePeriodSeconds: + type: integer + deletionTimestamp: + type: string + finalizers: + items: + type: string + type: array + generateName: + type: string + generation: + type: integer + labels: + additionalProperties: + type: string + type: object + name: + type: string + namespace: + type: string + resourceVersion: + type: string + selfLink: + type: string + uid: + type: string + type: object + spec: + description: The spec of this Service + nullable: true + properties: + allocateLoadBalancerNodePorts: + type: boolean + clusterIP: + type: string + clusterIPs: + items: + type: string + type: array + externalIPs: + items: + type: string + type: array + externalName: + type: string + externalTrafficPolicy: + type: string + healthCheckNodePort: + type: integer + internalTrafficPolicy: + type: string + ipFamilies: + items: + type: string + type: array + ipFamilyPolicy: + type: string + loadBalancerClass: + type: string + loadBalancerIP: + type: string + loadBalancerSourceRanges: + items: + type: string + type: array + publishNotReadyAddresses: + type: boolean + selector: + additionalProperties: + type: string + type: object + sessionAffinity: + type: string + type: + type: string + type: object + type: object + type: array + statefulSet: + properties: + metadata: + description: The metadata of this StatefulSet + properties: + annotations: + additionalProperties: + type: string + type: object + creationTimestamp: + type: string + deletionGracePeriodSeconds: + type: integer + deletionTimestamp: + type: string + finalizers: + items: + type: string + type: array + generateName: + type: string + generation: + type: integer + labels: + additionalProperties: + type: string + type: object + name: + type: string + namespace: + type: string + resourceVersion: + type: string + selfLink: + type: string + uid: + type: string + type: object + spec: + description: The spec of this StatefulSet + properties: + minReadySeconds: + type: integer + podManagementPolicy: + type: string + replicas: + type: integer + revisionHistoryLimit: + type: integer + serviceName: + type: string + type: object + type: object + type: object + status: + properties: + message: + type: string + state: + enum: + - CREATED + - ERROR + - ROLLING_UPDATE + - RUNNING + - SCALING + - STARTING + type: string + type: object + type: object + versions: + - name: v1 + served: true + storage: true diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/ComplexApprovalTest.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/ComplexApprovalTest.java new file mode 100644 index 00000000000..08c35a511e6 --- /dev/null +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/ComplexApprovalTest.java @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2015 Red Hat, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.fabric8.crd.generator.approvaltests.complex; + +import io.fabric8.crd.generator.approvaltests.AbstractCRDGeneratorApprovalTest; +import io.fabric8.kubernetes.client.CustomResource; + +public class ComplexApprovalTest extends AbstractCRDGeneratorApprovalTest { + protected Class>[] crClasses() { + return new Class[] { + io.fabric8.crd.generator.approvaltests.complex.api.Complex.class + }; + } + + protected String[] expectedCRDs() { + return new String[] { + "complexkinds.samples.fabric8.io" + }; + } +} diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/api/Complex.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/api/Complex.java new file mode 100644 index 00000000000..774a98c1d8e --- /dev/null +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/api/Complex.java @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2015 Red Hat, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.fabric8.crd.generator.approvaltests.complex.api; + +import io.fabric8.kubernetes.api.model.Namespaced; +import io.fabric8.kubernetes.client.CustomResource; +import io.fabric8.kubernetes.model.annotation.Group; +import io.fabric8.kubernetes.model.annotation.Kind; +import io.fabric8.kubernetes.model.annotation.Version; + +@Group("samples.fabric8.io") +@Version("v1") +@Kind("ComplexKind") +public class Complex extends CustomResource implements Namespaced { +} diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/api/ComplexSpec.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/api/ComplexSpec.java new file mode 100644 index 00000000000..b26ad586bfe --- /dev/null +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/api/ComplexSpec.java @@ -0,0 +1,79 @@ +/* + * Copyright (C) 2015 Red Hat, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.fabric8.crd.generator.approvaltests.complex.api; + +import java.util.ArrayList; +import java.util.List; + +@SuppressWarnings("LombokGetterMayBeUsed") +public class ComplexSpec { + private StatefulSetConfiguration statefulSet = new StatefulSetConfiguration(); + private List services = new ArrayList<>(); + + private String configMapName = "example-configuration"; + + private int actuatorPort; + private int metricsPort; + private String metricsPath = "/"; + + public StatefulSetConfiguration getStatefulSet() { + return statefulSet; + } + + public void setStatefulSet(StatefulSetConfiguration statefulSet) { + this.statefulSet = statefulSet; + } + + public List getServices() { + return services; + } + + public void setServices(List services) { + this.services = services; + } + + public String getConfigMapName() { + return configMapName; + } + + public void setConfigMapName(String configMapName) { + this.configMapName = configMapName; + } + + public int getActuatorPort() { + return actuatorPort; + } + + public void setActuatorPort(int actuatorPort) { + this.actuatorPort = actuatorPort; + } + + public int getMetricsPort() { + return metricsPort; + } + + public void setMetricsPort(int metricsPort) { + this.metricsPort = metricsPort; + } + + public String getMetricsPath() { + return metricsPath; + } + + public void setMetricsPath(String metricsPath) { + this.metricsPath = metricsPath; + } +} diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/api/ComplexStatus.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/api/ComplexStatus.java new file mode 100644 index 00000000000..9dd8a75777e --- /dev/null +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/api/ComplexStatus.java @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2015 Red Hat, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.fabric8.crd.generator.approvaltests.complex.api; + +import com.fasterxml.jackson.annotation.JsonProperty; +import io.fabric8.crd.generator.annotation.PrinterColumn; + +@SuppressWarnings("LombokGetterMayBeUsed") +public class ComplexStatus { + + public enum State { + CREATED, + STARTING, + RUNNING, + ROLLING_UPDATE, + SCALING, + ERROR + } + + public ComplexStatus() { + this.state = State.CREATED; + this.message = "Deployment was created"; + } + + @JsonProperty("state") + @PrinterColumn(name = "State") + private State state; + + @JsonProperty("message") + @PrinterColumn(name = "Message") + private String message; + + public State getState() { + return state; + } + + public void setState(final State state) { + this.state = state; + } + + public String getMessage() { + return message; + } + + public void setMessage(final String message) { + this.message = message; + } +} diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/api/ServiceConfiguration.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/api/ServiceConfiguration.java new file mode 100644 index 00000000000..9b4b571e883 --- /dev/null +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/api/ServiceConfiguration.java @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2015 Red Hat, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.fabric8.crd.generator.approvaltests.complex.api; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyDescription; +import io.fabric8.crd.generator.approvaltests.complex.api.k8s.ObjectMeta; +import io.fabric8.crd.generator.approvaltests.complex.api.k8s.ServiceSpec; +import io.fabric8.generator.annotation.Nullable; + +@SuppressWarnings("LombokGetterMayBeUsed") +public class ServiceConfiguration { + + @JsonProperty("metadata") + @JsonPropertyDescription("The metadata of this Service") + private ObjectMeta metadata = new ObjectMeta(); + + @JsonProperty("spec") + @JsonPropertyDescription("The spec of this Service") + private @Nullable ServiceSpec spec; + + public ServiceConfiguration() { + } + + public ObjectMeta getMetadata() { + return metadata; + } + + public void setMetadata(final ObjectMeta metadata) { + this.metadata = metadata; + } + + public @Nullable ServiceSpec getSpec() { + return spec; + } + + public void setSpec(final ServiceSpec spec) { + this.spec = spec; + } +} diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/api/StatefulSetConfiguration.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/api/StatefulSetConfiguration.java new file mode 100644 index 00000000000..c533074c888 --- /dev/null +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/api/StatefulSetConfiguration.java @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2015 Red Hat, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.fabric8.crd.generator.approvaltests.complex.api; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyDescription; +import io.fabric8.crd.generator.approvaltests.complex.api.k8s.ObjectMeta; +import io.fabric8.crd.generator.approvaltests.complex.api.k8s.StatefulSetSpec; + +@SuppressWarnings("LombokGetterMayBeUsed") +public class StatefulSetConfiguration { + + @JsonProperty("metadata") + @JsonPropertyDescription("The metadata of this StatefulSet") + private ObjectMeta metadata = new ObjectMeta(); + + @JsonProperty("spec") + @JsonPropertyDescription("The spec of this StatefulSet") + private StatefulSetSpec spec = new StatefulSetSpec(); + + public StatefulSetConfiguration() { + } + + public ObjectMeta getMetadata() { + return metadata; + } + + public void setMetadata(final ObjectMeta metadata) { + this.metadata = metadata; + } + + public StatefulSetSpec getSpec() { + return spec; + } + + public void setSpec(final StatefulSetSpec spec) { + this.spec = spec; + } +} diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/api/k8s/ObjectMeta.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/api/k8s/ObjectMeta.java new file mode 100644 index 00000000000..5114cb87b86 --- /dev/null +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/api/k8s/ObjectMeta.java @@ -0,0 +1,232 @@ +/* + * Copyright (C) 2015 Red Hat, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.fabric8.crd.generator.approvaltests.complex.api.k8s; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import io.fabric8.kubernetes.api.model.KubernetesResource; + +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +/** + * Simplified version of the K8s ObjectMeta. + * + * The purpose of this class is to create a complex, but stable CRD, that doesn't change when the generated ObjectMeta class is + * changed. + */ +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonPropertyOrder({ + "apiVersion", + "kind", + "metadata", + "annotations", + "creationTimestamp", + "deletionGracePeriodSeconds", + "deletionTimestamp", + "finalizers", + "generateName", + "generation", + "labels", + "name", + "namespace", + "resourceVersion", + "selfLink", + "uid" +}) +public class ObjectMeta implements KubernetesResource { + + @JsonProperty("annotations") + @JsonInclude(JsonInclude.Include.NON_EMPTY) + private Map annotations = new LinkedHashMap<>(); + @JsonProperty("creationTimestamp") + private String creationTimestamp; + @JsonProperty("deletionGracePeriodSeconds") + private Long deletionGracePeriodSeconds; + @JsonProperty("deletionTimestamp") + private String deletionTimestamp; + @JsonProperty("finalizers") + @JsonInclude(JsonInclude.Include.NON_EMPTY) + private List finalizers = new ArrayList<>(); + @JsonProperty("generateName") + private String generateName; + @JsonProperty("generation") + private Long generation; + @JsonProperty("labels") + @JsonInclude(JsonInclude.Include.NON_EMPTY) + private Map labels = new LinkedHashMap<>(); + @JsonProperty("name") + private String name; + @JsonProperty("namespace") + private String namespace; + @JsonProperty("resourceVersion") + private String resourceVersion; + @JsonProperty("selfLink") + private String selfLink; + @JsonProperty("uid") + private String uid; + @JsonIgnore + private final Map additionalProperties = new LinkedHashMap<>(); + + public ObjectMeta() { + } + + @JsonProperty("annotations") + public Map getAnnotations() { + return annotations; + } + + @JsonProperty("annotations") + public void setAnnotations(Map annotations) { + this.annotations = annotations; + } + + @JsonProperty("creationTimestamp") + public String getCreationTimestamp() { + return creationTimestamp; + } + + @JsonProperty("creationTimestamp") + public void setCreationTimestamp(String creationTimestamp) { + this.creationTimestamp = creationTimestamp; + } + + @JsonProperty("deletionGracePeriodSeconds") + public Long getDeletionGracePeriodSeconds() { + return deletionGracePeriodSeconds; + } + + @JsonProperty("deletionGracePeriodSeconds") + public void setDeletionGracePeriodSeconds(Long deletionGracePeriodSeconds) { + this.deletionGracePeriodSeconds = deletionGracePeriodSeconds; + } + + @JsonProperty("deletionTimestamp") + public String getDeletionTimestamp() { + return deletionTimestamp; + } + + @JsonProperty("deletionTimestamp") + public void setDeletionTimestamp(String deletionTimestamp) { + this.deletionTimestamp = deletionTimestamp; + } + + @JsonProperty("finalizers") + public List getFinalizers() { + return finalizers; + } + + @JsonProperty("finalizers") + public void setFinalizers(List finalizers) { + this.finalizers = finalizers; + } + + @JsonProperty("generateName") + public String getGenerateName() { + return generateName; + } + + @JsonProperty("generateName") + public void setGenerateName(String generateName) { + this.generateName = generateName; + } + + @JsonProperty("generation") + public Long getGeneration() { + return generation; + } + + @JsonProperty("generation") + public void setGeneration(Long generation) { + this.generation = generation; + } + + @JsonProperty("labels") + public Map getLabels() { + return labels; + } + + @JsonProperty("labels") + public void setLabels(Map labels) { + this.labels = labels; + } + + @JsonProperty("name") + public String getName() { + return name; + } + + @JsonProperty("name") + public void setName(String name) { + this.name = name; + } + + @JsonProperty("namespace") + public String getNamespace() { + return namespace; + } + + @JsonProperty("namespace") + public void setNamespace(String namespace) { + this.namespace = namespace; + } + + @JsonProperty("resourceVersion") + public String getResourceVersion() { + return resourceVersion; + } + + @JsonProperty("resourceVersion") + public void setResourceVersion(String resourceVersion) { + this.resourceVersion = resourceVersion; + } + + @JsonProperty("selfLink") + public String getSelfLink() { + return selfLink; + } + + @JsonProperty("selfLink") + public void setSelfLink(String selfLink) { + this.selfLink = selfLink; + } + + @JsonProperty("uid") + public String getUid() { + return uid; + } + + @JsonProperty("uid") + public void setUid(String uid) { + this.uid = uid; + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + @JsonAnySetter + public void setAdditionalProperty(String name, Object value) { + this.additionalProperties.put(name, value); + } +} diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/api/k8s/ServiceSpec.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/api/k8s/ServiceSpec.java new file mode 100644 index 00000000000..b3beedd933c --- /dev/null +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/api/k8s/ServiceSpec.java @@ -0,0 +1,286 @@ +/* + * Copyright (C) 2015 Red Hat, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.fabric8.crd.generator.approvaltests.complex.api.k8s; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import io.fabric8.kubernetes.api.model.KubernetesResource; + +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +/** + * Simplified version of the K8s ServiceSpec. + * + * The purpose of this class is to create a complex, but stable CRD, that doesn't change when the generated ServiceSpec class is + * changed. + */ +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonPropertyOrder({ + "apiVersion", + "kind", + "metadata", + "allocateLoadBalancerNodePorts", + "clusterIP", + "clusterIPs", + "externalIPs", + "externalName", + "externalTrafficPolicy", + "healthCheckNodePort", + "internalTrafficPolicy", + "ipFamilies", + "ipFamilyPolicy", + "loadBalancerClass", + "loadBalancerIP", + "loadBalancerSourceRanges", + "publishNotReadyAddresses", + "selector", + "sessionAffinityConfig", + "type" +}) +public class ServiceSpec implements KubernetesResource { + + @JsonProperty("allocateLoadBalancerNodePorts") + private Boolean allocateLoadBalancerNodePorts; + @JsonProperty("clusterIP") + private String clusterIP; + @JsonProperty("clusterIPs") + @JsonInclude(JsonInclude.Include.NON_EMPTY) + private List clusterIPs = new ArrayList<>(); + @JsonProperty("externalIPs") + @JsonInclude(JsonInclude.Include.NON_EMPTY) + private List externalIPs = new ArrayList<>(); + @JsonProperty("externalName") + private String externalName; + @JsonProperty("externalTrafficPolicy") + private String externalTrafficPolicy; + @JsonProperty("healthCheckNodePort") + private Integer healthCheckNodePort; + @JsonProperty("internalTrafficPolicy") + private String internalTrafficPolicy; + @JsonProperty("ipFamilies") + @JsonInclude(JsonInclude.Include.NON_EMPTY) + private List ipFamilies = new ArrayList<>(); + @JsonProperty("ipFamilyPolicy") + private String ipFamilyPolicy; + @JsonProperty("loadBalancerClass") + private String loadBalancerClass; + @JsonProperty("loadBalancerIP") + private String loadBalancerIP; + @JsonProperty("loadBalancerSourceRanges") + @JsonInclude(JsonInclude.Include.NON_EMPTY) + private List loadBalancerSourceRanges = new ArrayList<>(); + @JsonProperty("publishNotReadyAddresses") + private Boolean publishNotReadyAddresses; + @JsonProperty("selector") + @JsonInclude(JsonInclude.Include.NON_EMPTY) + private Map selector = new LinkedHashMap<>(); + @JsonProperty("sessionAffinity") + private String sessionAffinity; + @JsonProperty("type") + private String type; + @JsonIgnore + private final Map additionalProperties = new LinkedHashMap<>(); + + public ServiceSpec() { + } + + @JsonProperty("allocateLoadBalancerNodePorts") + public Boolean getAllocateLoadBalancerNodePorts() { + return allocateLoadBalancerNodePorts; + } + + @JsonProperty("allocateLoadBalancerNodePorts") + public void setAllocateLoadBalancerNodePorts(Boolean allocateLoadBalancerNodePorts) { + this.allocateLoadBalancerNodePorts = allocateLoadBalancerNodePorts; + } + + @JsonProperty("clusterIP") + public String getClusterIP() { + return clusterIP; + } + + @JsonProperty("clusterIP") + public void setClusterIP(String clusterIP) { + this.clusterIP = clusterIP; + } + + @JsonProperty("clusterIPs") + public List getClusterIPs() { + return clusterIPs; + } + + @JsonProperty("clusterIPs") + public void setClusterIPs(List clusterIPs) { + this.clusterIPs = clusterIPs; + } + + @JsonProperty("externalIPs") + public List getExternalIPs() { + return externalIPs; + } + + @JsonProperty("externalIPs") + public void setExternalIPs(List externalIPs) { + this.externalIPs = externalIPs; + } + + @JsonProperty("externalName") + public String getExternalName() { + return externalName; + } + + @JsonProperty("externalName") + public void setExternalName(String externalName) { + this.externalName = externalName; + } + + @JsonProperty("externalTrafficPolicy") + public String getExternalTrafficPolicy() { + return externalTrafficPolicy; + } + + @JsonProperty("externalTrafficPolicy") + public void setExternalTrafficPolicy(String externalTrafficPolicy) { + this.externalTrafficPolicy = externalTrafficPolicy; + } + + @JsonProperty("healthCheckNodePort") + public Integer getHealthCheckNodePort() { + return healthCheckNodePort; + } + + @JsonProperty("healthCheckNodePort") + public void setHealthCheckNodePort(Integer healthCheckNodePort) { + this.healthCheckNodePort = healthCheckNodePort; + } + + @JsonProperty("internalTrafficPolicy") + public String getInternalTrafficPolicy() { + return internalTrafficPolicy; + } + + @JsonProperty("internalTrafficPolicy") + public void setInternalTrafficPolicy(String internalTrafficPolicy) { + this.internalTrafficPolicy = internalTrafficPolicy; + } + + @JsonProperty("ipFamilies") + public List getIpFamilies() { + return ipFamilies; + } + + @JsonProperty("ipFamilies") + public void setIpFamilies(List ipFamilies) { + this.ipFamilies = ipFamilies; + } + + @JsonProperty("ipFamilyPolicy") + public String getIpFamilyPolicy() { + return ipFamilyPolicy; + } + + @JsonProperty("ipFamilyPolicy") + public void setIpFamilyPolicy(String ipFamilyPolicy) { + this.ipFamilyPolicy = ipFamilyPolicy; + } + + @JsonProperty("loadBalancerClass") + public String getLoadBalancerClass() { + return loadBalancerClass; + } + + @JsonProperty("loadBalancerClass") + public void setLoadBalancerClass(String loadBalancerClass) { + this.loadBalancerClass = loadBalancerClass; + } + + @JsonProperty("loadBalancerIP") + public String getLoadBalancerIP() { + return loadBalancerIP; + } + + @JsonProperty("loadBalancerIP") + public void setLoadBalancerIP(String loadBalancerIP) { + this.loadBalancerIP = loadBalancerIP; + } + + @JsonProperty("loadBalancerSourceRanges") + public List getLoadBalancerSourceRanges() { + return loadBalancerSourceRanges; + } + + @JsonProperty("loadBalancerSourceRanges") + public void setLoadBalancerSourceRanges(List loadBalancerSourceRanges) { + this.loadBalancerSourceRanges = loadBalancerSourceRanges; + } + + @JsonProperty("publishNotReadyAddresses") + public Boolean getPublishNotReadyAddresses() { + return publishNotReadyAddresses; + } + + @JsonProperty("publishNotReadyAddresses") + public void setPublishNotReadyAddresses(Boolean publishNotReadyAddresses) { + this.publishNotReadyAddresses = publishNotReadyAddresses; + } + + @JsonProperty("selector") + public Map getSelector() { + return selector; + } + + @JsonProperty("selector") + public void setSelector(Map selector) { + this.selector = selector; + } + + @JsonProperty("sessionAffinity") + public String getSessionAffinity() { + return sessionAffinity; + } + + @JsonProperty("sessionAffinity") + public void setSessionAffinity(String sessionAffinity) { + this.sessionAffinity = sessionAffinity; + } + + @JsonProperty("type") + public String getType() { + return type; + } + + @JsonProperty("type") + public void setType(String type) { + this.type = type; + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + @JsonAnySetter + public void setAdditionalProperty(String name, Object value) { + this.additionalProperties.put(name, value); + } +} diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/api/k8s/StatefulSetSpec.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/api/k8s/StatefulSetSpec.java new file mode 100644 index 00000000000..59bb1f624a4 --- /dev/null +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/api/k8s/StatefulSetSpec.java @@ -0,0 +1,126 @@ +/* + * Copyright (C) 2015 Red Hat, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.fabric8.crd.generator.approvaltests.complex.api.k8s; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import io.fabric8.kubernetes.api.model.KubernetesResource; + +import java.util.LinkedHashMap; +import java.util.Map; + +/** + * Simplified version of the K8s StatefulSetSpec. + * + * The purpose of this class is to create a complex, but stable CRD, that doesn't change when the generated StatefulSetSpec + * class is changed. + */ +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonPropertyOrder({ + "apiVersion", + "kind", + "metadata", + "minReadySeconds", + "podManagementPolicy", + "replicas", + "revisionHistoryLimit", + "serviceName" +}) +public class StatefulSetSpec implements KubernetesResource { + @JsonProperty("minReadySeconds") + private Integer minReadySeconds; + @JsonProperty("podManagementPolicy") + private String podManagementPolicy; + @JsonProperty("replicas") + private Integer replicas; + @JsonProperty("revisionHistoryLimit") + private Integer revisionHistoryLimit; + @JsonProperty("serviceName") + private String serviceName; + @JsonIgnore + private final Map additionalProperties = new LinkedHashMap<>(); + + /** + * No args constructor for use in serialization + * + */ + public StatefulSetSpec() { + } + + @JsonProperty("minReadySeconds") + public Integer getMinReadySeconds() { + return minReadySeconds; + } + + @JsonProperty("minReadySeconds") + public void setMinReadySeconds(Integer minReadySeconds) { + this.minReadySeconds = minReadySeconds; + } + + @JsonProperty("podManagementPolicy") + public String getPodManagementPolicy() { + return podManagementPolicy; + } + + @JsonProperty("podManagementPolicy") + public void setPodManagementPolicy(String podManagementPolicy) { + this.podManagementPolicy = podManagementPolicy; + } + + @JsonProperty("replicas") + public Integer getReplicas() { + return replicas; + } + + @JsonProperty("replicas") + public void setReplicas(Integer replicas) { + this.replicas = replicas; + } + + @JsonProperty("revisionHistoryLimit") + public Integer getRevisionHistoryLimit() { + return revisionHistoryLimit; + } + + @JsonProperty("revisionHistoryLimit") + public void setRevisionHistoryLimit(Integer revisionHistoryLimit) { + this.revisionHistoryLimit = revisionHistoryLimit; + } + + @JsonProperty("serviceName") + public String getServiceName() { + return serviceName; + } + + @JsonProperty("serviceName") + public void setServiceName(String serviceName) { + this.serviceName = serviceName; + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + @JsonAnySetter + public void setAdditionalProperty(String name, Object value) { + this.additionalProperties.put(name, value); + } +} diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/inherited/InheritedApprovalTest.children.sample.fabric8.io.v1.approved.yml b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/inherited/InheritedApprovalTest.children.sample.fabric8.io.v1.approved.yml new file mode 100644 index 00000000000..2ae0d789efa --- /dev/null +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/inherited/InheritedApprovalTest.children.sample.fabric8.io.v1.approved.yml @@ -0,0 +1,41 @@ +# Generated by Fabric8 CRDGenerator, manual edits might get overwritten! +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + name: children.sample.fabric8.io +spec: + group: sample.fabric8.io + names: + kind: Child + plural: children + singular: child + scope: Namespaced + versions: + - name: v1alpha1 + schema: + openAPIV3Schema: + properties: + spec: + properties: + baseInt: + type: integer + supported: + additionalProperties: + type: string + type: object + unsupported: + additionalProperties: + type: object + type: object + unsupported2: + additionalProperties: + type: object + type: object + type: object + status: + type: object + type: object + served: true + storage: true + subresources: + status: {} \ No newline at end of file diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/inherited/InheritedApprovalTest.children.sample.fabric8.io.v1beta1.approved.yml b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/inherited/InheritedApprovalTest.children.sample.fabric8.io.v1beta1.approved.yml new file mode 100644 index 00000000000..5824f453b80 --- /dev/null +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/inherited/InheritedApprovalTest.children.sample.fabric8.io.v1beta1.approved.yml @@ -0,0 +1,41 @@ +# Generated by Fabric8 CRDGenerator, manual edits might get overwritten! +apiVersion: apiextensions.k8s.io/v1beta1 +kind: CustomResourceDefinition +metadata: + name: children.sample.fabric8.io +spec: + group: sample.fabric8.io + names: + kind: Child + plural: children + singular: child + scope: Namespaced + subresources: + status: {} + validation: + openAPIV3Schema: + properties: + spec: + properties: + baseInt: + type: integer + supported: + additionalProperties: + type: string + type: object + unsupported: + additionalProperties: + type: object + type: object + unsupported2: + additionalProperties: + type: object + type: object + type: object + status: + type: object + type: object + versions: + - name: v1alpha1 + served: true + storage: true \ No newline at end of file diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/inherited/InheritedApprovalTest.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/inherited/InheritedApprovalTest.java new file mode 100644 index 00000000000..2f28f296dbe --- /dev/null +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/inherited/InheritedApprovalTest.java @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2015 Red Hat, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.fabric8.crd.generator.approvaltests.inherited; + +import io.fabric8.crd.generator.approvaltests.AbstractCRDGeneratorApprovalTest; +import io.fabric8.kubernetes.client.CustomResource; + +class InheritedApprovalTest extends AbstractCRDGeneratorApprovalTest { + protected Class>[] crClasses() { + return new Class[] { + io.fabric8.crd.generator.approvaltests.inherited.api.Child.class + }; + } + + protected String[] expectedCRDs() { + return new String[] { + "children.sample.fabric8.io" + }; + } +} diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/inherited/api/Base.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/inherited/api/Base.java new file mode 100644 index 00000000000..7c4cf9ede6d --- /dev/null +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/inherited/api/Base.java @@ -0,0 +1,25 @@ +/* + * Copyright (C) 2015 Red Hat, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.fabric8.crd.generator.approvaltests.inherited.api; + +import io.fabric8.kubernetes.api.model.Namespaced; +import io.fabric8.kubernetes.client.CustomResource; + +public abstract class Base + extends CustomResource + implements Namespaced { + +} diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/inherited/api/BaseSpec.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/inherited/api/BaseSpec.java new file mode 100644 index 00000000000..b29b50fd6a4 --- /dev/null +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/inherited/api/BaseSpec.java @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2015 Red Hat, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.fabric8.crd.generator.approvaltests.inherited.api; + +public class BaseSpec { + private int baseInt; + + public int getBaseInt() { + return baseInt; + } + + public void setBaseInt(int baseInt) { + this.baseInt = baseInt; + } +} diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/inherited/api/BaseStatus.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/inherited/api/BaseStatus.java new file mode 100644 index 00000000000..50e38576e64 --- /dev/null +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/inherited/api/BaseStatus.java @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2015 Red Hat, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.fabric8.crd.generator.approvaltests.inherited.api; + +/** + * @author Christophe Laprun + */ +public class BaseStatus { + +} diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/inherited/api/Child.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/inherited/api/Child.java new file mode 100644 index 00000000000..d74849bd67c --- /dev/null +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/inherited/api/Child.java @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2015 Red Hat, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.fabric8.crd.generator.approvaltests.inherited.api; + +import io.fabric8.kubernetes.api.model.Namespaced; +import io.fabric8.kubernetes.model.annotation.Group; +import io.fabric8.kubernetes.model.annotation.Version; + +@Version("v1alpha1") +@Group("sample.fabric8.io") +public class Child extends Base implements Namespaced { + +} diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/inherited/api/ChildSpec.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/inherited/api/ChildSpec.java new file mode 100644 index 00000000000..b6c7da39881 --- /dev/null +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/inherited/api/ChildSpec.java @@ -0,0 +1,24 @@ +/* + * Copyright (C) 2015 Red Hat, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.fabric8.crd.generator.approvaltests.inherited.api; + +import java.util.Map; + +public class ChildSpec extends BaseSpec { + private Map unsupported; + private Map supported; + private Map unsupported2; +} diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/inherited/api/ChildStatus.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/inherited/api/ChildStatus.java new file mode 100644 index 00000000000..2cdf10f8be9 --- /dev/null +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/inherited/api/ChildStatus.java @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2015 Red Hat, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.fabric8.crd.generator.approvaltests.inherited.api; + +/** + * @author Christophe Laprun + */ +public class ChildStatus extends BaseStatus { + +} diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/json/JsonApprovalTest.containingjsons.sample.fabric8.io.v1.approved.yml b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/json/JsonApprovalTest.containingjsons.sample.fabric8.io.v1.approved.yml new file mode 100644 index 00000000000..89592cd1f07 --- /dev/null +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/json/JsonApprovalTest.containingjsons.sample.fabric8.io.v1.approved.yml @@ -0,0 +1,38 @@ +# Generated by Fabric8 CRDGenerator, manual edits might get overwritten! +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + name: containingjsons.sample.fabric8.io +spec: + group: sample.fabric8.io + names: + kind: ContainingJson + plural: containingjsons + singular: containingjson + scope: Cluster + versions: + - name: v1alpha1 + schema: + openAPIV3Schema: + properties: + spec: + properties: + field: + type: integer + foo: + properties: + configAsMap: + additionalProperties: + type: object + type: object + x-kubernetes-preserve-unknown-fields: true + type: object + x-kubernetes-preserve-unknown-fields: true + free: + x-kubernetes-preserve-unknown-fields: true + type: object + status: + type: object + type: object + served: true + storage: true \ No newline at end of file diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/json/JsonApprovalTest.containingjsons.sample.fabric8.io.v1beta1.approved.yml b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/json/JsonApprovalTest.containingjsons.sample.fabric8.io.v1beta1.approved.yml new file mode 100644 index 00000000000..051a0a5934f --- /dev/null +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/json/JsonApprovalTest.containingjsons.sample.fabric8.io.v1beta1.approved.yml @@ -0,0 +1,38 @@ +# Generated by Fabric8 CRDGenerator, manual edits might get overwritten! +apiVersion: apiextensions.k8s.io/v1beta1 +kind: CustomResourceDefinition +metadata: + name: containingjsons.sample.fabric8.io +spec: + group: sample.fabric8.io + names: + kind: ContainingJson + plural: containingjsons + singular: containingjson + scope: Cluster + validation: + openAPIV3Schema: + properties: + spec: + properties: + field: + type: integer + foo: + properties: + configAsMap: + additionalProperties: + type: object + type: object + x-kubernetes-preserve-unknown-fields: true + type: object + x-kubernetes-preserve-unknown-fields: true + free: + x-kubernetes-preserve-unknown-fields: true + type: object + status: + type: object + type: object + versions: + - name: v1alpha1 + served: true + storage: true \ No newline at end of file diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/json/JsonApprovalTest.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/json/JsonApprovalTest.java new file mode 100644 index 00000000000..341e52ff8e0 --- /dev/null +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/json/JsonApprovalTest.java @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2015 Red Hat, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.fabric8.crd.generator.approvaltests.json; + +import io.fabric8.crd.generator.approvaltests.AbstractCRDGeneratorApprovalTest; +import io.fabric8.kubernetes.client.CustomResource; + +class JsonApprovalTest extends AbstractCRDGeneratorApprovalTest { + protected Class>[] crClasses() { + return new Class[] { + io.fabric8.crd.generator.approvaltests.json.api.ContainingJson.class + }; + } + + protected String[] expectedCRDs() { + return new String[] { + "containingjsons.sample.fabric8.io" + }; + } +} diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/json/api/ContainingJson.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/json/api/ContainingJson.java new file mode 100644 index 00000000000..35ddc720e9a --- /dev/null +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/json/api/ContainingJson.java @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2015 Red Hat, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.fabric8.crd.generator.approvaltests.json.api; + +import io.fabric8.kubernetes.client.CustomResource; +import io.fabric8.kubernetes.model.annotation.Group; +import io.fabric8.kubernetes.model.annotation.Version; + +@Group("sample.fabric8.io") +@Version("v1alpha1") +public class ContainingJson extends CustomResource { + +} diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/json/api/ContainingJsonSpec.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/json/api/ContainingJsonSpec.java new file mode 100644 index 00000000000..227e43649e6 --- /dev/null +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/json/api/ContainingJsonSpec.java @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2015 Red Hat, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.fabric8.crd.generator.approvaltests.json.api; + +import com.fasterxml.jackson.databind.JsonNode; + +public class ContainingJsonSpec { + + private int field; + + public int getField() { + return field; + } + + private JsonNode free; + + public JsonNode getFree() { + return free; + } + + private Foo foo; + + public Foo getFoo() { + return foo; + } + +} diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/json/api/Foo.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/json/api/Foo.java new file mode 100644 index 00000000000..be670d35bb8 --- /dev/null +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/json/api/Foo.java @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2015 Red Hat, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.fabric8.crd.generator.approvaltests.json.api; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; + +import java.util.HashMap; +import java.util.Map; + +public class Foo { + + private Map configAsMap = new HashMap<>(); + + @JsonAnyGetter + public Map getConfigAsMap() { + return configAsMap; + } + + @JsonAnySetter + public void setConfigAsMap(String name, Object value) { + this.configAsMap.put(name, value); + } + +} diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/k8svalidation/K8sValidationApprovalTest.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/k8svalidation/K8sValidationApprovalTest.java new file mode 100644 index 00000000000..4dfed1b7c4a --- /dev/null +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/k8svalidation/K8sValidationApprovalTest.java @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2015 Red Hat, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.fabric8.crd.generator.approvaltests.k8svalidation; + +import io.fabric8.crd.generator.approvaltests.AbstractCRDGeneratorApprovalTest; +import io.fabric8.kubernetes.client.CustomResource; + +class K8sValidationApprovalTest extends AbstractCRDGeneratorApprovalTest { + + protected Class>[] crClasses() { + return new Class[] { + io.fabric8.crd.generator.approvaltests.k8svalidation.api.K8sValidation.class + }; + } + + protected String[] expectedCRDs() { + return new String[] { + "k8svalidations.samples.fabric8.io" + }; + } +} diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/k8svalidation/K8sValidationApprovalTest.k8svalidations.samples.fabric8.io.v1.approved.yml b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/k8svalidation/K8sValidationApprovalTest.k8svalidations.samples.fabric8.io.v1.approved.yml new file mode 100644 index 00000000000..7205b7ea70b --- /dev/null +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/k8svalidation/K8sValidationApprovalTest.k8svalidations.samples.fabric8.io.v1.approved.yml @@ -0,0 +1,145 @@ +# Generated by Fabric8 CRDGenerator, manual edits might get overwritten! +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + name: k8svalidations.samples.fabric8.io +spec: + group: samples.fabric8.io + names: + kind: K8sValidation + plural: k8svalidations + singular: k8svalidation + scope: Cluster + versions: + - name: v1alpha1 + schema: + openAPIV3Schema: + properties: + spec: + properties: + deepLevel1: + properties: + deepLevel2: + properties: + simple: + type: string + x-kubernetes-validations: + - rule: self.startsWith('deep-') + valueL2: + type: string + required: + - valueL2 + type: object + valueL1: + type: string + required: + - deepLevel2 + - valueL1 + type: object + x-kubernetes-validations: + - messageExpression: '''valueL1 ('' + self.valueL1 + '') must be equal + to deepLevel2.valueL2 ('' + self.deepLevel2.valueL2 + '')''' + rule: self.valueL1 == self.deepLevel2.valueL2 + immutable: + type: string + x-kubernetes-validations: + - message: cannot be changed once set + rule: self == oldSelf + maxReplicas: + type: integer + minReplicas: + type: integer + monotonicCounter: + type: integer + x-kubernetes-validations: + - message: cannot decrease value once set + reason: FieldValueForbidden + rule: self >= oldSelf + multiple: + type: string + x-kubernetes-validations: + - rule: self.startsWith('start-') + - rule: self.endsWith('-end') + namePrefix: + type: string + onAbstractClass: + properties: + dummy: + type: string + required: + - dummy + type: object + x-kubernetes-validations: + - rule: self.dummy.startsWith('abstract-') + onAttributeAndClass: + properties: + dummy: + type: string + required: + - dummy + type: object + x-kubernetes-validations: + - rule: self.dummy.startsWith('on-class-') + - rule: self.dummy.startsWith('on-attr-') + onAttributeAndGetter: + type: string + x-kubernetes-validations: + - rule: self.startsWith('start-') + - rule: self.endsWith('-end') + onGetter: + type: string + x-kubernetes-validations: + - rule: self.startsWith('on-getter-') + priority: + enum: + - high + - low + - medium + type: string + x-kubernetes-validations: + - message: cannot transition directly between 'low' and 'high' + rule: '!(self == ''high'' && oldSelf == ''low'') && !(self == ''low'' + && oldSelf == ''high'')' + replicas: + type: integer + simple: + type: string + x-kubernetes-validations: + - rule: self.startsWith('simple-') + required: + - deepLevel1 + - maxReplicas + - minReplicas + - multiple + - namePrefix + - onAbstractClass + - onAttributeAndClass + - onAttributeAndGetter + - onGetter + - priority + - replicas + - simple + type: object + x-kubernetes-validations: + - fieldPath: .replicas + rule: self.minReplicas <= self.replicas && self.replicas <= self.maxReplicas + - message: replicas must be greater than or equal to minReplicas + rule: self.minReplicas <= self.replicas + - message: replicas must be smaller than or equal to maxReplicas + rule: self.replicas <= self.maxReplicas + status: + properties: + availableReplicas: + type: integer + type: object + type: object + x-kubernetes-validations: + - messageExpression: '''name must start with '' + self.spec.namePrefix' + reason: FieldValueForbidden + rule: self.metadata.name.startsWith(self.spec.namePrefix) + - message: updates not allowed in degraded state + rule: self.status.availableReplicas >= self.spec.minReplicas + served: true + storage: true + subresources: + status: {} \ No newline at end of file diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/k8svalidation/K8sValidationApprovalTest.k8svalidations.samples.fabric8.io.v1beta1.approved.yml b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/k8svalidation/K8sValidationApprovalTest.k8svalidations.samples.fabric8.io.v1beta1.approved.yml new file mode 100644 index 00000000000..d09c05e9ccb --- /dev/null +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/k8svalidation/K8sValidationApprovalTest.k8svalidations.samples.fabric8.io.v1beta1.approved.yml @@ -0,0 +1,145 @@ +# Generated by Fabric8 CRDGenerator, manual edits might get overwritten! +apiVersion: apiextensions.k8s.io/v1beta1 +kind: CustomResourceDefinition +metadata: + name: k8svalidations.samples.fabric8.io +spec: + group: samples.fabric8.io + names: + kind: K8sValidation + plural: k8svalidations + singular: k8svalidation + scope: Cluster + subresources: + status: {} + validation: + openAPIV3Schema: + properties: + spec: + properties: + deepLevel1: + properties: + deepLevel2: + properties: + simple: + type: string + x-kubernetes-validations: + - rule: self.startsWith('deep-') + valueL2: + type: string + required: + - valueL2 + type: object + valueL1: + type: string + required: + - deepLevel2 + - valueL1 + type: object + x-kubernetes-validations: + - messageExpression: '''valueL1 ('' + self.valueL1 + '') must be equal + to deepLevel2.valueL2 ('' + self.deepLevel2.valueL2 + '')''' + rule: self.valueL1 == self.deepLevel2.valueL2 + immutable: + type: string + x-kubernetes-validations: + - message: cannot be changed once set + rule: self == oldSelf + maxReplicas: + type: integer + minReplicas: + type: integer + monotonicCounter: + type: integer + x-kubernetes-validations: + - message: cannot decrease value once set + reason: FieldValueForbidden + rule: self >= oldSelf + multiple: + type: string + x-kubernetes-validations: + - rule: self.startsWith('start-') + - rule: self.endsWith('-end') + namePrefix: + type: string + onAbstractClass: + properties: + dummy: + type: string + required: + - dummy + type: object + x-kubernetes-validations: + - rule: self.dummy.startsWith('abstract-') + onAttributeAndClass: + properties: + dummy: + type: string + required: + - dummy + type: object + x-kubernetes-validations: + - rule: self.dummy.startsWith('on-class-') + - rule: self.dummy.startsWith('on-attr-') + onAttributeAndGetter: + type: string + x-kubernetes-validations: + - rule: self.startsWith('start-') + - rule: self.endsWith('-end') + onGetter: + type: string + x-kubernetes-validations: + - rule: self.startsWith('on-getter-') + priority: + enum: + - high + - low + - medium + type: string + x-kubernetes-validations: + - message: cannot transition directly between 'low' and 'high' + rule: '!(self == ''high'' && oldSelf == ''low'') && !(self == ''low'' + && oldSelf == ''high'')' + replicas: + type: integer + simple: + type: string + x-kubernetes-validations: + - rule: self.startsWith('simple-') + required: + - deepLevel1 + - maxReplicas + - minReplicas + - multiple + - namePrefix + - onAbstractClass + - onAttributeAndClass + - onAttributeAndGetter + - onGetter + - priority + - replicas + - simple + type: object + x-kubernetes-validations: + - fieldPath: .replicas + rule: self.minReplicas <= self.replicas && self.replicas <= self.maxReplicas + - message: replicas must be greater than or equal to minReplicas + rule: self.minReplicas <= self.replicas + - message: replicas must be smaller than or equal to maxReplicas + rule: self.replicas <= self.maxReplicas + status: + properties: + availableReplicas: + type: integer + type: object + type: object + x-kubernetes-validations: + - messageExpression: '''name must start with '' + self.spec.namePrefix' + reason: FieldValueForbidden + rule: self.metadata.name.startsWith(self.spec.namePrefix) + - message: updates not allowed in degraded state + rule: self.status.availableReplicas >= self.spec.minReplicas + versions: + - name: v1alpha1 + served: true + storage: true \ No newline at end of file diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/k8svalidation/api/K8sValidation.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/k8svalidation/api/K8sValidation.java new file mode 100644 index 00000000000..3e8ec8fdbfa --- /dev/null +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/k8svalidation/api/K8sValidation.java @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2015 Red Hat, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.fabric8.crd.generator.approvaltests.k8svalidation.api; + +import io.fabric8.generator.annotation.ValidationRule; +import io.fabric8.kubernetes.client.CustomResource; +import io.fabric8.kubernetes.model.annotation.Group; +import io.fabric8.kubernetes.model.annotation.Version; + +@Group("samples.fabric8.io") +@Version("v1alpha1") +@ValidationRule(value = "self.metadata.name.startsWith(self.spec.namePrefix)", messageExpression = "'name must start with ' + self.spec.namePrefix", reason = "FieldValueForbidden") +@ValidationRule(value = "self.status.availableReplicas >= self.spec.minReplicas", message = "updates not allowed in degraded state") +public class K8sValidation extends CustomResource { + + @Override + @ValidationRule(value = "self.minReplicas <= self.replicas", message = "replicas must be greater than or equal to minReplicas") + @ValidationRule(value = "self.replicas <= self.maxReplicas", message = "replicas must be smaller than or equal to maxReplicas") + public K8sValidationSpec getSpec() { + return super.getSpec(); + } +} diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/k8svalidation/api/K8sValidationSpec.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/k8svalidation/api/K8sValidationSpec.java new file mode 100644 index 00000000000..39fa11fc9c8 --- /dev/null +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/k8svalidation/api/K8sValidationSpec.java @@ -0,0 +1,117 @@ +/* + * Copyright (C) 2015 Red Hat, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.fabric8.crd.generator.approvaltests.k8svalidation.api; + +import io.fabric8.generator.annotation.Required; +import io.fabric8.generator.annotation.ValidationRule; + +@ValidationRule(value = "self.minReplicas <= self.replicas && self.replicas <= self.maxReplicas", fieldPath = ".replicas") +public class K8sValidationSpec { + @Required + String namePrefix; + @Required + Integer replicas; + @Required + Integer minReplicas; + @Required + Integer maxReplicas; + + @Required + @ValidationRule("self.startsWith('simple-')") + private String simple; + + // see getter + private String onGetter; + + @Required + @ValidationRule("self.startsWith('start-')") + @ValidationRule("self.endsWith('-end')") + private String multiple; + + @Required + @ValidationRule("self.startsWith('start-')") + private String onAttributeAndGetter; + + @Required + @ValidationRule(value = "self.valueL1 == self.deepLevel2.valueL2", messageExpression = "'valueL1 (' + self.valueL1 + ') must be equal to deepLevel2.valueL2 (' + self.deepLevel2.valueL2 + ')'") + private DeepLevel1 deepLevel1; + + @Required + @ValidationRule("self.dummy.startsWith('on-attr-')") + private OnClass onAttributeAndClass; + + @Required + private ClassWithValidationsFromAbstractClass onAbstractClass; + + // transition rules + @ValidationRule(value = "self == oldSelf", message = "cannot be changed once set") + private String immutable; + @Required + @ValidationRule(value = "!(self == 'high' && oldSelf == 'low') && !(self == 'low' && oldSelf == 'high')", message = "cannot transition directly between 'low' and 'high'") + private Priority priority; + @ValidationRule(value = "self >= oldSelf", message = "cannot decrease value once set", reason = "FieldValueForbidden") + private Integer monotonicCounter; + + @Required + @ValidationRule("self.startsWith('on-getter-')") + public String getOnGetter() { + return onGetter; + } + + @ValidationRule("self.endsWith('-end')") + public String getOnAttributeAndGetter() { + return onAttributeAndGetter; + } + + enum Priority { + low, + medium, + high + } + + static class DeepLevel1 { + @Required + private String valueL1; + + @Required + private DeepLevel2 deepLevel2; + } + + static class DeepLevel2 { + @Required + private String valueL2; + + @ValidationRule("self.startsWith('deep-')") + private String simple; + + } + + @ValidationRule("self.dummy.startsWith('on-class-')") + static class OnClass { + @Required + private String dummy; + } + + static class ClassWithValidationsFromAbstractClass extends AbstractBase { + + } + + @ValidationRule("self.dummy.startsWith('abstract-')") + static abstract class AbstractBase { + @Required + private String dummy; + } +} diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/k8svalidation/api/K8sValidationStatus.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/k8svalidation/api/K8sValidationStatus.java new file mode 100644 index 00000000000..86e26bcc5f5 --- /dev/null +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/k8svalidation/api/K8sValidationStatus.java @@ -0,0 +1,20 @@ +/* + * Copyright (C) 2015 Red Hat, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.fabric8.crd.generator.approvaltests.k8svalidation.api; + +public class K8sValidationStatus { + Integer availableReplicas; +} diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/map/MapApprovalTest.containingmaps.sample.fabric8.io.v1.approved.yml b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/map/MapApprovalTest.containingmaps.sample.fabric8.io.v1.approved.yml new file mode 100644 index 00000000000..3a65e673ccf --- /dev/null +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/map/MapApprovalTest.containingmaps.sample.fabric8.io.v1.approved.yml @@ -0,0 +1,85 @@ +# Generated by Fabric8 CRDGenerator, manual edits might get overwritten! +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + name: containingmaps.sample.fabric8.io +spec: + group: sample.fabric8.io + names: + kind: ContainingMaps + plural: containingmaps + singular: containingmaps + scope: Cluster + versions: + - name: v1alpha1 + schema: + openAPIV3Schema: + properties: + enumToStringMap: + additionalProperties: + type: string + type: object + spec: + properties: + stringToIntMultiMap1: + additionalProperties: + items: + type: integer + type: array + type: object + stringToIntMultiMap2: + additionalProperties: + items: + type: integer + type: array + type: object + stringToIntMultiMap3: + additionalProperties: + items: + type: integer + type: array + type: object + stringToIntMultiMap4: + additionalProperties: + items: + type: integer + type: array + type: object + stringToIntMultiMap5: + additionalProperties: + items: + type: integer + type: array + type: object + stringToIntMultiMap6: + additionalProperties: + items: + type: integer + type: array + type: object + stringToIntMultiMap7: + additionalProperties: + items: + type: integer + type: array + type: object + test: + additionalProperties: + items: + type: string + type: array + type: object + test2: + additionalProperties: + additionalProperties: + items: + type: boolean + type: array + type: object + type: object + type: object + status: + type: object + type: object + served: true + storage: true \ No newline at end of file diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/map/MapApprovalTest.containingmaps.sample.fabric8.io.v1beta1.approved.yml b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/map/MapApprovalTest.containingmaps.sample.fabric8.io.v1beta1.approved.yml new file mode 100644 index 00000000000..97cf0fd7efd --- /dev/null +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/map/MapApprovalTest.containingmaps.sample.fabric8.io.v1beta1.approved.yml @@ -0,0 +1,85 @@ +# Generated by Fabric8 CRDGenerator, manual edits might get overwritten! +apiVersion: apiextensions.k8s.io/v1beta1 +kind: CustomResourceDefinition +metadata: + name: containingmaps.sample.fabric8.io +spec: + group: sample.fabric8.io + names: + kind: ContainingMaps + plural: containingmaps + singular: containingmaps + scope: Cluster + validation: + openAPIV3Schema: + properties: + enumToStringMap: + additionalProperties: + type: string + type: object + spec: + properties: + stringToIntMultiMap1: + additionalProperties: + items: + type: integer + type: array + type: object + stringToIntMultiMap2: + additionalProperties: + items: + type: integer + type: array + type: object + stringToIntMultiMap3: + additionalProperties: + items: + type: integer + type: array + type: object + stringToIntMultiMap4: + additionalProperties: + items: + type: integer + type: array + type: object + stringToIntMultiMap5: + additionalProperties: + items: + type: integer + type: array + type: object + stringToIntMultiMap6: + additionalProperties: + items: + type: integer + type: array + type: object + stringToIntMultiMap7: + additionalProperties: + items: + type: integer + type: array + type: object + test: + additionalProperties: + items: + type: string + type: array + type: object + test2: + additionalProperties: + additionalProperties: + items: + type: boolean + type: array + type: object + type: object + type: object + status: + type: object + type: object + versions: + - name: v1alpha1 + served: true + storage: true \ No newline at end of file diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/map/MapApprovalTest.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/map/MapApprovalTest.java new file mode 100644 index 00000000000..84b8f7d7331 --- /dev/null +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/map/MapApprovalTest.java @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2015 Red Hat, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.fabric8.crd.generator.approvaltests.map; + +import io.fabric8.crd.generator.approvaltests.AbstractCRDGeneratorApprovalTest; +import io.fabric8.kubernetes.client.CustomResource; + +class MapApprovalTest extends AbstractCRDGeneratorApprovalTest { + protected Class>[] crClasses() { + return new Class[] { + io.fabric8.crd.generator.approvaltests.map.api.ContainingMaps.class + }; + } + + protected String[] expectedCRDs() { + return new String[] { + "containingmaps.sample.fabric8.io" + }; + } +} diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/map/api/ContainingMaps.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/map/api/ContainingMaps.java new file mode 100644 index 00000000000..a2229fa2119 --- /dev/null +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/map/api/ContainingMaps.java @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2015 Red Hat, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.fabric8.crd.generator.approvaltests.map.api; + +import io.fabric8.kubernetes.client.CustomResource; +import io.fabric8.kubernetes.model.annotation.Group; +import io.fabric8.kubernetes.model.annotation.Version; + +import java.util.EnumMap; + +@Group("sample.fabric8.io") +@Version("v1alpha1") +public class ContainingMaps extends CustomResource { + + public enum Foo { + BAR + } + + private EnumMap enumToStringMap; + +} diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/map/api/ContainingMapsSpec.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/map/api/ContainingMapsSpec.java new file mode 100644 index 00000000000..bf4b458dced --- /dev/null +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/map/api/ContainingMapsSpec.java @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2015 Red Hat, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.fabric8.crd.generator.approvaltests.map.api; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class ContainingMapsSpec { + + private Map> test = null; + + public Map> getTest() { + return test; + } + + private Map>> test2 = null; + + public Map>> getTest2() { + return test2; + } + + private MultiHashMap stringToIntMultiMap1; + private MultiMap stringToIntMultiMap2; + private SwappedParametersMap, String> stringToIntMultiMap3; + private RedundantParametersMap> stringToIntMultiMap4; + private RedundantParametersStringToIntMultiMap stringToIntMultiMap5; + private StringKeyedMultiHashMap stringToIntMultiMap6; + private IntValuedMultiMap stringToIntMultiMap7; + + static class MultiHashMap extends HashMap> { + } + + interface MultiMap extends Map> { + } + + interface SwappedParametersMap extends Map { + } + + interface RedundantParametersMap extends Map { + } + + interface RedundantParametersStringToIntMultiMap extends Map> { + } + + static class StringKeyedMultiHashMap extends MultiHashMap { + } + + interface IntValuedMultiMap extends MultiMap { + } +} diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/multipleversions/MultipleVersionsApprovalTest.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/multipleversions/MultipleVersionsApprovalTest.java new file mode 100644 index 00000000000..52810d2a88d --- /dev/null +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/multipleversions/MultipleVersionsApprovalTest.java @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2015 Red Hat, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.fabric8.crd.generator.approvaltests.multipleversions; + +import io.fabric8.crd.generator.approvaltests.AbstractCRDGeneratorApprovalTest; +import io.fabric8.kubernetes.client.CustomResource; + +class MultipleVersionsApprovalTest extends AbstractCRDGeneratorApprovalTest { + + protected Class>[] crClasses() { + return new Class[] { + io.fabric8.crd.generator.approvaltests.multipleversions.api.v1.Multiple.class, + io.fabric8.crd.generator.approvaltests.multipleversions.api.v2.Multiple.class + }; + } + + protected String[] expectedCRDs() { + return new String[] { + "multiples.sample.fabric8.io" + }; + } +} diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/multipleversions/MultipleVersionsApprovalTest.multiples.sample.fabric8.io.v1.approved.yml b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/multipleversions/MultipleVersionsApprovalTest.multiples.sample.fabric8.io.v1.approved.yml new file mode 100644 index 00000000000..b94afd65aed --- /dev/null +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/multipleversions/MultipleVersionsApprovalTest.multiples.sample.fabric8.io.v1.approved.yml @@ -0,0 +1,42 @@ +# Generated by Fabric8 CRDGenerator, manual edits might get overwritten! +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + name: multiples.sample.fabric8.io +spec: + group: sample.fabric8.io + names: + kind: Multiple + plural: multiples + singular: multiple + scope: Cluster + versions: + - name: v2 + schema: + openAPIV3Schema: + properties: + spec: + properties: + v2: + type: string + type: object + status: + type: object + type: object + served: true + storage: true + - deprecated: true + name: v1 + schema: + openAPIV3Schema: + properties: + spec: + properties: + v1: + type: string + type: object + status: + type: object + type: object + served: true + storage: false diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/multipleversions/MultipleVersionsApprovalTest.multiples.sample.fabric8.io.v1beta1.approved.yml b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/multipleversions/MultipleVersionsApprovalTest.multiples.sample.fabric8.io.v1beta1.approved.yml new file mode 100644 index 00000000000..496bc0f8362 --- /dev/null +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/multipleversions/MultipleVersionsApprovalTest.multiples.sample.fabric8.io.v1beta1.approved.yml @@ -0,0 +1,42 @@ +# Generated by Fabric8 CRDGenerator, manual edits might get overwritten! +apiVersion: apiextensions.k8s.io/v1beta1 +kind: CustomResourceDefinition +metadata: + name: multiples.sample.fabric8.io +spec: + group: sample.fabric8.io + names: + kind: Multiple + plural: multiples + singular: multiple + scope: Cluster + versions: + - name: v2 + schema: + openAPIV3Schema: + properties: + spec: + properties: + v2: + type: string + type: object + status: + type: object + type: object + served: true + storage: true + - deprecated: true + name: v1 + schema: + openAPIV3Schema: + properties: + spec: + properties: + v1: + type: string + type: object + status: + type: object + type: object + served: true + storage: false diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/multipleversions/api/v1/Multiple.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/multipleversions/api/v1/Multiple.java new file mode 100644 index 00000000000..e963c9e202b --- /dev/null +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/multipleversions/api/v1/Multiple.java @@ -0,0 +1,25 @@ +/* + * Copyright (C) 2015 Red Hat, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.fabric8.crd.generator.approvaltests.multipleversions.api.v1; + +import io.fabric8.kubernetes.client.CustomResource; +import io.fabric8.kubernetes.model.annotation.Group; +import io.fabric8.kubernetes.model.annotation.Version; + +@Group("sample.fabric8.io") +@Version(value = "v1", storage = false, deprecated = true) +public class Multiple extends CustomResource { +} diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/ParallelCRDGeneratorExamplesTest.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/multipleversions/api/v1/MultipleSpec.java similarity index 75% rename from crd-generator/api/src/test/java/io/fabric8/crd/generator/ParallelCRDGeneratorExamplesTest.java rename to crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/multipleversions/api/v1/MultipleSpec.java index 2073b71b7a8..88287e68eea 100644 --- a/crd-generator/api/src/test/java/io/fabric8/crd/generator/ParallelCRDGeneratorExamplesTest.java +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/multipleversions/api/v1/MultipleSpec.java @@ -13,10 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.fabric8.crd.generator; +package io.fabric8.crd.generator.approvaltests.multipleversions.api.v1; -public class ParallelCRDGeneratorExamplesTest extends CRDGeneratorExamplesTest { - public ParallelCRDGeneratorExamplesTest() { - parallelCRDGeneration = true; +public class MultipleSpec { + private String v1; + + public String getV1() { + return v1; } } diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/multipleversions/api/v2/Multiple.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/multipleversions/api/v2/Multiple.java new file mode 100644 index 00000000000..9f36a9a09a8 --- /dev/null +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/multipleversions/api/v2/Multiple.java @@ -0,0 +1,25 @@ +/* + * Copyright (C) 2015 Red Hat, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.fabric8.crd.generator.approvaltests.multipleversions.api.v2; + +import io.fabric8.kubernetes.client.CustomResource; +import io.fabric8.kubernetes.model.annotation.Group; +import io.fabric8.kubernetes.model.annotation.Version; + +@Group("sample.fabric8.io") +@Version("v2") +public class Multiple extends CustomResource { +} diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/multipleversions/api/v2/MultipleSpec.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/multipleversions/api/v2/MultipleSpec.java new file mode 100644 index 00000000000..e3a59d01e00 --- /dev/null +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/multipleversions/api/v2/MultipleSpec.java @@ -0,0 +1,24 @@ +/* + * Copyright (C) 2015 Red Hat, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.fabric8.crd.generator.approvaltests.multipleversions.api.v2; + +public class MultipleSpec { + private String v2; + + public String getV2() { + return v2; + } +} diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/nocyclic/NoCyclicApprovalTest.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/nocyclic/NoCyclicApprovalTest.java new file mode 100644 index 00000000000..b578aa800f4 --- /dev/null +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/nocyclic/NoCyclicApprovalTest.java @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2015 Red Hat, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.fabric8.crd.generator.approvaltests.nocyclic; + +import io.fabric8.crd.generator.approvaltests.AbstractCRDGeneratorApprovalTest; +import io.fabric8.kubernetes.client.CustomResource; + +class NoCyclicApprovalTest extends AbstractCRDGeneratorApprovalTest { + protected Class>[] crClasses() { + return new Class[] { + io.fabric8.crd.generator.approvaltests.nocyclic.api.NoCyclic.class + }; + } + + protected String[] expectedCRDs() { + return new String[] { + "nocyclics.sample.fabric8.io" + }; + } +} diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/nocyclic/NoCyclicApprovalTest.nocyclics.sample.fabric8.io.v1.approved.yml b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/nocyclic/NoCyclicApprovalTest.nocyclics.sample.fabric8.io.v1.approved.yml new file mode 100644 index 00000000000..3d40aa4f5c6 --- /dev/null +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/nocyclic/NoCyclicApprovalTest.nocyclics.sample.fabric8.io.v1.approved.yml @@ -0,0 +1,51 @@ +# Generated by Fabric8 CRDGenerator, manual edits might get overwritten! +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + name: nocyclics.sample.fabric8.io +spec: + group: sample.fabric8.io + names: + kind: NoCyclic + plural: nocyclics + singular: nocyclic + scope: Namespaced + versions: + - name: v1alpha1 + schema: + openAPIV3Schema: + properties: + spec: + properties: + ref1: + properties: + inner: + type: object + ref: + type: integer + type: object + ref2: + properties: + inner: + type: object + ref: + type: integer + type: object + type: object + status: + properties: + message: + type: string + ref1: + properties: + inner: + type: object + ref: + type: integer + type: object + type: object + type: object + served: true + storage: true + subresources: + status: {} \ No newline at end of file diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/nocyclic/NoCyclicApprovalTest.nocyclics.sample.fabric8.io.v1beta1.approved.yml b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/nocyclic/NoCyclicApprovalTest.nocyclics.sample.fabric8.io.v1beta1.approved.yml new file mode 100644 index 00000000000..546f2ccd875 --- /dev/null +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/nocyclic/NoCyclicApprovalTest.nocyclics.sample.fabric8.io.v1beta1.approved.yml @@ -0,0 +1,51 @@ +# Generated by Fabric8 CRDGenerator, manual edits might get overwritten! +apiVersion: apiextensions.k8s.io/v1beta1 +kind: CustomResourceDefinition +metadata: + name: nocyclics.sample.fabric8.io +spec: + group: sample.fabric8.io + names: + kind: NoCyclic + plural: nocyclics + singular: nocyclic + scope: Namespaced + subresources: + status: {} + validation: + openAPIV3Schema: + properties: + spec: + properties: + ref1: + properties: + inner: + type: object + ref: + type: integer + type: object + ref2: + properties: + inner: + type: object + ref: + type: integer + type: object + type: object + status: + properties: + message: + type: string + ref1: + properties: + inner: + type: object + ref: + type: integer + type: object + type: object + type: object + versions: + - name: v1alpha1 + served: true + storage: true \ No newline at end of file diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/nocyclic/api/NoCyclic.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/nocyclic/api/NoCyclic.java new file mode 100644 index 00000000000..48258fc47e4 --- /dev/null +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/nocyclic/api/NoCyclic.java @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2015 Red Hat, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.fabric8.crd.generator.approvaltests.nocyclic.api; + +import io.fabric8.kubernetes.api.model.Namespaced; +import io.fabric8.kubernetes.client.CustomResource; +import io.fabric8.kubernetes.model.annotation.Group; +import io.fabric8.kubernetes.model.annotation.Version; + +@Group("sample.fabric8.io") +@Version("v1alpha1") +public class NoCyclic extends CustomResource implements Namespaced { + +} diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/nocyclic/api/NoCyclicSpec.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/nocyclic/api/NoCyclicSpec.java new file mode 100644 index 00000000000..7f93f98fbb5 --- /dev/null +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/nocyclic/api/NoCyclicSpec.java @@ -0,0 +1,21 @@ +/* + * Copyright (C) 2015 Red Hat, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.fabric8.crd.generator.approvaltests.nocyclic.api; + +public class NoCyclicSpec { + private Ref ref1; + private Ref ref2; +} diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/nocyclic/api/NoCyclicStatus.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/nocyclic/api/NoCyclicStatus.java new file mode 100644 index 00000000000..fa97cfc0d2c --- /dev/null +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/nocyclic/api/NoCyclicStatus.java @@ -0,0 +1,21 @@ +/* + * Copyright (C) 2015 Red Hat, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.fabric8.crd.generator.approvaltests.nocyclic.api; + +public class NoCyclicStatus { + private String message; + private Ref ref1; +} diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/nocyclic/api/Ref.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/nocyclic/api/Ref.java new file mode 100644 index 00000000000..247df80eaa0 --- /dev/null +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/nocyclic/api/Ref.java @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2015 Red Hat, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.fabric8.crd.generator.approvaltests.nocyclic.api; + +public class Ref { + + private int ref; + + protected Inner inner; + + public static class Inner { + } + +} diff --git a/pom.xml b/pom.xml index 53cb5198cea..d0eb9fc936c 100644 --- a/pom.xml +++ b/pom.xml @@ -1251,6 +1251,8 @@ kubernetes-client/src/test/resources/mockito-extensions/* **/src/test/resources/ssl/* **/src/test/resources/io/fabric8/java/generator/approvals/*.*.approved.txt + crd-generator/api/src/test/java/**/*.approved.yml + crd-generator/apt/src/test/java/**/*.approved.yml **/it/**/expected/**/*.expected Jenkinsfile .mvn/**/* From cd47c6f6b84b469ea37d70dbe125a7c8cc484eda Mon Sep 17 00:00:00 2001 From: Marc Nuri Date: Fri, 26 Apr 2024 11:33:05 +0200 Subject: [PATCH 05/11] test(crd-generator): MultipleStoredVersionsTest uses parameters Signed-off-by: Marc Nuri --- crd-generator/api/pom.xml | 10 +++++ .../generator/MultipleStoredVersionsTest.java | 43 ++++++++----------- 2 files changed, 29 insertions(+), 24 deletions(-) diff --git a/crd-generator/api/pom.xml b/crd-generator/api/pom.xml index 280393fa40e..6000dfd0cb1 100644 --- a/crd-generator/api/pom.xml +++ b/crd-generator/api/pom.xml @@ -76,6 +76,16 @@ junit-jupiter-engine test + + org.junit.jupiter + junit-jupiter-params + test + + + org.assertj + assertj-core + test + org.slf4j slf4j-simple diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/MultipleStoredVersionsTest.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/MultipleStoredVersionsTest.java index ef0adf3ef3a..099af018ee3 100644 --- a/crd-generator/api/src/test/java/io/fabric8/crd/generator/MultipleStoredVersionsTest.java +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/MultipleStoredVersionsTest.java @@ -19,12 +19,16 @@ import io.fabric8.kubernetes.client.CustomResource; import io.fabric8.kubernetes.model.annotation.Group; import io.fabric8.kubernetes.model.annotation.Version; -import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.io.TempDir; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; import java.io.File; +import java.util.stream.Stream; -import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.assertj.core.api.Assertions.assertThatIllegalStateException; class MultipleStoredVersionsTest { @@ -33,33 +37,24 @@ class MultipleStoredVersionsTest { public static class Multiple extends CustomResource { } - @Test - void generateV1_expectException(@TempDir File tmpDir) { - test("v1", false, tmpDir); - } - - @Test - void generateV1beta1_expectException(@TempDir File tmpDir) { - test("v1beta1", false, tmpDir); - } - - @Test - void generateV1Parallel_expectException(@TempDir File tmpDir) { - test("v1", true, tmpDir); - } - - @Test - void generateV1beta1Parallel_expectException(@TempDir File tmpDir) { - test("v1beta1", true, tmpDir); - } - - private void test(String crdVersion, boolean parallel, File tmpDir) { + @ParameterizedTest(name = "{index}: version: {0}, parallel: {1}") + @DisplayName("Generate CRD for multiple stored versions throws exception") + @MethodSource("multipleCrdVersions") + void generateMultipleThrowsException(String crdVersion, boolean parallel, @TempDir File tmpDir) { final CRDGenerator crdGenerator = new CRDGenerator() .inOutputDir(tmpDir) .withParallelGenerationEnabled(parallel) .forCRDVersions(crdVersion) .customResourceClasses(io.fabric8.crd.example.multiple.v2.Multiple.class, Multiple.class); + assertThatIllegalStateException() + .isThrownBy(crdGenerator::generate) + .withMessageContaining("Only one version can be marked as storage per custom resource."); + } - assertThrows(IllegalStateException.class, crdGenerator::generate); + static Stream multipleCrdVersions() { + return Stream.of("v1", "v1beta1") + .flatMap(crdVersion -> Stream.of( + Arguments.of(crdVersion, false), + Arguments.of(crdVersion, true))); } } From b948114adbb19ac6c0b3fdaa802d4430e1bcd707 Mon Sep 17 00:00:00 2001 From: Marc Nuri Date: Fri, 26 Apr 2024 16:08:39 +0200 Subject: [PATCH 06/11] test(crd-generator): simplify crd generator approval tests Signed-off-by: Marc Nuri --- .../AbstractCRDGeneratorApprovalTest.java | 143 ------------------ .../CRDGeneratorApprovalNamer.java | 82 ---------- .../CRDGeneratorApprovalTest.java | 108 +++++++++++++ .../approvaltests/PackageSettings.java | 1 + .../annotated/AnnotatedApprovalTest.java | 34 ----- .../complex/ComplexApprovalTest.java | 33 ---- .../inherited/InheritedApprovalTest.java | 33 ---- .../approvaltests/json/JsonApprovalTest.java | 33 ---- .../K8sValidationApprovalTest.java | 34 ----- .../approvaltests/map/MapApprovalTest.java | 33 ---- .../MultipleVersionsApprovalTest.java | 35 ----- .../nocyclic/NoCyclicApprovalTest.java | 33 ---- ...tateds.samples.fabric8.io.v1.approved.txt} | 2 +- ...s.samples.fabric8.io.v1beta1.approved.txt} | 2 +- ...hildren.sample.fabric8.io.v1.approved.txt} | 0 ...en.sample.fabric8.io.v1beta1.approved.txt} | 0 ...xkinds.samples.fabric8.io.v1.approved.txt} | 0 ...s.samples.fabric8.io.v1beta1.approved.txt} | 0 ...ngjsons.sample.fabric8.io.v1.approved.txt} | 0 ...ns.sample.fabric8.io.v1beta1.approved.txt} | 0 ...ingmaps.sample.fabric8.io.v1.approved.txt} | 0 ...ps.sample.fabric8.io.v1beta1.approved.txt} | 0 ...ations.samples.fabric8.io.v1.approved.txt} | 0 ...s.samples.fabric8.io.v1beta1.approved.txt} | 2 +- ...ltiples.sample.fabric8.io.v1.approved.txt} | 0 ...es.sample.fabric8.io.v1beta1.approved.txt} | 0 ...cyclics.sample.fabric8.io.v1.approved.txt} | 0 ...cs.sample.fabric8.io.v1beta1.approved.txt} | 0 pom.xml | 3 +- 29 files changed, 113 insertions(+), 498 deletions(-) delete mode 100644 crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/AbstractCRDGeneratorApprovalTest.java delete mode 100644 crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalNamer.java create mode 100644 crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.java delete mode 100644 crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/annotated/AnnotatedApprovalTest.java delete mode 100644 crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/ComplexApprovalTest.java delete mode 100644 crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/inherited/InheritedApprovalTest.java delete mode 100644 crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/json/JsonApprovalTest.java delete mode 100644 crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/k8svalidation/K8sValidationApprovalTest.java delete mode 100644 crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/map/MapApprovalTest.java delete mode 100644 crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/multipleversions/MultipleVersionsApprovalTest.java delete mode 100644 crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/nocyclic/NoCyclicApprovalTest.java rename crd-generator/api/src/test/{java/io/fabric8/crd/generator/approvaltests/annotated/AnnotatedApprovalTest.annotateds.samples.fabric8.io.v1.approved.yml => resources/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.approvalTest.annotateds.samples.fabric8.io.v1.approved.txt} (99%) rename crd-generator/api/src/test/{java/io/fabric8/crd/generator/approvaltests/annotated/AnnotatedApprovalTest.annotateds.samples.fabric8.io.v1beta1.approved.yml => resources/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.approvalTest.annotateds.samples.fabric8.io.v1beta1.approved.txt} (99%) rename crd-generator/api/src/test/{java/io/fabric8/crd/generator/approvaltests/inherited/InheritedApprovalTest.children.sample.fabric8.io.v1.approved.yml => resources/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.approvalTest.children.sample.fabric8.io.v1.approved.txt} (100%) rename crd-generator/api/src/test/{java/io/fabric8/crd/generator/approvaltests/inherited/InheritedApprovalTest.children.sample.fabric8.io.v1beta1.approved.yml => resources/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.approvalTest.children.sample.fabric8.io.v1beta1.approved.txt} (100%) rename crd-generator/api/src/test/{java/io/fabric8/crd/generator/approvaltests/complex/ComplexApprovalTest.complexkinds.samples.fabric8.io.v1.approved.yml => resources/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.approvalTest.complexkinds.samples.fabric8.io.v1.approved.txt} (100%) rename crd-generator/api/src/test/{java/io/fabric8/crd/generator/approvaltests/complex/ComplexApprovalTest.complexkinds.samples.fabric8.io.v1beta1.approved.yml => resources/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.approvalTest.complexkinds.samples.fabric8.io.v1beta1.approved.txt} (100%) rename crd-generator/api/src/test/{java/io/fabric8/crd/generator/approvaltests/json/JsonApprovalTest.containingjsons.sample.fabric8.io.v1.approved.yml => resources/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.approvalTest.containingjsons.sample.fabric8.io.v1.approved.txt} (100%) rename crd-generator/api/src/test/{java/io/fabric8/crd/generator/approvaltests/json/JsonApprovalTest.containingjsons.sample.fabric8.io.v1beta1.approved.yml => resources/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.approvalTest.containingjsons.sample.fabric8.io.v1beta1.approved.txt} (100%) rename crd-generator/api/src/test/{java/io/fabric8/crd/generator/approvaltests/map/MapApprovalTest.containingmaps.sample.fabric8.io.v1.approved.yml => resources/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.approvalTest.containingmaps.sample.fabric8.io.v1.approved.txt} (100%) rename crd-generator/api/src/test/{java/io/fabric8/crd/generator/approvaltests/map/MapApprovalTest.containingmaps.sample.fabric8.io.v1beta1.approved.yml => resources/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.approvalTest.containingmaps.sample.fabric8.io.v1beta1.approved.txt} (100%) rename crd-generator/api/src/test/{java/io/fabric8/crd/generator/approvaltests/k8svalidation/K8sValidationApprovalTest.k8svalidations.samples.fabric8.io.v1.approved.yml => resources/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.approvalTest.k8svalidations.samples.fabric8.io.v1.approved.txt} (100%) rename crd-generator/api/src/test/{java/io/fabric8/crd/generator/approvaltests/k8svalidation/K8sValidationApprovalTest.k8svalidations.samples.fabric8.io.v1beta1.approved.yml => resources/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.approvalTest.k8svalidations.samples.fabric8.io.v1beta1.approved.txt} (99%) rename crd-generator/api/src/test/{java/io/fabric8/crd/generator/approvaltests/multipleversions/MultipleVersionsApprovalTest.multiples.sample.fabric8.io.v1.approved.yml => resources/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.approvalTest.multiples.sample.fabric8.io.v1.approved.txt} (100%) rename crd-generator/api/src/test/{java/io/fabric8/crd/generator/approvaltests/multipleversions/MultipleVersionsApprovalTest.multiples.sample.fabric8.io.v1beta1.approved.yml => resources/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.approvalTest.multiples.sample.fabric8.io.v1beta1.approved.txt} (100%) rename crd-generator/api/src/test/{java/io/fabric8/crd/generator/approvaltests/nocyclic/NoCyclicApprovalTest.nocyclics.sample.fabric8.io.v1.approved.yml => resources/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.approvalTest.nocyclics.sample.fabric8.io.v1.approved.txt} (100%) rename crd-generator/api/src/test/{java/io/fabric8/crd/generator/approvaltests/nocyclic/NoCyclicApprovalTest.nocyclics.sample.fabric8.io.v1beta1.approved.yml => resources/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.approvalTest.nocyclics.sample.fabric8.io.v1beta1.approved.txt} (100%) diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/AbstractCRDGeneratorApprovalTest.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/AbstractCRDGeneratorApprovalTest.java deleted file mode 100644 index 16dfb0fc4e7..00000000000 --- a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/AbstractCRDGeneratorApprovalTest.java +++ /dev/null @@ -1,143 +0,0 @@ -package io.fabric8.crd.generator.approvaltests; - -/* - * Copyright (C) 2015 Red Hat, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import io.fabric8.crd.generator.CRDGenerationInfo; -import io.fabric8.crd.generator.CRDGenerator; -import io.fabric8.crd.generator.CRDInfo; -import io.fabric8.kubernetes.client.CustomResource; -import org.approvaltests.Approvals; -import org.approvaltests.approvers.ApprovalApprover; -import org.approvaltests.approvers.FileApprover; -import org.approvaltests.core.Options; -import org.approvaltests.namer.ApprovalNamer; -import org.approvaltests.writers.ApprovalTextWriter; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.TestInstance; - -import java.io.BufferedReader; -import java.io.File; -import java.io.IOException; -import java.io.InputStreamReader; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.Comparator; -import java.util.Map; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.jupiter.api.Assertions.fail; - -@TestInstance(TestInstance.Lifecycle.PER_CLASS) -public abstract class AbstractCRDGeneratorApprovalTest { - - private static final String[] CRD_VERSIONS = new String[] { - "v1", "v1beta1" - }; - - protected abstract Class>[] crClasses(); - - protected abstract String[] expectedCRDs(); - - @BeforeAll - public void init() { - // Allow using the same approval files for this class multiple times (required for parallel testing) - String className = getClass().getName().replace('.', File.separatorChar); - FileApprover.tracker.addAllowedDuplicates(f -> f.contains(className)); - } - - @Test - public void test() { - test(false); - } - - @Test - public void testParallel() { - test(true); - } - - public void test(boolean parallel) { - Class>[] crClasses = crClasses(); - assertNotNull(crClasses); - assertTrue(crClasses.length > 0); - - final File outputDir; - try { - outputDir = Files.createTempDirectory("crd-").toFile(); - } catch (IOException e) { - fail("Could not create temp directory", e); - throw new RuntimeException(e); - } - - // generate actual CRDs - final CRDGenerationInfo crdGenerationInfo = new CRDGenerator() - .withParallelGenerationEnabled(parallel) - .inOutputDir(outputDir) - .customResourceClasses(crClasses) - .forCRDVersions(CRD_VERSIONS) - .detailedGenerate(); - - for (String crdName : expectedCRDs()) { - Map> crdDetails = crdGenerationInfo.getCRDDetailsPerNameAndVersion(); - Map crdInfos = crdDetails.get(crdName); - assertNotNull(crdInfos, "Could not find expected CRD " + crdName - + " in results. Found instead: " + crdDetails.keySet()); - for (String crdVersion : CRD_VERSIONS) { - CRDInfo crdInfo = crdInfos.get(crdVersion); - final File actualCRDFile = new File(crdInfo.getFilePath()); - String crdFileContent = readFile(actualCRDFile); - verify(crdName, crdVersion, crdFileContent); - } - } - - // only delete the generated files if the test is successful - deleteDirectory(outputDir); - } - - private void verify(String crdName, String crdVersion, String crdFileContent) { - ApprovalTextWriter writer = new ApprovalTextWriter(crdFileContent, new Options() - .forFile().withExtension(".yml")); - ApprovalNamer approvalNamer = new CRDGeneratorApprovalNamer(AbstractCRDGeneratorApprovalTest.class, getClass()) - .addAdditionalInformation(crdName) - .addAdditionalInformation(crdVersion); - ApprovalApprover approver = new FileApprover(writer, approvalNamer); - Approvals.verify(approver); - } - - private String readFile(File file) { - try { - return new BufferedReader(new InputStreamReader(Files.newInputStream(file.toPath()))) - .lines().collect(Collectors.joining("\n")); - } catch (IOException e) { - fail(e); - throw new RuntimeException(e); - } - } - - private void deleteDirectory(File dir) { - try (Stream fileStream = Files.walk(dir.toPath())) { - fileStream.sorted(Comparator.reverseOrder()) - .map(Path::toFile) - .forEach(File::delete); - } catch (IOException e) { - fail("Could not delete output directory", e); - } - } -} diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalNamer.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalNamer.java deleted file mode 100644 index 04885a50f98..00000000000 --- a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalNamer.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright (C) 2015 Red Hat, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.fabric8.crd.generator.approvaltests; - -import com.spun.util.tests.StackTraceReflectionResult; -import com.spun.util.tests.TestUtils; -import org.approvaltests.namer.ApprovalNamer; -import org.approvaltests.namer.AttributeStackSelector; -import org.approvaltests.namer.NamerFactory; -import org.approvaltests.writers.Writer; - -import java.io.File; - -class CRDGeneratorApprovalNamer implements ApprovalNamer { - - private final String implementationClassName; - private final String baseDirectory; - private final String additionalInformation; - - public CRDGeneratorApprovalNamer(Class abstractClass, Class implementationClass) { - StackTraceReflectionResult info = TestUtils.getCurrentFileForMethod(new AttributeStackSelector()); - additionalInformation = NamerFactory.getAndClearAdditionalInformation(); - - String abstractClassPath = abstractClass.getPackage().getName().replace('.', File.separatorChar); - String implementationClassPath = implementationClass.getPackage().getName().replace('.', File.separatorChar); - this.implementationClassName = implementationClass.getSimpleName(); - - String abstractClassAbsolutePath = info.getSourceFile().getAbsolutePath(); - this.baseDirectory = abstractClassAbsolutePath.replace(abstractClassPath, - File.separatorChar + implementationClassPath); - } - - public CRDGeneratorApprovalNamer(String baseDirectory, - String implementationClassName, - String additionalInformation) { - this.baseDirectory = baseDirectory; - this.implementationClassName = implementationClassName; - this.additionalInformation = additionalInformation; - } - - @Override - public String getApprovalName() { - return String.format("%s%s", implementationClassName, additionalInformation); - } - - @Override - public String getSourceFilePath() { - String sub = NamerFactory.getSubdirectory(); - String subdirectory = sub != null && !sub.isEmpty() ? sub + File.separator : ""; - return baseDirectory + File.separator + subdirectory; - } - - @Override - public File getReceivedFile(String extensionWithDot) { - return new File( - getSourceFilePath() + File.separatorChar + getApprovalName() + Writer.received + extensionWithDot); - } - - @Override - public File getApprovedFile(String extensionWithDot) { - return new File( - getSourceFilePath() + File.separatorChar + getApprovalName() + Writer.approved + extensionWithDot); - } - - public ApprovalNamer addAdditionalInformation(String additionalInformation) { - return new CRDGeneratorApprovalNamer(this.baseDirectory, this.implementationClassName, - this.additionalInformation + "." + additionalInformation); - } -} diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.java new file mode 100644 index 00000000000..5853e1dda88 --- /dev/null +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.java @@ -0,0 +1,108 @@ +/* + * Copyright (C) 2015 Red Hat, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.fabric8.crd.generator.approvaltests; + +import io.fabric8.crd.generator.CRDGenerator; +import io.fabric8.crd.generator.CRDInfo; +import io.fabric8.crd.generator.approvaltests.annotated.api.Annotated; +import io.fabric8.crd.generator.approvaltests.complex.api.Complex; +import io.fabric8.crd.generator.approvaltests.inherited.api.Child; +import io.fabric8.crd.generator.approvaltests.json.api.ContainingJson; +import io.fabric8.crd.generator.approvaltests.k8svalidation.api.K8sValidation; +import io.fabric8.crd.generator.approvaltests.map.api.ContainingMaps; +import io.fabric8.crd.generator.approvaltests.nocyclic.api.NoCyclic; +import io.fabric8.kubernetes.client.CustomResource; +import org.approvaltests.Approvals; +import org.junit.jupiter.api.io.TempDir; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.stream.Stream; + +import static org.assertj.core.api.Assertions.assertThat; + +class CRDGeneratorApprovalTest { + + @TempDir + File tempDir; + + @ParameterizedTest(name = "{1}.{2} parallel={3}") + @MethodSource("crdApprovalTests") + void approvalTest( + Class>[] crClasses, String expectedCrd, String version, boolean parallel) + throws IOException { + Approvals.settings().allowMultipleVerifyCallsForThisMethod(); + final Map> result = new CRDGenerator() + .withParallelGenerationEnabled(parallel) + .inOutputDir(tempDir) + .customResourceClasses(crClasses) + .forCRDVersions(version) + .detailedGenerate() + .getCRDDetailsPerNameAndVersion(); + + assertThat(result) + .withFailMessage(() -> "Could not find expected CRD " + expectedCrd + + " in results. Found instead: " + result.keySet()) + .containsKey(expectedCrd) + .extractingByKey(expectedCrd) + .isNotNull(); + + Approvals.verify( + new String(Files.readAllBytes(new File(result.get(expectedCrd).get(version).getFilePath()).toPath())), + Approvals.NAMES.withParameters(expectedCrd, version)); + } + + static Stream crdApprovalTests() { + final List cases = new ArrayList<>(); + for (String crdVersion : new String[] { "v1", "v1beta1" }) { + for (boolean parallel : new boolean[] { false, true }) { + cases.add(new TestCase("annotateds.samples.fabric8.io", crdVersion, parallel, Annotated.class)); + cases.add(new TestCase("complexkinds.samples.fabric8.io", crdVersion, parallel, Complex.class)); + cases.add(new TestCase("children.sample.fabric8.io", crdVersion, parallel, Child.class)); + cases.add(new TestCase("containingjsons.sample.fabric8.io", crdVersion, parallel, ContainingJson.class)); + cases.add(new TestCase("k8svalidations.samples.fabric8.io", crdVersion, parallel, K8sValidation.class)); + cases.add(new TestCase("containingmaps.sample.fabric8.io", crdVersion, parallel, ContainingMaps.class)); + cases.add(new TestCase("multiples.sample.fabric8.io", crdVersion, parallel, + io.fabric8.crd.generator.approvaltests.multipleversions.api.v1.Multiple.class, + io.fabric8.crd.generator.approvaltests.multipleversions.api.v2.Multiple.class)); + cases.add(new TestCase("nocyclics.sample.fabric8.io", crdVersion, parallel, NoCyclic.class)); + } + } + return cases.stream().map(tc -> Arguments.of(tc.crClasses, tc.expectedCrd, tc.version, tc.parallel)); + } + + private static final class TestCase { + private Class>[] crClasses; + private String expectedCrd; + private String version; + private boolean parallel; + + public TestCase(String expectedCrd, String version, boolean parallel, Class>... crClasses) { + this.expectedCrd = expectedCrd; + this.version = version; + this.parallel = parallel; + this.crClasses = crClasses; + } + } + +} diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/PackageSettings.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/PackageSettings.java index abccc6a6469..a9bf45dc312 100644 --- a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/PackageSettings.java +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/PackageSettings.java @@ -29,4 +29,5 @@ public class PackageSettings { */ @SuppressWarnings("unused") public static ApprovalFailureReporter UseReporter = new QuietReporter(); + public String ApprovalBaseDirectory = "../resources"; } diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/annotated/AnnotatedApprovalTest.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/annotated/AnnotatedApprovalTest.java deleted file mode 100644 index fd45bd7660a..00000000000 --- a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/annotated/AnnotatedApprovalTest.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (C) 2015 Red Hat, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.fabric8.crd.generator.approvaltests.annotated; - -import io.fabric8.crd.generator.approvaltests.AbstractCRDGeneratorApprovalTest; -import io.fabric8.kubernetes.client.CustomResource; - -public class AnnotatedApprovalTest extends AbstractCRDGeneratorApprovalTest { - - protected Class>[] crClasses() { - return new Class[] { - io.fabric8.crd.generator.approvaltests.annotated.api.Annotated.class - }; - } - - protected String[] expectedCRDs() { - return new String[] { - "annotateds.samples.fabric8.io" - }; - } -} diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/ComplexApprovalTest.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/ComplexApprovalTest.java deleted file mode 100644 index 08c35a511e6..00000000000 --- a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/ComplexApprovalTest.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (C) 2015 Red Hat, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.fabric8.crd.generator.approvaltests.complex; - -import io.fabric8.crd.generator.approvaltests.AbstractCRDGeneratorApprovalTest; -import io.fabric8.kubernetes.client.CustomResource; - -public class ComplexApprovalTest extends AbstractCRDGeneratorApprovalTest { - protected Class>[] crClasses() { - return new Class[] { - io.fabric8.crd.generator.approvaltests.complex.api.Complex.class - }; - } - - protected String[] expectedCRDs() { - return new String[] { - "complexkinds.samples.fabric8.io" - }; - } -} diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/inherited/InheritedApprovalTest.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/inherited/InheritedApprovalTest.java deleted file mode 100644 index 2f28f296dbe..00000000000 --- a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/inherited/InheritedApprovalTest.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (C) 2015 Red Hat, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.fabric8.crd.generator.approvaltests.inherited; - -import io.fabric8.crd.generator.approvaltests.AbstractCRDGeneratorApprovalTest; -import io.fabric8.kubernetes.client.CustomResource; - -class InheritedApprovalTest extends AbstractCRDGeneratorApprovalTest { - protected Class>[] crClasses() { - return new Class[] { - io.fabric8.crd.generator.approvaltests.inherited.api.Child.class - }; - } - - protected String[] expectedCRDs() { - return new String[] { - "children.sample.fabric8.io" - }; - } -} diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/json/JsonApprovalTest.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/json/JsonApprovalTest.java deleted file mode 100644 index 341e52ff8e0..00000000000 --- a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/json/JsonApprovalTest.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (C) 2015 Red Hat, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.fabric8.crd.generator.approvaltests.json; - -import io.fabric8.crd.generator.approvaltests.AbstractCRDGeneratorApprovalTest; -import io.fabric8.kubernetes.client.CustomResource; - -class JsonApprovalTest extends AbstractCRDGeneratorApprovalTest { - protected Class>[] crClasses() { - return new Class[] { - io.fabric8.crd.generator.approvaltests.json.api.ContainingJson.class - }; - } - - protected String[] expectedCRDs() { - return new String[] { - "containingjsons.sample.fabric8.io" - }; - } -} diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/k8svalidation/K8sValidationApprovalTest.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/k8svalidation/K8sValidationApprovalTest.java deleted file mode 100644 index 4dfed1b7c4a..00000000000 --- a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/k8svalidation/K8sValidationApprovalTest.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (C) 2015 Red Hat, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.fabric8.crd.generator.approvaltests.k8svalidation; - -import io.fabric8.crd.generator.approvaltests.AbstractCRDGeneratorApprovalTest; -import io.fabric8.kubernetes.client.CustomResource; - -class K8sValidationApprovalTest extends AbstractCRDGeneratorApprovalTest { - - protected Class>[] crClasses() { - return new Class[] { - io.fabric8.crd.generator.approvaltests.k8svalidation.api.K8sValidation.class - }; - } - - protected String[] expectedCRDs() { - return new String[] { - "k8svalidations.samples.fabric8.io" - }; - } -} diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/map/MapApprovalTest.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/map/MapApprovalTest.java deleted file mode 100644 index 84b8f7d7331..00000000000 --- a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/map/MapApprovalTest.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (C) 2015 Red Hat, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.fabric8.crd.generator.approvaltests.map; - -import io.fabric8.crd.generator.approvaltests.AbstractCRDGeneratorApprovalTest; -import io.fabric8.kubernetes.client.CustomResource; - -class MapApprovalTest extends AbstractCRDGeneratorApprovalTest { - protected Class>[] crClasses() { - return new Class[] { - io.fabric8.crd.generator.approvaltests.map.api.ContainingMaps.class - }; - } - - protected String[] expectedCRDs() { - return new String[] { - "containingmaps.sample.fabric8.io" - }; - } -} diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/multipleversions/MultipleVersionsApprovalTest.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/multipleversions/MultipleVersionsApprovalTest.java deleted file mode 100644 index 52810d2a88d..00000000000 --- a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/multipleversions/MultipleVersionsApprovalTest.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (C) 2015 Red Hat, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.fabric8.crd.generator.approvaltests.multipleversions; - -import io.fabric8.crd.generator.approvaltests.AbstractCRDGeneratorApprovalTest; -import io.fabric8.kubernetes.client.CustomResource; - -class MultipleVersionsApprovalTest extends AbstractCRDGeneratorApprovalTest { - - protected Class>[] crClasses() { - return new Class[] { - io.fabric8.crd.generator.approvaltests.multipleversions.api.v1.Multiple.class, - io.fabric8.crd.generator.approvaltests.multipleversions.api.v2.Multiple.class - }; - } - - protected String[] expectedCRDs() { - return new String[] { - "multiples.sample.fabric8.io" - }; - } -} diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/nocyclic/NoCyclicApprovalTest.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/nocyclic/NoCyclicApprovalTest.java deleted file mode 100644 index b578aa800f4..00000000000 --- a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/nocyclic/NoCyclicApprovalTest.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (C) 2015 Red Hat, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.fabric8.crd.generator.approvaltests.nocyclic; - -import io.fabric8.crd.generator.approvaltests.AbstractCRDGeneratorApprovalTest; -import io.fabric8.kubernetes.client.CustomResource; - -class NoCyclicApprovalTest extends AbstractCRDGeneratorApprovalTest { - protected Class>[] crClasses() { - return new Class[] { - io.fabric8.crd.generator.approvaltests.nocyclic.api.NoCyclic.class - }; - } - - protected String[] expectedCRDs() { - return new String[] { - "nocyclics.sample.fabric8.io" - }; - } -} diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/annotated/AnnotatedApprovalTest.annotateds.samples.fabric8.io.v1.approved.yml b/crd-generator/api/src/test/resources/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.approvalTest.annotateds.samples.fabric8.io.v1.approved.txt similarity index 99% rename from crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/annotated/AnnotatedApprovalTest.annotateds.samples.fabric8.io.v1.approved.yml rename to crd-generator/api/src/test/resources/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.approvalTest.annotateds.samples.fabric8.io.v1.approved.txt index 2b8d292108a..82da118d7de 100644 --- a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/annotated/AnnotatedApprovalTest.annotateds.samples.fabric8.io.v1.approved.yml +++ b/crd-generator/api/src/test/resources/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.approvalTest.annotateds.samples.fabric8.io.v1.approved.txt @@ -75,4 +75,4 @@ spec: type: object type: object served: true - storage: true \ No newline at end of file + storage: true diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/annotated/AnnotatedApprovalTest.annotateds.samples.fabric8.io.v1beta1.approved.yml b/crd-generator/api/src/test/resources/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.approvalTest.annotateds.samples.fabric8.io.v1beta1.approved.txt similarity index 99% rename from crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/annotated/AnnotatedApprovalTest.annotateds.samples.fabric8.io.v1beta1.approved.yml rename to crd-generator/api/src/test/resources/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.approvalTest.annotateds.samples.fabric8.io.v1beta1.approved.txt index e520f1b0a8f..d3fcf7cd9e9 100644 --- a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/annotated/AnnotatedApprovalTest.annotateds.samples.fabric8.io.v1beta1.approved.yml +++ b/crd-generator/api/src/test/resources/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.approvalTest.annotateds.samples.fabric8.io.v1beta1.approved.txt @@ -75,4 +75,4 @@ spec: versions: - name: v1 served: true - storage: true \ No newline at end of file + storage: true diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/inherited/InheritedApprovalTest.children.sample.fabric8.io.v1.approved.yml b/crd-generator/api/src/test/resources/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.approvalTest.children.sample.fabric8.io.v1.approved.txt similarity index 100% rename from crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/inherited/InheritedApprovalTest.children.sample.fabric8.io.v1.approved.yml rename to crd-generator/api/src/test/resources/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.approvalTest.children.sample.fabric8.io.v1.approved.txt diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/inherited/InheritedApprovalTest.children.sample.fabric8.io.v1beta1.approved.yml b/crd-generator/api/src/test/resources/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.approvalTest.children.sample.fabric8.io.v1beta1.approved.txt similarity index 100% rename from crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/inherited/InheritedApprovalTest.children.sample.fabric8.io.v1beta1.approved.yml rename to crd-generator/api/src/test/resources/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.approvalTest.children.sample.fabric8.io.v1beta1.approved.txt diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/ComplexApprovalTest.complexkinds.samples.fabric8.io.v1.approved.yml b/crd-generator/api/src/test/resources/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.approvalTest.complexkinds.samples.fabric8.io.v1.approved.txt similarity index 100% rename from crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/ComplexApprovalTest.complexkinds.samples.fabric8.io.v1.approved.yml rename to crd-generator/api/src/test/resources/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.approvalTest.complexkinds.samples.fabric8.io.v1.approved.txt diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/ComplexApprovalTest.complexkinds.samples.fabric8.io.v1beta1.approved.yml b/crd-generator/api/src/test/resources/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.approvalTest.complexkinds.samples.fabric8.io.v1beta1.approved.txt similarity index 100% rename from crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/ComplexApprovalTest.complexkinds.samples.fabric8.io.v1beta1.approved.yml rename to crd-generator/api/src/test/resources/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.approvalTest.complexkinds.samples.fabric8.io.v1beta1.approved.txt diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/json/JsonApprovalTest.containingjsons.sample.fabric8.io.v1.approved.yml b/crd-generator/api/src/test/resources/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.approvalTest.containingjsons.sample.fabric8.io.v1.approved.txt similarity index 100% rename from crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/json/JsonApprovalTest.containingjsons.sample.fabric8.io.v1.approved.yml rename to crd-generator/api/src/test/resources/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.approvalTest.containingjsons.sample.fabric8.io.v1.approved.txt diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/json/JsonApprovalTest.containingjsons.sample.fabric8.io.v1beta1.approved.yml b/crd-generator/api/src/test/resources/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.approvalTest.containingjsons.sample.fabric8.io.v1beta1.approved.txt similarity index 100% rename from crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/json/JsonApprovalTest.containingjsons.sample.fabric8.io.v1beta1.approved.yml rename to crd-generator/api/src/test/resources/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.approvalTest.containingjsons.sample.fabric8.io.v1beta1.approved.txt diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/map/MapApprovalTest.containingmaps.sample.fabric8.io.v1.approved.yml b/crd-generator/api/src/test/resources/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.approvalTest.containingmaps.sample.fabric8.io.v1.approved.txt similarity index 100% rename from crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/map/MapApprovalTest.containingmaps.sample.fabric8.io.v1.approved.yml rename to crd-generator/api/src/test/resources/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.approvalTest.containingmaps.sample.fabric8.io.v1.approved.txt diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/map/MapApprovalTest.containingmaps.sample.fabric8.io.v1beta1.approved.yml b/crd-generator/api/src/test/resources/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.approvalTest.containingmaps.sample.fabric8.io.v1beta1.approved.txt similarity index 100% rename from crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/map/MapApprovalTest.containingmaps.sample.fabric8.io.v1beta1.approved.yml rename to crd-generator/api/src/test/resources/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.approvalTest.containingmaps.sample.fabric8.io.v1beta1.approved.txt diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/k8svalidation/K8sValidationApprovalTest.k8svalidations.samples.fabric8.io.v1.approved.yml b/crd-generator/api/src/test/resources/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.approvalTest.k8svalidations.samples.fabric8.io.v1.approved.txt similarity index 100% rename from crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/k8svalidation/K8sValidationApprovalTest.k8svalidations.samples.fabric8.io.v1.approved.yml rename to crd-generator/api/src/test/resources/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.approvalTest.k8svalidations.samples.fabric8.io.v1.approved.txt diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/k8svalidation/K8sValidationApprovalTest.k8svalidations.samples.fabric8.io.v1beta1.approved.yml b/crd-generator/api/src/test/resources/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.approvalTest.k8svalidations.samples.fabric8.io.v1beta1.approved.txt similarity index 99% rename from crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/k8svalidation/K8sValidationApprovalTest.k8svalidations.samples.fabric8.io.v1beta1.approved.yml rename to crd-generator/api/src/test/resources/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.approvalTest.k8svalidations.samples.fabric8.io.v1beta1.approved.txt index d09c05e9ccb..64e2731f98e 100644 --- a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/k8svalidation/K8sValidationApprovalTest.k8svalidations.samples.fabric8.io.v1beta1.approved.yml +++ b/crd-generator/api/src/test/resources/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.approvalTest.k8svalidations.samples.fabric8.io.v1beta1.approved.txt @@ -142,4 +142,4 @@ spec: versions: - name: v1alpha1 served: true - storage: true \ No newline at end of file + storage: true diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/multipleversions/MultipleVersionsApprovalTest.multiples.sample.fabric8.io.v1.approved.yml b/crd-generator/api/src/test/resources/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.approvalTest.multiples.sample.fabric8.io.v1.approved.txt similarity index 100% rename from crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/multipleversions/MultipleVersionsApprovalTest.multiples.sample.fabric8.io.v1.approved.yml rename to crd-generator/api/src/test/resources/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.approvalTest.multiples.sample.fabric8.io.v1.approved.txt diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/multipleversions/MultipleVersionsApprovalTest.multiples.sample.fabric8.io.v1beta1.approved.yml b/crd-generator/api/src/test/resources/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.approvalTest.multiples.sample.fabric8.io.v1beta1.approved.txt similarity index 100% rename from crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/multipleversions/MultipleVersionsApprovalTest.multiples.sample.fabric8.io.v1beta1.approved.yml rename to crd-generator/api/src/test/resources/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.approvalTest.multiples.sample.fabric8.io.v1beta1.approved.txt diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/nocyclic/NoCyclicApprovalTest.nocyclics.sample.fabric8.io.v1.approved.yml b/crd-generator/api/src/test/resources/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.approvalTest.nocyclics.sample.fabric8.io.v1.approved.txt similarity index 100% rename from crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/nocyclic/NoCyclicApprovalTest.nocyclics.sample.fabric8.io.v1.approved.yml rename to crd-generator/api/src/test/resources/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.approvalTest.nocyclics.sample.fabric8.io.v1.approved.txt diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/nocyclic/NoCyclicApprovalTest.nocyclics.sample.fabric8.io.v1beta1.approved.yml b/crd-generator/api/src/test/resources/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.approvalTest.nocyclics.sample.fabric8.io.v1beta1.approved.txt similarity index 100% rename from crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/nocyclic/NoCyclicApprovalTest.nocyclics.sample.fabric8.io.v1beta1.approved.yml rename to crd-generator/api/src/test/resources/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.approvalTest.nocyclics.sample.fabric8.io.v1beta1.approved.txt diff --git a/pom.xml b/pom.xml index d0eb9fc936c..72ccfd3ad91 100644 --- a/pom.xml +++ b/pom.xml @@ -1251,8 +1251,7 @@ kubernetes-client/src/test/resources/mockito-extensions/* **/src/test/resources/ssl/* **/src/test/resources/io/fabric8/java/generator/approvals/*.*.approved.txt - crd-generator/api/src/test/java/**/*.approved.yml - crd-generator/apt/src/test/java/**/*.approved.yml + crd-generator/api/src/test/resources/**/*.approved.txt **/it/**/expected/**/*.expected Jenkinsfile .mvn/**/* From 8d98cb81375e964d6cd8b84fd4e3a7274a4ec7c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bernhard=20Str=C3=A4hle?= Date: Fri, 26 Apr 2024 16:58:36 +0200 Subject: [PATCH 07/11] Get rid of unnecessary api package in approval tests for crd-generator --- .../CRDGeneratorApprovalTest.java | 18 +++++++++--------- .../annotated/{api => }/Annotated.java | 2 +- .../annotated/{api => }/AnnotatedSpec.java | 2 +- .../complex/{api => }/Complex.java | 2 +- .../complex/{api => }/ComplexSpec.java | 2 +- .../complex/{api => }/ComplexStatus.java | 2 +- .../{api => }/ServiceConfiguration.java | 6 +++--- .../{api => }/StatefulSetConfiguration.java | 6 +++--- .../complex/{api => }/k8s/ObjectMeta.java | 2 +- .../complex/{api => }/k8s/ServiceSpec.java | 2 +- .../complex/{api => }/k8s/StatefulSetSpec.java | 2 +- .../inherited/{api => }/Base.java | 2 +- .../inherited/{api => }/BaseSpec.java | 2 +- .../inherited/{api => }/BaseStatus.java | 2 +- .../inherited/{api => }/Child.java | 2 +- .../inherited/{api => }/ChildSpec.java | 2 +- .../inherited/{api => }/ChildStatus.java | 2 +- .../json/{api => }/ContainingJson.java | 2 +- .../json/{api => }/ContainingJsonSpec.java | 2 +- .../approvaltests/json/{api => }/Foo.java | 2 +- .../k8svalidation/{api => }/K8sValidation.java | 2 +- .../{api => }/K8sValidationSpec.java | 2 +- .../{api => }/K8sValidationStatus.java | 2 +- .../map/{api => }/ContainingMaps.java | 2 +- .../map/{api => }/ContainingMapsSpec.java | 2 +- .../{api => }/v1/Multiple.java | 2 +- .../{api => }/v1/MultipleSpec.java | 2 +- .../{api => }/v2/Multiple.java | 2 +- .../{api => }/v2/MultipleSpec.java | 2 +- .../nocyclic/{api => }/NoCyclic.java | 2 +- .../nocyclic/{api => }/NoCyclicSpec.java | 2 +- .../nocyclic/{api => }/NoCyclicStatus.java | 2 +- .../approvaltests/nocyclic/{api => }/Ref.java | 2 +- 33 files changed, 45 insertions(+), 45 deletions(-) rename crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/annotated/{api => }/Annotated.java (93%) rename crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/annotated/{api => }/AnnotatedSpec.java (98%) rename crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/{api => }/Complex.java (94%) rename crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/{api => }/ComplexSpec.java (97%) rename crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/{api => }/ComplexStatus.java (96%) rename crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/{api => }/ServiceConfiguration.java (87%) rename crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/{api => }/StatefulSetConfiguration.java (87%) rename crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/{api => }/k8s/ObjectMeta.java (98%) rename crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/{api => }/k8s/ServiceSpec.java (99%) rename crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/{api => }/k8s/StatefulSetSpec.java (98%) rename crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/inherited/{api => }/Base.java (93%) rename crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/inherited/{api => }/BaseSpec.java (92%) rename crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/inherited/{api => }/BaseStatus.java (91%) rename crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/inherited/{api => }/Child.java (93%) rename crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/inherited/{api => }/ChildSpec.java (92%) rename crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/inherited/{api => }/ChildStatus.java (92%) rename crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/json/{api => }/ContainingJson.java (94%) rename crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/json/{api => }/ContainingJsonSpec.java (94%) rename crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/json/{api => }/Foo.java (94%) rename crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/k8svalidation/{api => }/K8sValidation.java (96%) rename crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/k8svalidation/{api => }/K8sValidationSpec.java (97%) rename crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/k8svalidation/{api => }/K8sValidationStatus.java (91%) rename crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/map/{api => }/ContainingMaps.java (94%) rename crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/map/{api => }/ContainingMapsSpec.java (97%) rename crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/multipleversions/{api => }/v1/Multiple.java (99%) rename crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/multipleversions/{api => }/v1/MultipleSpec.java (98%) rename crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/multipleversions/{api => }/v2/Multiple.java (99%) rename crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/multipleversions/{api => }/v2/MultipleSpec.java (98%) rename crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/nocyclic/{api => }/NoCyclic.java (94%) rename crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/nocyclic/{api => }/NoCyclicSpec.java (91%) rename crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/nocyclic/{api => }/NoCyclicStatus.java (91%) rename crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/nocyclic/{api => }/Ref.java (92%) diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.java index 5853e1dda88..da4871e799e 100644 --- a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.java +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.java @@ -17,13 +17,13 @@ import io.fabric8.crd.generator.CRDGenerator; import io.fabric8.crd.generator.CRDInfo; -import io.fabric8.crd.generator.approvaltests.annotated.api.Annotated; -import io.fabric8.crd.generator.approvaltests.complex.api.Complex; -import io.fabric8.crd.generator.approvaltests.inherited.api.Child; -import io.fabric8.crd.generator.approvaltests.json.api.ContainingJson; -import io.fabric8.crd.generator.approvaltests.k8svalidation.api.K8sValidation; -import io.fabric8.crd.generator.approvaltests.map.api.ContainingMaps; -import io.fabric8.crd.generator.approvaltests.nocyclic.api.NoCyclic; +import io.fabric8.crd.generator.approvaltests.annotated.Annotated; +import io.fabric8.crd.generator.approvaltests.complex.Complex; +import io.fabric8.crd.generator.approvaltests.inherited.Child; +import io.fabric8.crd.generator.approvaltests.json.ContainingJson; +import io.fabric8.crd.generator.approvaltests.k8svalidation.K8sValidation; +import io.fabric8.crd.generator.approvaltests.map.ContainingMaps; +import io.fabric8.crd.generator.approvaltests.nocyclic.NoCyclic; import io.fabric8.kubernetes.client.CustomResource; import org.approvaltests.Approvals; import org.junit.jupiter.api.io.TempDir; @@ -83,8 +83,8 @@ static Stream crdApprovalTests() { cases.add(new TestCase("k8svalidations.samples.fabric8.io", crdVersion, parallel, K8sValidation.class)); cases.add(new TestCase("containingmaps.sample.fabric8.io", crdVersion, parallel, ContainingMaps.class)); cases.add(new TestCase("multiples.sample.fabric8.io", crdVersion, parallel, - io.fabric8.crd.generator.approvaltests.multipleversions.api.v1.Multiple.class, - io.fabric8.crd.generator.approvaltests.multipleversions.api.v2.Multiple.class)); + io.fabric8.crd.generator.approvaltests.multipleversions.v1.Multiple.class, + io.fabric8.crd.generator.approvaltests.multipleversions.v2.Multiple.class)); cases.add(new TestCase("nocyclics.sample.fabric8.io", crdVersion, parallel, NoCyclic.class)); } } diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/annotated/api/Annotated.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/annotated/Annotated.java similarity index 93% rename from crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/annotated/api/Annotated.java rename to crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/annotated/Annotated.java index cc2cc300612..9657a25274d 100644 --- a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/annotated/api/Annotated.java +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/annotated/Annotated.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.fabric8.crd.generator.approvaltests.annotated.api; +package io.fabric8.crd.generator.approvaltests.annotated; import io.fabric8.kubernetes.client.CustomResource; import io.fabric8.kubernetes.model.annotation.Group; diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/annotated/api/AnnotatedSpec.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/annotated/AnnotatedSpec.java similarity index 98% rename from crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/annotated/api/AnnotatedSpec.java rename to crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/annotated/AnnotatedSpec.java index dd2dbc6dc61..d875fee3bf3 100644 --- a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/annotated/api/AnnotatedSpec.java +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/annotated/AnnotatedSpec.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.fabric8.crd.generator.approvaltests.annotated.api; +package io.fabric8.crd.generator.approvaltests.annotated; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/api/Complex.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/Complex.java similarity index 94% rename from crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/api/Complex.java rename to crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/Complex.java index 774a98c1d8e..c9832e80be7 100644 --- a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/api/Complex.java +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/Complex.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.fabric8.crd.generator.approvaltests.complex.api; +package io.fabric8.crd.generator.approvaltests.complex; import io.fabric8.kubernetes.api.model.Namespaced; import io.fabric8.kubernetes.client.CustomResource; diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/api/ComplexSpec.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/ComplexSpec.java similarity index 97% rename from crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/api/ComplexSpec.java rename to crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/ComplexSpec.java index b26ad586bfe..326e78f7ea9 100644 --- a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/api/ComplexSpec.java +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/ComplexSpec.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.fabric8.crd.generator.approvaltests.complex.api; +package io.fabric8.crd.generator.approvaltests.complex; import java.util.ArrayList; import java.util.List; diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/api/ComplexStatus.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/ComplexStatus.java similarity index 96% rename from crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/api/ComplexStatus.java rename to crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/ComplexStatus.java index 9dd8a75777e..2ea1ae87346 100644 --- a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/api/ComplexStatus.java +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/ComplexStatus.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.fabric8.crd.generator.approvaltests.complex.api; +package io.fabric8.crd.generator.approvaltests.complex; import com.fasterxml.jackson.annotation.JsonProperty; import io.fabric8.crd.generator.annotation.PrinterColumn; diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/api/ServiceConfiguration.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/ServiceConfiguration.java similarity index 87% rename from crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/api/ServiceConfiguration.java rename to crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/ServiceConfiguration.java index 9b4b571e883..ea82a685f90 100644 --- a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/api/ServiceConfiguration.java +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/ServiceConfiguration.java @@ -13,12 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.fabric8.crd.generator.approvaltests.complex.api; +package io.fabric8.crd.generator.approvaltests.complex; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonPropertyDescription; -import io.fabric8.crd.generator.approvaltests.complex.api.k8s.ObjectMeta; -import io.fabric8.crd.generator.approvaltests.complex.api.k8s.ServiceSpec; +import io.fabric8.crd.generator.approvaltests.complex.k8s.ObjectMeta; +import io.fabric8.crd.generator.approvaltests.complex.k8s.ServiceSpec; import io.fabric8.generator.annotation.Nullable; @SuppressWarnings("LombokGetterMayBeUsed") diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/api/StatefulSetConfiguration.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/StatefulSetConfiguration.java similarity index 87% rename from crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/api/StatefulSetConfiguration.java rename to crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/StatefulSetConfiguration.java index c533074c888..4099e649370 100644 --- a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/api/StatefulSetConfiguration.java +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/StatefulSetConfiguration.java @@ -13,12 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.fabric8.crd.generator.approvaltests.complex.api; +package io.fabric8.crd.generator.approvaltests.complex; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonPropertyDescription; -import io.fabric8.crd.generator.approvaltests.complex.api.k8s.ObjectMeta; -import io.fabric8.crd.generator.approvaltests.complex.api.k8s.StatefulSetSpec; +import io.fabric8.crd.generator.approvaltests.complex.k8s.ObjectMeta; +import io.fabric8.crd.generator.approvaltests.complex.k8s.StatefulSetSpec; @SuppressWarnings("LombokGetterMayBeUsed") public class StatefulSetConfiguration { diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/api/k8s/ObjectMeta.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/k8s/ObjectMeta.java similarity index 98% rename from crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/api/k8s/ObjectMeta.java rename to crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/k8s/ObjectMeta.java index 5114cb87b86..e8af8010ef2 100644 --- a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/api/k8s/ObjectMeta.java +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/k8s/ObjectMeta.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.fabric8.crd.generator.approvaltests.complex.api.k8s; +package io.fabric8.crd.generator.approvaltests.complex.k8s; import com.fasterxml.jackson.annotation.JsonAnyGetter; import com.fasterxml.jackson.annotation.JsonAnySetter; diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/api/k8s/ServiceSpec.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/k8s/ServiceSpec.java similarity index 99% rename from crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/api/k8s/ServiceSpec.java rename to crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/k8s/ServiceSpec.java index b3beedd933c..ccfdb14a6d2 100644 --- a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/api/k8s/ServiceSpec.java +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/k8s/ServiceSpec.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.fabric8.crd.generator.approvaltests.complex.api.k8s; +package io.fabric8.crd.generator.approvaltests.complex.k8s; import com.fasterxml.jackson.annotation.JsonAnyGetter; import com.fasterxml.jackson.annotation.JsonAnySetter; diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/api/k8s/StatefulSetSpec.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/k8s/StatefulSetSpec.java similarity index 98% rename from crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/api/k8s/StatefulSetSpec.java rename to crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/k8s/StatefulSetSpec.java index 59bb1f624a4..3af389927c2 100644 --- a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/api/k8s/StatefulSetSpec.java +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/k8s/StatefulSetSpec.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.fabric8.crd.generator.approvaltests.complex.api.k8s; +package io.fabric8.crd.generator.approvaltests.complex.k8s; import com.fasterxml.jackson.annotation.JsonAnyGetter; import com.fasterxml.jackson.annotation.JsonAnySetter; diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/inherited/api/Base.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/inherited/Base.java similarity index 93% rename from crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/inherited/api/Base.java rename to crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/inherited/Base.java index 7c4cf9ede6d..3bda352b759 100644 --- a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/inherited/api/Base.java +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/inherited/Base.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.fabric8.crd.generator.approvaltests.inherited.api; +package io.fabric8.crd.generator.approvaltests.inherited; import io.fabric8.kubernetes.api.model.Namespaced; import io.fabric8.kubernetes.client.CustomResource; diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/inherited/api/BaseSpec.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/inherited/BaseSpec.java similarity index 92% rename from crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/inherited/api/BaseSpec.java rename to crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/inherited/BaseSpec.java index b29b50fd6a4..28d906d9939 100644 --- a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/inherited/api/BaseSpec.java +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/inherited/BaseSpec.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.fabric8.crd.generator.approvaltests.inherited.api; +package io.fabric8.crd.generator.approvaltests.inherited; public class BaseSpec { private int baseInt; diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/inherited/api/BaseStatus.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/inherited/BaseStatus.java similarity index 91% rename from crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/inherited/api/BaseStatus.java rename to crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/inherited/BaseStatus.java index 50e38576e64..fadf5a3182d 100644 --- a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/inherited/api/BaseStatus.java +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/inherited/BaseStatus.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.fabric8.crd.generator.approvaltests.inherited.api; +package io.fabric8.crd.generator.approvaltests.inherited; /** * @author Christophe Laprun diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/inherited/api/Child.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/inherited/Child.java similarity index 93% rename from crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/inherited/api/Child.java rename to crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/inherited/Child.java index d74849bd67c..ca39f5b41f8 100644 --- a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/inherited/api/Child.java +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/inherited/Child.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.fabric8.crd.generator.approvaltests.inherited.api; +package io.fabric8.crd.generator.approvaltests.inherited; import io.fabric8.kubernetes.api.model.Namespaced; import io.fabric8.kubernetes.model.annotation.Group; diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/inherited/api/ChildSpec.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/inherited/ChildSpec.java similarity index 92% rename from crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/inherited/api/ChildSpec.java rename to crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/inherited/ChildSpec.java index b6c7da39881..352ab4e4d7a 100644 --- a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/inherited/api/ChildSpec.java +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/inherited/ChildSpec.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.fabric8.crd.generator.approvaltests.inherited.api; +package io.fabric8.crd.generator.approvaltests.inherited; import java.util.Map; diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/inherited/api/ChildStatus.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/inherited/ChildStatus.java similarity index 92% rename from crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/inherited/api/ChildStatus.java rename to crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/inherited/ChildStatus.java index 2cdf10f8be9..7f3674683fe 100644 --- a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/inherited/api/ChildStatus.java +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/inherited/ChildStatus.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.fabric8.crd.generator.approvaltests.inherited.api; +package io.fabric8.crd.generator.approvaltests.inherited; /** * @author Christophe Laprun diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/json/api/ContainingJson.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/json/ContainingJson.java similarity index 94% rename from crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/json/api/ContainingJson.java rename to crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/json/ContainingJson.java index 35ddc720e9a..55d4255c57b 100644 --- a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/json/api/ContainingJson.java +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/json/ContainingJson.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.fabric8.crd.generator.approvaltests.json.api; +package io.fabric8.crd.generator.approvaltests.json; import io.fabric8.kubernetes.client.CustomResource; import io.fabric8.kubernetes.model.annotation.Group; diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/json/api/ContainingJsonSpec.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/json/ContainingJsonSpec.java similarity index 94% rename from crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/json/api/ContainingJsonSpec.java rename to crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/json/ContainingJsonSpec.java index 227e43649e6..7f1be1d0f5e 100644 --- a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/json/api/ContainingJsonSpec.java +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/json/ContainingJsonSpec.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.fabric8.crd.generator.approvaltests.json.api; +package io.fabric8.crd.generator.approvaltests.json; import com.fasterxml.jackson.databind.JsonNode; diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/json/api/Foo.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/json/Foo.java similarity index 94% rename from crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/json/api/Foo.java rename to crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/json/Foo.java index be670d35bb8..3e27b063f26 100644 --- a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/json/api/Foo.java +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/json/Foo.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.fabric8.crd.generator.approvaltests.json.api; +package io.fabric8.crd.generator.approvaltests.json; import com.fasterxml.jackson.annotation.JsonAnyGetter; import com.fasterxml.jackson.annotation.JsonAnySetter; diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/k8svalidation/api/K8sValidation.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/k8svalidation/K8sValidation.java similarity index 96% rename from crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/k8svalidation/api/K8sValidation.java rename to crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/k8svalidation/K8sValidation.java index 3e8ec8fdbfa..a75bcff636e 100644 --- a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/k8svalidation/api/K8sValidation.java +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/k8svalidation/K8sValidation.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.fabric8.crd.generator.approvaltests.k8svalidation.api; +package io.fabric8.crd.generator.approvaltests.k8svalidation; import io.fabric8.generator.annotation.ValidationRule; import io.fabric8.kubernetes.client.CustomResource; diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/k8svalidation/api/K8sValidationSpec.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/k8svalidation/K8sValidationSpec.java similarity index 97% rename from crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/k8svalidation/api/K8sValidationSpec.java rename to crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/k8svalidation/K8sValidationSpec.java index 39fa11fc9c8..43250e81d92 100644 --- a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/k8svalidation/api/K8sValidationSpec.java +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/k8svalidation/K8sValidationSpec.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.fabric8.crd.generator.approvaltests.k8svalidation.api; +package io.fabric8.crd.generator.approvaltests.k8svalidation; import io.fabric8.generator.annotation.Required; import io.fabric8.generator.annotation.ValidationRule; diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/k8svalidation/api/K8sValidationStatus.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/k8svalidation/K8sValidationStatus.java similarity index 91% rename from crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/k8svalidation/api/K8sValidationStatus.java rename to crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/k8svalidation/K8sValidationStatus.java index 86e26bcc5f5..73c9f4f2487 100644 --- a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/k8svalidation/api/K8sValidationStatus.java +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/k8svalidation/K8sValidationStatus.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.fabric8.crd.generator.approvaltests.k8svalidation.api; +package io.fabric8.crd.generator.approvaltests.k8svalidation; public class K8sValidationStatus { Integer availableReplicas; diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/map/api/ContainingMaps.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/map/ContainingMaps.java similarity index 94% rename from crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/map/api/ContainingMaps.java rename to crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/map/ContainingMaps.java index a2229fa2119..28e666a7232 100644 --- a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/map/api/ContainingMaps.java +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/map/ContainingMaps.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.fabric8.crd.generator.approvaltests.map.api; +package io.fabric8.crd.generator.approvaltests.map; import io.fabric8.kubernetes.client.CustomResource; import io.fabric8.kubernetes.model.annotation.Group; diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/map/api/ContainingMapsSpec.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/map/ContainingMapsSpec.java similarity index 97% rename from crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/map/api/ContainingMapsSpec.java rename to crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/map/ContainingMapsSpec.java index bf4b458dced..e59b1848bd4 100644 --- a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/map/api/ContainingMapsSpec.java +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/map/ContainingMapsSpec.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.fabric8.crd.generator.approvaltests.map.api; +package io.fabric8.crd.generator.approvaltests.map; import java.util.HashMap; import java.util.List; diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/multipleversions/api/v1/Multiple.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/multipleversions/v1/Multiple.java similarity index 99% rename from crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/multipleversions/api/v1/Multiple.java rename to crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/multipleversions/v1/Multiple.java index e963c9e202b..764dec43074 100644 --- a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/multipleversions/api/v1/Multiple.java +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/multipleversions/v1/Multiple.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.fabric8.crd.generator.approvaltests.multipleversions.api.v1; +package io.fabric8.crd.generator.approvaltests.multipleversions.v1; import io.fabric8.kubernetes.client.CustomResource; import io.fabric8.kubernetes.model.annotation.Group; diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/multipleversions/api/v1/MultipleSpec.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/multipleversions/v1/MultipleSpec.java similarity index 98% rename from crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/multipleversions/api/v1/MultipleSpec.java rename to crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/multipleversions/v1/MultipleSpec.java index 88287e68eea..46bb4660c9e 100644 --- a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/multipleversions/api/v1/MultipleSpec.java +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/multipleversions/v1/MultipleSpec.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.fabric8.crd.generator.approvaltests.multipleversions.api.v1; +package io.fabric8.crd.generator.approvaltests.multipleversions.v1; public class MultipleSpec { private String v1; diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/multipleversions/api/v2/Multiple.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/multipleversions/v2/Multiple.java similarity index 99% rename from crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/multipleversions/api/v2/Multiple.java rename to crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/multipleversions/v2/Multiple.java index 9f36a9a09a8..9a6d061ee26 100644 --- a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/multipleversions/api/v2/Multiple.java +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/multipleversions/v2/Multiple.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.fabric8.crd.generator.approvaltests.multipleversions.api.v2; +package io.fabric8.crd.generator.approvaltests.multipleversions.v2; import io.fabric8.kubernetes.client.CustomResource; import io.fabric8.kubernetes.model.annotation.Group; diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/multipleversions/api/v2/MultipleSpec.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/multipleversions/v2/MultipleSpec.java similarity index 98% rename from crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/multipleversions/api/v2/MultipleSpec.java rename to crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/multipleversions/v2/MultipleSpec.java index e3a59d01e00..098fb2e0851 100644 --- a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/multipleversions/api/v2/MultipleSpec.java +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/multipleversions/v2/MultipleSpec.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.fabric8.crd.generator.approvaltests.multipleversions.api.v2; +package io.fabric8.crd.generator.approvaltests.multipleversions.v2; public class MultipleSpec { private String v2; diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/nocyclic/api/NoCyclic.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/nocyclic/NoCyclic.java similarity index 94% rename from crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/nocyclic/api/NoCyclic.java rename to crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/nocyclic/NoCyclic.java index 48258fc47e4..40c67910048 100644 --- a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/nocyclic/api/NoCyclic.java +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/nocyclic/NoCyclic.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.fabric8.crd.generator.approvaltests.nocyclic.api; +package io.fabric8.crd.generator.approvaltests.nocyclic; import io.fabric8.kubernetes.api.model.Namespaced; import io.fabric8.kubernetes.client.CustomResource; diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/nocyclic/api/NoCyclicSpec.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/nocyclic/NoCyclicSpec.java similarity index 91% rename from crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/nocyclic/api/NoCyclicSpec.java rename to crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/nocyclic/NoCyclicSpec.java index 7f93f98fbb5..448ed9e4a22 100644 --- a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/nocyclic/api/NoCyclicSpec.java +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/nocyclic/NoCyclicSpec.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.fabric8.crd.generator.approvaltests.nocyclic.api; +package io.fabric8.crd.generator.approvaltests.nocyclic; public class NoCyclicSpec { private Ref ref1; diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/nocyclic/api/NoCyclicStatus.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/nocyclic/NoCyclicStatus.java similarity index 91% rename from crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/nocyclic/api/NoCyclicStatus.java rename to crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/nocyclic/NoCyclicStatus.java index fa97cfc0d2c..99cf43202bb 100644 --- a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/nocyclic/api/NoCyclicStatus.java +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/nocyclic/NoCyclicStatus.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.fabric8.crd.generator.approvaltests.nocyclic.api; +package io.fabric8.crd.generator.approvaltests.nocyclic; public class NoCyclicStatus { private String message; diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/nocyclic/api/Ref.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/nocyclic/Ref.java similarity index 92% rename from crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/nocyclic/api/Ref.java rename to crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/nocyclic/Ref.java index 247df80eaa0..35c6b2fed0e 100644 --- a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/nocyclic/api/Ref.java +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/nocyclic/Ref.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.fabric8.crd.generator.approvaltests.nocyclic.api; +package io.fabric8.crd.generator.approvaltests.nocyclic; public class Ref { From 1064088ec230b2de7116f5adf19100b532cb9329 Mon Sep 17 00:00:00 2001 From: Steven Hawkins Date: Mon, 29 Apr 2024 00:55:58 -0400 Subject: [PATCH 08/11] fix: updating the kubernetesserializer handling of time types closes: #5960 Signed-off-by: Steve Hawkins --- CHANGELOG.md | 2 ++ .../crd/generator/types/TypeMappingsTest.java | 20 +++++++++---------- .../client/utils/KubernetesSerialization.java | 3 +++ 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e788acd514c..c56abe8fa64 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ### 6.13-SNAPSHOT #### Bugs +* Fix #5960: The serialization of time related types should be string * Fix #5866: Addressed cycle in crd generation with Java 19+ and ZonedDateTime #### Improvements @@ -17,6 +18,7 @@ #### New Features #### _**Note**_: Breaking changes +* Fix #5960: The KubernetesSerializer will now by default serialize time related types to strings - rather than object, integer, number, or arrays of integer / number. If you are using these types in a custom object and were not including JsonFormat annotations to adjust the serialization they were likely being serialized in a non-standard way that would not be usable other Kubernetes clients, nor match the generated custom resource definition if one was being produced. Please open an issue if you need the previous behavior for whatever reason - there is a workaround by creating a customized KubernetesSerializer. ### 6.12.1 (2024-04-18) diff --git a/crd-generator/test/src/test/java/io/fabric8/crd/generator/types/TypeMappingsTest.java b/crd-generator/test/src/test/java/io/fabric8/crd/generator/types/TypeMappingsTest.java index 5eda53475fe..c8ba3100057 100644 --- a/crd-generator/test/src/test/java/io/fabric8/crd/generator/types/TypeMappingsTest.java +++ b/crd-generator/test/src/test/java/io/fabric8/crd/generator/types/TypeMappingsTest.java @@ -52,17 +52,17 @@ void targetType(String propertyName, String expectedType) { private static Stream targetTypeCases() { return Stream.of( Arguments.of("date", "string"), - Arguments.of("localDate", "array"), // to review - Arguments.of("localDateTime", "array"), // to review - Arguments.of("zonedDateTime", "number"), // to review - Arguments.of("offsetDateTime", "number"), // to review - Arguments.of("offsetTime", "array"), // to review - Arguments.of("yearMonth", "array"), // to review - Arguments.of("monthDay", "array"), // to review - Arguments.of("instant", "number"), // to review - Arguments.of("duration", "integer"), // to review + Arguments.of("localDate", "string"), + Arguments.of("localDateTime", "string"), + Arguments.of("zonedDateTime", "string"), + Arguments.of("offsetDateTime", "string"), + Arguments.of("offsetTime", "string"), + Arguments.of("yearMonth", "string"), + Arguments.of("monthDay", "string"), + Arguments.of("instant", "string"), + Arguments.of("duration", "string"), Arguments.of("period", "string"), - Arguments.of("timestamp", "integer"), // to review + Arguments.of("timestamp", "string"), // to review // Arguments.of("aShort", "integer"), // TODO: Not even present in the CRD Arguments.of("aShortObj", "integer"), Arguments.of("aInt", "integer"), diff --git a/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/utils/KubernetesSerialization.java b/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/utils/KubernetesSerialization.java index 609bf20a0ef..db04df0247c 100644 --- a/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/utils/KubernetesSerialization.java +++ b/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/utils/KubernetesSerialization.java @@ -27,6 +27,7 @@ import com.fasterxml.jackson.databind.KeyDeserializer; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationConfig; +import com.fasterxml.jackson.databind.SerializationFeature; import com.fasterxml.jackson.databind.cfg.HandlerInstantiator; import com.fasterxml.jackson.databind.cfg.MapperConfig; import com.fasterxml.jackson.databind.introspect.Annotated; @@ -90,6 +91,8 @@ public KubernetesSerialization(ObjectMapper mapper, boolean searchClassloaders) protected void configureMapper(ObjectMapper mapper) { mapper.registerModules(new JavaTimeModule(), unmatchedFieldTypeModule); mapper.disable(DeserializationFeature.FAIL_ON_INVALID_SUBTYPE); + mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); + mapper.disable(SerializationFeature.WRITE_DURATIONS_AS_TIMESTAMPS); // omit null fields, but keep null map values mapper.setDefaultPropertyInclusion(JsonInclude.Value.construct(Include.NON_NULL, Include.ALWAYS)); HandlerInstantiator instanciator = mapper.getDeserializationConfig().getHandlerInstantiator(); From e873bf6ed66b27e8672a4063d22b9cfeaebbc7ac Mon Sep 17 00:00:00 2001 From: erabii Date: Mon, 29 Apr 2024 10:52:30 +0300 Subject: [PATCH 09/11] fix: clean leader election related classes (5937) * clean-up * chekstyle * drop @Getter * chekstyle * placeholder commit --- .../client/extended/leaderelection/LeaderCallbacks.java | 6 +++--- .../client/extended/leaderelection/LeaderElector.java | 7 ++----- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/extended/leaderelection/LeaderCallbacks.java b/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/extended/leaderelection/LeaderCallbacks.java index 2fdb5047ec7..71ed61dc0c0 100644 --- a/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/extended/leaderelection/LeaderCallbacks.java +++ b/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/extended/leaderelection/LeaderCallbacks.java @@ -20,9 +20,9 @@ public class LeaderCallbacks { - private Runnable onStartLeading; - private Runnable onStopLeading; - private Consumer onNewLeader; + private final Runnable onStartLeading; + private final Runnable onStopLeading; + private final Consumer onNewLeader; public LeaderCallbacks(Runnable onStartLeading, Runnable onStopLeading, Consumer onNewLeader) { this.onStartLeading = Objects.requireNonNull(onStartLeading, "onStartLeading callback is required"); diff --git a/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/extended/leaderelection/LeaderElector.java b/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/extended/leaderelection/LeaderElector.java index 8b63cfbd229..7d02e0cf7f2 100644 --- a/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/extended/leaderelection/LeaderElector.java +++ b/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/extended/leaderelection/LeaderElector.java @@ -25,7 +25,6 @@ import java.net.HttpURLConnection; import java.time.Duration; -import java.time.LocalDateTime; import java.time.ZoneOffset; import java.time.ZonedDateTime; import java.time.temporal.ChronoUnit; @@ -46,10 +45,9 @@ public class LeaderElector { protected static final Double JITTER_FACTOR = 1.2; - private KubernetesClient kubernetesClient; - private LeaderElectionConfig leaderElectionConfig; + private final KubernetesClient kubernetesClient; + private final LeaderElectionConfig leaderElectionConfig; private final AtomicReference observedRecord = new AtomicReference<>(); - private final AtomicReference observedTime = new AtomicReference<>(); private final Executor executor; private boolean started; private boolean stopped; @@ -254,7 +252,6 @@ synchronized boolean tryAcquireOrRenew() { private void updateObserved(LeaderElectionRecord leaderElectionRecord) { final LeaderElectionRecord current = observedRecord.getAndSet(leaderElectionRecord); if (!Objects.equals(leaderElectionRecord, current)) { - observedTime.set(LocalDateTime.now()); final String currentLeader = current == null ? null : current.getHolderIdentity(); final String newLeader = leaderElectionRecord.getHolderIdentity(); if (!Objects.equals(newLeader, currentLeader)) { From 20c6b0cb3baef1da8379a6442a1e0988c70bcd48 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 29 Apr 2024 14:27:04 +0200 Subject: [PATCH 10/11] chore(deps): bump org.apache.maven.plugins:maven-install-plugin Bumps [org.apache.maven.plugins:maven-install-plugin](https://github.com/apache/maven-install-plugin) from 3.1.1 to 3.1.2. - [Release notes](https://github.com/apache/maven-install-plugin/releases) - [Commits](https://github.com/apache/maven-install-plugin/compare/maven-install-plugin-3.1.1...maven-install-plugin-3.1.2) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-install-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 72ccfd3ad91..d214e3e956f 100644 --- a/pom.xml +++ b/pom.xml @@ -160,7 +160,7 @@ 3.1.0 3.6.1 3.5.3 - 3.1.1 + 3.1.2 3.6.1 3.12.0 3.0.2 From 8cf7b2defc16b6b5b98f1ad31b764ca0810a677c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 29 Apr 2024 16:13:02 +0200 Subject: [PATCH 11/11] chore(deps): bump org.apache.maven.plugins:maven-deploy-plugin Bumps [org.apache.maven.plugins:maven-deploy-plugin](https://github.com/apache/maven-deploy-plugin) from 3.1.1 to 3.1.2. - [Release notes](https://github.com/apache/maven-deploy-plugin/releases) - [Commits](https://github.com/apache/maven-deploy-plugin/compare/maven-deploy-plugin-3.1.1...maven-deploy-plugin-3.1.2) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-deploy-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index d214e3e956f..7daa1e6e824 100644 --- a/pom.xml +++ b/pom.xml @@ -155,7 +155,7 @@ 3.6.3 3.3.1 3.4.1 - 3.1.1 + 3.1.2 3.2.4 3.1.0 3.6.1