diff --git a/CHANGELOG.md b/CHANGELOG.md index d7f12171c29..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 @@ -10,12 +11,14 @@ * 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 #### 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/api/pom.xml b/crd-generator/api/pom.xml index 49574461d2f..6000dfd0cb1 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 @@ -76,12 +76,27 @@ junit-jupiter-engine test + + org.junit.jupiter + junit-jupiter-params + test + + + org.assertj + assertj-core + test + org.slf4j slf4j-simple ${slf4j.version} test + + com.approvaltests + approvaltests + test + javax.validation validation-api 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/java/io/fabric8/crd/generator/CRDGeneratorExamplesTest.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/CRDGeneratorExamplesTest.java deleted file mode 100644 index 51a050b4aba..00000000000 --- a/crd-generator/api/src/test/java/io/fabric8/crd/generator/CRDGeneratorExamplesTest.java +++ /dev/null @@ -1,62 +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; - -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 java.io.IOException; - -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); - } - - @Group("sample.fabric8.io") - @Version(value = "v3") - 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)); - } - - @Test - void k8sValidation() throws IOException { - assertCRDOutputEquals(newCRDGenerator(), K8sValidation.class); - } - - private CRDGenerator newCRDGenerator() { - return new CRDGenerator() - .withParallelGenerationEnabled(parallelCRDGeneration); - } - -} 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 new file mode 100644 index 00000000000..099af018ee3 --- /dev/null +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/MultipleStoredVersionsTest.java @@ -0,0 +1,60 @@ +/* + * 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; + +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.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.assertj.core.api.Assertions.assertThatIllegalStateException; + +class MultipleStoredVersionsTest { + + @Group("sample.fabric8.io") + @Version(value = "v3") + public static class Multiple extends CustomResource { + } + + @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."); + } + + static Stream multipleCrdVersions() { + return Stream.of("v1", "v1beta1") + .flatMap(crdVersion -> Stream.of( + Arguments.of(crdVersion, false), + Arguments.of(crdVersion, true))); + } +} 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..da4871e799e --- /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.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; +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.v1.Multiple.class, + io.fabric8.crd.generator.approvaltests.multipleversions.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 new file mode 100644 index 00000000000..a9bf45dc312 --- /dev/null +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/PackageSettings.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; + +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(); + public String ApprovalBaseDirectory = "../resources"; +} diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/annotated/Annotated.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/annotated/Annotated.java new file mode 100644 index 00000000000..9657a25274d --- /dev/null +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/annotated/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; + +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/AnnotatedSpec.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/annotated/AnnotatedSpec.java new file mode 100644 index 00000000000..d875fee3bf3 --- /dev/null +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/annotated/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; + +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/Complex.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/Complex.java new file mode 100644 index 00000000000..c9832e80be7 --- /dev/null +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/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; + +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/ComplexSpec.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/ComplexSpec.java new file mode 100644 index 00000000000..326e78f7ea9 --- /dev/null +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/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; + +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/ComplexStatus.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/ComplexStatus.java new file mode 100644 index 00000000000..2ea1ae87346 --- /dev/null +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/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; + +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/ServiceConfiguration.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/ServiceConfiguration.java new file mode 100644 index 00000000000..ea82a685f90 --- /dev/null +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/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; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyDescription; +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") +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/StatefulSetConfiguration.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/StatefulSetConfiguration.java new file mode 100644 index 00000000000..4099e649370 --- /dev/null +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/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; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyDescription; +import io.fabric8.crd.generator.approvaltests.complex.k8s.ObjectMeta; +import io.fabric8.crd.generator.approvaltests.complex.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/k8s/ObjectMeta.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/k8s/ObjectMeta.java new file mode 100644 index 00000000000..e8af8010ef2 --- /dev/null +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/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.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/k8s/ServiceSpec.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/k8s/ServiceSpec.java new file mode 100644 index 00000000000..ccfdb14a6d2 --- /dev/null +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/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.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/k8s/StatefulSetSpec.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/k8s/StatefulSetSpec.java new file mode 100644 index 00000000000..3af389927c2 --- /dev/null +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/complex/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.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/Base.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/inherited/Base.java new file mode 100644 index 00000000000..3bda352b759 --- /dev/null +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/inherited/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; + +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/BaseSpec.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/inherited/BaseSpec.java new file mode 100644 index 00000000000..28d906d9939 --- /dev/null +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/inherited/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; + +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/BaseStatus.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/inherited/BaseStatus.java new file mode 100644 index 00000000000..fadf5a3182d --- /dev/null +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/inherited/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; + +/** + * @author Christophe Laprun + */ +public class BaseStatus { + +} diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/inherited/Child.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/inherited/Child.java new file mode 100644 index 00000000000..ca39f5b41f8 --- /dev/null +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/inherited/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; + +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/ChildSpec.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/inherited/ChildSpec.java new file mode 100644 index 00000000000..352ab4e4d7a --- /dev/null +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/inherited/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; + +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/ChildStatus.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/inherited/ChildStatus.java new file mode 100644 index 00000000000..7f3674683fe --- /dev/null +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/inherited/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; + +/** + * @author Christophe Laprun + */ +public class ChildStatus extends BaseStatus { + +} diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/json/ContainingJson.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/json/ContainingJson.java new file mode 100644 index 00000000000..55d4255c57b --- /dev/null +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/json/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; + +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/ContainingJsonSpec.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/json/ContainingJsonSpec.java new file mode 100644 index 00000000000..7f1be1d0f5e --- /dev/null +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/json/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; + +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/Foo.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/json/Foo.java new file mode 100644 index 00000000000..3e27b063f26 --- /dev/null +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/json/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; + +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/K8sValidation.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/k8svalidation/K8sValidation.java new file mode 100644 index 00000000000..a75bcff636e --- /dev/null +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/k8svalidation/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; + +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/K8sValidationSpec.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/k8svalidation/K8sValidationSpec.java new file mode 100644 index 00000000000..43250e81d92 --- /dev/null +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/k8svalidation/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; + +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/K8sValidationStatus.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/k8svalidation/K8sValidationStatus.java new file mode 100644 index 00000000000..73c9f4f2487 --- /dev/null +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/k8svalidation/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; + +public class K8sValidationStatus { + Integer availableReplicas; +} diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/map/ContainingMaps.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/map/ContainingMaps.java new file mode 100644 index 00000000000..28e666a7232 --- /dev/null +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/map/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; + +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/ContainingMapsSpec.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/map/ContainingMapsSpec.java new file mode 100644 index 00000000000..e59b1848bd4 --- /dev/null +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/map/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; + +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/v1/Multiple.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/multipleversions/v1/Multiple.java new file mode 100644 index 00000000000..764dec43074 --- /dev/null +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/multipleversions/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.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/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/v1/MultipleSpec.java index 2073b71b7a8..46bb4660c9e 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/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.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/v2/Multiple.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/multipleversions/v2/Multiple.java new file mode 100644 index 00000000000..9a6d061ee26 --- /dev/null +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/multipleversions/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.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/v2/MultipleSpec.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/multipleversions/v2/MultipleSpec.java new file mode 100644 index 00000000000..098fb2e0851 --- /dev/null +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/multipleversions/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.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/NoCyclic.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/nocyclic/NoCyclic.java new file mode 100644 index 00000000000..40c67910048 --- /dev/null +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/nocyclic/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; + +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/NoCyclicSpec.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/nocyclic/NoCyclicSpec.java new file mode 100644 index 00000000000..448ed9e4a22 --- /dev/null +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/nocyclic/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; + +public class NoCyclicSpec { + private Ref ref1; + private Ref ref2; +} diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/nocyclic/NoCyclicStatus.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/nocyclic/NoCyclicStatus.java new file mode 100644 index 00000000000..99cf43202bb --- /dev/null +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/nocyclic/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; + +public class NoCyclicStatus { + private String message; + private Ref ref1; +} diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/nocyclic/Ref.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/nocyclic/Ref.java new file mode 100644 index 00000000000..35c6b2fed0e --- /dev/null +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/approvaltests/nocyclic/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; + +public class Ref { + + private int ref; + + protected Inner inner; + + public static class Inner { + } + +} diff --git a/crd-generator/api/src/test/resources/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.approvalTest.annotateds.samples.fabric8.io.v1.approved.txt b/crd-generator/api/src/test/resources/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.approvalTest.annotateds.samples.fabric8.io.v1.approved.txt new file mode 100644 index 00000000000..82da118d7de --- /dev/null +++ b/crd-generator/api/src/test/resources/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.approvalTest.annotateds.samples.fabric8.io.v1.approved.txt @@ -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 diff --git a/crd-generator/api/src/test/resources/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.approvalTest.annotateds.samples.fabric8.io.v1beta1.approved.txt b/crd-generator/api/src/test/resources/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.approvalTest.annotateds.samples.fabric8.io.v1beta1.approved.txt new file mode 100644 index 00000000000..d3fcf7cd9e9 --- /dev/null +++ b/crd-generator/api/src/test/resources/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.approvalTest.annotateds.samples.fabric8.io.v1beta1.approved.txt @@ -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 diff --git a/crd-generator/api/src/test/resources/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.approvalTest.children.sample.fabric8.io.v1.approved.txt b/crd-generator/api/src/test/resources/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.approvalTest.children.sample.fabric8.io.v1.approved.txt new file mode 100644 index 00000000000..2ae0d789efa --- /dev/null +++ b/crd-generator/api/src/test/resources/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.approvalTest.children.sample.fabric8.io.v1.approved.txt @@ -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/resources/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.approvalTest.children.sample.fabric8.io.v1beta1.approved.txt b/crd-generator/api/src/test/resources/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.approvalTest.children.sample.fabric8.io.v1beta1.approved.txt new file mode 100644 index 00000000000..5824f453b80 --- /dev/null +++ b/crd-generator/api/src/test/resources/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.approvalTest.children.sample.fabric8.io.v1beta1.approved.txt @@ -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/resources/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.approvalTest.complexkinds.samples.fabric8.io.v1.approved.txt b/crd-generator/api/src/test/resources/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.approvalTest.complexkinds.samples.fabric8.io.v1.approved.txt new file mode 100644 index 00000000000..7a3ca65680e --- /dev/null +++ b/crd-generator/api/src/test/resources/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.approvalTest.complexkinds.samples.fabric8.io.v1.approved.txt @@ -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/resources/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.approvalTest.complexkinds.samples.fabric8.io.v1beta1.approved.txt b/crd-generator/api/src/test/resources/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.approvalTest.complexkinds.samples.fabric8.io.v1beta1.approved.txt new file mode 100644 index 00000000000..5aa1169b6a2 --- /dev/null +++ b/crd-generator/api/src/test/resources/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.approvalTest.complexkinds.samples.fabric8.io.v1beta1.approved.txt @@ -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/resources/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.approvalTest.containingjsons.sample.fabric8.io.v1.approved.txt b/crd-generator/api/src/test/resources/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.approvalTest.containingjsons.sample.fabric8.io.v1.approved.txt new file mode 100644 index 00000000000..89592cd1f07 --- /dev/null +++ b/crd-generator/api/src/test/resources/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.approvalTest.containingjsons.sample.fabric8.io.v1.approved.txt @@ -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/resources/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.approvalTest.containingjsons.sample.fabric8.io.v1beta1.approved.txt b/crd-generator/api/src/test/resources/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.approvalTest.containingjsons.sample.fabric8.io.v1beta1.approved.txt new file mode 100644 index 00000000000..051a0a5934f --- /dev/null +++ b/crd-generator/api/src/test/resources/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.approvalTest.containingjsons.sample.fabric8.io.v1beta1.approved.txt @@ -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/resources/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.approvalTest.containingmaps.sample.fabric8.io.v1.approved.txt b/crd-generator/api/src/test/resources/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.approvalTest.containingmaps.sample.fabric8.io.v1.approved.txt new file mode 100644 index 00000000000..3a65e673ccf --- /dev/null +++ b/crd-generator/api/src/test/resources/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.approvalTest.containingmaps.sample.fabric8.io.v1.approved.txt @@ -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/resources/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.approvalTest.containingmaps.sample.fabric8.io.v1beta1.approved.txt b/crd-generator/api/src/test/resources/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.approvalTest.containingmaps.sample.fabric8.io.v1beta1.approved.txt new file mode 100644 index 00000000000..97cf0fd7efd --- /dev/null +++ b/crd-generator/api/src/test/resources/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.approvalTest.containingmaps.sample.fabric8.io.v1beta1.approved.txt @@ -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/resources/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.approvalTest.k8svalidations.samples.fabric8.io.v1.approved.txt b/crd-generator/api/src/test/resources/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.approvalTest.k8svalidations.samples.fabric8.io.v1.approved.txt new file mode 100644 index 00000000000..7205b7ea70b --- /dev/null +++ b/crd-generator/api/src/test/resources/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.approvalTest.k8svalidations.samples.fabric8.io.v1.approved.txt @@ -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/resources/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.approvalTest.k8svalidations.samples.fabric8.io.v1beta1.approved.txt b/crd-generator/api/src/test/resources/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.approvalTest.k8svalidations.samples.fabric8.io.v1beta1.approved.txt new file mode 100644 index 00000000000..64e2731f98e --- /dev/null +++ b/crd-generator/api/src/test/resources/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.approvalTest.k8svalidations.samples.fabric8.io.v1beta1.approved.txt @@ -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 diff --git a/crd-generator/api/src/test/resources/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.approvalTest.multiples.sample.fabric8.io.v1.approved.txt b/crd-generator/api/src/test/resources/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.approvalTest.multiples.sample.fabric8.io.v1.approved.txt new file mode 100644 index 00000000000..b94afd65aed --- /dev/null +++ b/crd-generator/api/src/test/resources/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.approvalTest.multiples.sample.fabric8.io.v1.approved.txt @@ -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/resources/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.approvalTest.multiples.sample.fabric8.io.v1beta1.approved.txt b/crd-generator/api/src/test/resources/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.approvalTest.multiples.sample.fabric8.io.v1beta1.approved.txt new file mode 100644 index 00000000000..496bc0f8362 --- /dev/null +++ b/crd-generator/api/src/test/resources/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.approvalTest.multiples.sample.fabric8.io.v1beta1.approved.txt @@ -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/resources/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.approvalTest.nocyclics.sample.fabric8.io.v1.approved.txt b/crd-generator/api/src/test/resources/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.approvalTest.nocyclics.sample.fabric8.io.v1.approved.txt new file mode 100644 index 00000000000..3d40aa4f5c6 --- /dev/null +++ b/crd-generator/api/src/test/resources/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.approvalTest.nocyclics.sample.fabric8.io.v1.approved.txt @@ -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/resources/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.approvalTest.nocyclics.sample.fabric8.io.v1beta1.approved.txt b/crd-generator/api/src/test/resources/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.approvalTest.nocyclics.sample.fabric8.io.v1beta1.approved.txt new file mode 100644 index 00000000000..546f2ccd875 --- /dev/null +++ b/crd-generator/api/src/test/resources/io/fabric8/crd/generator/approvaltests/CRDGeneratorApprovalTest.approvalTest.nocyclics.sample.fabric8.io.v1beta1.approved.txt @@ -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/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 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/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/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)) { 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 d3a00fa548f..ea2a04d1829 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(); diff --git a/pom.xml b/pom.xml index 5d567e948a9..a7fdf724e4e 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 @@ -155,12 +155,12 @@ 3.6.3 3.3.1 3.4.1 - 3.1.1 + 3.1.2 3.2.4 3.1.0 3.6.1 - 3.5.2 - 3.1.1 + 3.5.3 + 3.1.2 3.6.1 3.12.0 3.0.2 @@ -1256,6 +1256,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/resources/**/*.approved.txt **/it/**/expected/**/*.expected Jenkinsfile .mvn/**/*