Skip to content

Commit

Permalink
refactor: kubernetes-model-core generated from OpenAPI schemas
Browse files Browse the repository at this point in the history
Signed-off-by: Marc Nuri <[email protected]>
  • Loading branch information
manusa committed Jul 22, 2024
1 parent 88adc1e commit 5e42bfe
Show file tree
Hide file tree
Showing 19 changed files with 255 additions and 338 deletions.
10 changes: 9 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,21 @@ generate-openapi:
cd kubernetes-model-generator/openapi/generator && go build
./kubernetes-model-generator/openapi/generator/generator ./kubernetes-model-generator/openapi/schemas

.PHONY: generate-openapi-classes
generate-openapi-classes:
# TODO: Do for all modules once they've all been migrated
# cd kubernetes-model-generator && mvn -Pgenerate clean install
cd kubernetes-model-generator/kubernetes-model-common && mvn clean install
cd kubernetes-model-generator/openapi/maven-plugin && mvn clean verify
cd kubernetes-model-generator/kubernetes-model-core && mvn -Pgenerate clean install

# Legacy generation of the model: TODO: remove
.PHONY: generate-model-legacy
generate-model-legacy:
cd kubernetes-model-generator && ./generateModel.sh

.PHONY: generate-model
generate-model: generate-openapi generate-model-legacy
generate-model: generate-openapi generate-openapi-classes generate-model-legacy

.PHONY: sonar
sonar:
Expand Down
1 change: 0 additions & 1 deletion kubernetes-model-generator/generateModel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ ABSOLUTE_BASEDIR=$(realpath "$BASEDIR")

# Array for all existing modules
declare -a modules=(
"kubernetes-model-core"
"kubernetes-model-rbac"
"kubernetes-model-admissionregistration"
"kubernetes-model-apiextensions"
Expand Down
27 changes: 0 additions & 27 deletions kubernetes-model-generator/kubernetes-model-core/Makefile

This file was deleted.

This file was deleted.

82 changes: 22 additions & 60 deletions kubernetes-model-generator/kubernetes-model-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -130,74 +130,36 @@
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>attach-artifacts</id>
<configuration>
<skipAttach>false</skipAttach>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>generate</id>
<build>
<plugins>
<plugin>
<groupId>org.jsonschema2pojo</groupId>
<artifactId>jsonschema2pojo-maven-plugin</artifactId>
<configuration>
<customAnnotator>io.fabric8.kubernetes.jsonschema2pojo.KubernetesCoreTypeAnnotator</customAnnotator>
<groupId>io.fabric8</groupId>
<artifactId>openapi-model-generator-maven-plugin</artifactId>
<configuration >
<settings combine.self="append">
<addBuildableReferences>false</addBuildableReferences>
<schemas>
<schema>${project.basedir}/../openapi/schemas/kubernetes-1.30.0.json</schema>
<schema>${project.basedir}/../openapi/schemas/api-machinery-extra.json</schema>
<schema>${project.basedir}/../openapi/schemas/admission-registration.json</schema>
</schemas>
<packageMappings combine.self="append">
<io.k8s.client-go.tools.clientcmd.api.v1>io.fabric8.kubernetes.api.model</io.k8s.client-go.tools.clientcmd.api.v1>
<io.k8s.kube-aggregator.pkg.apis.apiregistration.v1>io.fabric8.kubernetes.api.model</io.k8s.kube-aggregator.pkg.apis.apiregistration.v1>
</packageMappings>
<skipGenerationRegexes>
<skipGenerationRegex>^io\.k8s\.apimachinery\.pkg\.runtime\.RawExtension$</skipGenerationRegex>
</skipGenerationRegexes>
<includeGenerationRegexes>
<includeGenerationRegex>^io\.k8s\.api\.core\..*$</includeGenerationRegex>
<includeGenerationRegex>^io\.k8s\.apimachinery\..*$</includeGenerationRegex>
</includeGenerationRegexes>
</settings>
</configuration>
</plugin>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>generate-sources</phase>
<configuration>
<target>
<echo>Removing the duplicate generated class</echo>
<delete
file="${generate.targetDirectory}/io/fabric8/kubernetes/api/model/Duration.java"
verbose="true" />
<delete
file="${generate.targetDirectory}/io/fabric8/kubernetes/api/model/HasMetadata.java"
verbose="true" />
<delete
file="${generate.targetDirectory}/io/fabric8/kubernetes/api/model/IntOrString.java"
verbose="true" />
<delete
file="${generate.targetDirectory}/io/fabric8/kubernetes/api/model/Quantity.java"
verbose="true" />
<delete
file="${generate.targetDirectory}/io/fabric8/kubernetes/api/model/KubernetesResource.java"
verbose="true" />
<delete
file="${generate.targetDirectory}/io/fabric8/kubernetes/api/model/KubernetesList.java"
verbose="true" />
<delete verbose="true">
<fileset dir="${generate.targetDirectory}">
<include name="*.java" />
</fileset>
</delete>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import io.fabric8.kubernetes.api.builder.Editable;
import io.fabric8.kubernetes.model.annotation.Group;
import io.fabric8.kubernetes.model.annotation.Version;
import io.sundr.builder.annotations.Buildable;
import io.sundr.transform.annotations.TemplateTransformation;
import io.sundr.transform.annotations.TemplateTransformations;
Expand All @@ -39,6 +41,8 @@
@TemplateTransformations({
@TemplateTransformation(value = "/manifest.vm", outputPath = "META-INF/services/io.fabric8.kubernetes.api.model.KubernetesResource", gather = true)
})
@Version("v1")
@Group("")
@Generated("jsonschema2pojo")
public class APIResourceList implements Editable<APIResourceListBuilder> , KubernetesResource
{
Expand Down
Loading

0 comments on commit 5e42bfe

Please sign in to comment.