Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of github.com:fabric8io/kubernetes-client into cr…
Browse files Browse the repository at this point in the history
…d-generator-v7-development
shawkins committed Apr 29, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
2 parents ef05f18 + 8cf7b2d commit f239671
Showing 63 changed files with 3,413 additions and 105 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -3,19 +3,22 @@
### 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
* Fix #5878: (java-generator) Add implements Editable for extraAnnotations
* 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)

17 changes: 16 additions & 1 deletion crd-generator/api/pom.xml
Original file line number Diff line number Diff line change
@@ -35,7 +35,7 @@
<artifactId>kubernetes-client-api</artifactId>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-jsonSchema</artifactId>
@@ -76,12 +76,27 @@
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>${slf4j.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.approvaltests</groupId>
<artifactId>approvaltests</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
Original file line number Diff line number Diff line change
@@ -400,7 +400,11 @@ private T internalFromImpl(TypeDef definition, LinkedHashMap<String, String> vis
.collect(Collectors.toList());

swaps.throwIfUnmatchedSwaps();
return build(builder, required, validationRules, preserveUnknownFields);

List<String> sortedRequiredProperties = required.stream().sorted()
.collect(Collectors.toList());

return build(builder, sortedRequiredProperties, validationRules, preserveUnknownFields);
}

private Map<String, Method> indexPotentialAccessors(TypeDef definition) {

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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<MultipleSpec, Void> {
}

@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<Arguments> multipleCrdVersions() {
return Stream.of("v1", "v1beta1")
.flatMap(crdVersion -> Stream.of(
Arguments.of(crdVersion, false),
Arguments.of(crdVersion, true)));
}
}
Original file line number Diff line number Diff line change
@@ -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<? extends CustomResource<?, ?>>[] crClasses, String expectedCrd, String version, boolean parallel)
throws IOException {
Approvals.settings().allowMultipleVerifyCallsForThisMethod();
final Map<String, Map<String, CRDInfo>> 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<Arguments> crdApprovalTests() {
final List<TestCase> 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<? extends CustomResource<?, ?>>[] crClasses;
private String expectedCrd;
private String version;
private boolean parallel;

public TestCase(String expectedCrd, String version, boolean parallel, Class<? extends CustomResource<?, ?>>... crClasses) {
this.expectedCrd = expectedCrd;
this.version = version;
this.parallel = parallel;
this.crClasses = crClasses;
}
}

}
Original file line number Diff line number Diff line change
@@ -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 <a href=
* "https://github.com/approvals/ApprovalTests.Java/blob/master/approvaltests/docs/explanations/BestConfigurationPractices.md">
* ApprovalTests - Best Configuration Practices</a>
*/
public class PackageSettings {
/**
* Disable Diff-Reporter
*/
@SuppressWarnings("unused")
public static ApprovalFailureReporter UseReporter = new QuietReporter();
public String ApprovalBaseDirectory = "../resources";
}
Original file line number Diff line number Diff line change
@@ -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<AnnotatedSpec, Void> {

}
Loading

0 comments on commit f239671

Please sign in to comment.