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 6485ac1
Show file tree
Hide file tree
Showing 16 changed files with 208 additions and 163 deletions.
9 changes: 8 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,20 @@ 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 package
cd kubernetes-model-generator/openapi/maven-plugin && mvn clean verify
cd kubernetes-model-generator/kubernetes-model-core && mvn -Pgenerate clean package

# 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
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
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,19 @@ public class LimitRangeItem implements Editable<LimitRangeItemBuilder> , Kuberne

@JsonProperty("default")
@JsonInclude(JsonInclude.Include.NON_EMPTY)
private Map<String, io.fabric8.kubernetes.api.model.Quantity> _default = new LinkedHashMap<>();
private Map<String, Quantity> _default = new LinkedHashMap<>();
@JsonProperty("defaultRequest")
@JsonInclude(JsonInclude.Include.NON_EMPTY)
private Map<String, io.fabric8.kubernetes.api.model.Quantity> defaultRequest = new LinkedHashMap<>();
private Map<String, Quantity> defaultRequest = new LinkedHashMap<>();
@JsonProperty("max")
@JsonInclude(JsonInclude.Include.NON_EMPTY)
private Map<String, io.fabric8.kubernetes.api.model.Quantity> max = new LinkedHashMap<>();
private Map<String, Quantity> max = new LinkedHashMap<>();
@JsonProperty("maxLimitRequestRatio")
@JsonInclude(JsonInclude.Include.NON_EMPTY)
private Map<String, io.fabric8.kubernetes.api.model.Quantity> maxLimitRequestRatio = new LinkedHashMap<>();
private Map<String, Quantity> maxLimitRequestRatio = new LinkedHashMap<>();
@JsonProperty("min")
@JsonInclude(JsonInclude.Include.NON_EMPTY)
private Map<String, io.fabric8.kubernetes.api.model.Quantity> min = new LinkedHashMap<>();
private Map<String, Quantity> min = new LinkedHashMap<>();
@JsonProperty("type")
private String type;
@JsonIgnore
Expand All @@ -65,7 +65,7 @@ public class LimitRangeItem implements Editable<LimitRangeItemBuilder> , Kuberne
public LimitRangeItem() {
}

public LimitRangeItem(Map<String, io.fabric8.kubernetes.api.model.Quantity> _default, Map<String, io.fabric8.kubernetes.api.model.Quantity> defaultRequest, Map<String, io.fabric8.kubernetes.api.model.Quantity> max, Map<String, io.fabric8.kubernetes.api.model.Quantity> maxLimitRequestRatio, Map<String, io.fabric8.kubernetes.api.model.Quantity> min, String type) {
public LimitRangeItem(Map<String, Quantity> _default, Map<String, Quantity> defaultRequest, Map<String, Quantity> max, Map<String, Quantity> maxLimitRequestRatio, Map<String, Quantity> min, String type) {
super();
this._default = _default;
this.defaultRequest = defaultRequest;
Expand All @@ -77,56 +77,56 @@ public LimitRangeItem(Map<String, io.fabric8.kubernetes.api.model.Quantity> _def

@JsonProperty("default")
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public Map<String, io.fabric8.kubernetes.api.model.Quantity> getDefault() {
public Map<String, Quantity> getDefault() {
return _default;
}

@JsonProperty("default")
public void setDefault(Map<String, io.fabric8.kubernetes.api.model.Quantity> _default) {
public void setDefault(Map<String, Quantity> _default) {
this._default = _default;
}

@JsonProperty("defaultRequest")
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public Map<String, io.fabric8.kubernetes.api.model.Quantity> getDefaultRequest() {
public Map<String, Quantity> getDefaultRequest() {
return defaultRequest;
}

@JsonProperty("defaultRequest")
public void setDefaultRequest(Map<String, io.fabric8.kubernetes.api.model.Quantity> defaultRequest) {
public void setDefaultRequest(Map<String, Quantity> defaultRequest) {
this.defaultRequest = defaultRequest;
}

@JsonProperty("max")
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public Map<String, io.fabric8.kubernetes.api.model.Quantity> getMax() {
public Map<String, Quantity> getMax() {
return max;
}

@JsonProperty("max")
public void setMax(Map<String, io.fabric8.kubernetes.api.model.Quantity> max) {
public void setMax(Map<String, Quantity> max) {
this.max = max;
}

@JsonProperty("maxLimitRequestRatio")
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public Map<String, io.fabric8.kubernetes.api.model.Quantity> getMaxLimitRequestRatio() {
public Map<String, Quantity> getMaxLimitRequestRatio() {
return maxLimitRequestRatio;
}

@JsonProperty("maxLimitRequestRatio")
public void setMaxLimitRequestRatio(Map<String, io.fabric8.kubernetes.api.model.Quantity> maxLimitRequestRatio) {
public void setMaxLimitRequestRatio(Map<String, Quantity> maxLimitRequestRatio) {
this.maxLimitRequestRatio = maxLimitRequestRatio;
}

@JsonProperty("min")
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public Map<String, io.fabric8.kubernetes.api.model.Quantity> getMin() {
public Map<String, Quantity> getMin() {
return min;
}

@JsonProperty("min")
public void setMin(Map<String, io.fabric8.kubernetes.api.model.Quantity> min) {
public void setMin(Map<String, Quantity> min) {
this.min = min;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ public class NodeStatus implements Editable<NodeStatusBuilder> , KubernetesResou
private List<NodeAddress> addresses = new ArrayList<>();
@JsonProperty("allocatable")
@JsonInclude(JsonInclude.Include.NON_EMPTY)
private Map<String, io.fabric8.kubernetes.api.model.Quantity> allocatable = new LinkedHashMap<>();
private Map<String, Quantity> allocatable = new LinkedHashMap<>();
@JsonProperty("capacity")
@JsonInclude(JsonInclude.Include.NON_EMPTY)
private Map<String, io.fabric8.kubernetes.api.model.Quantity> capacity = new LinkedHashMap<>();
private Map<String, Quantity> capacity = new LinkedHashMap<>();
@JsonProperty("conditions")
@JsonInclude(JsonInclude.Include.NON_EMPTY)
private List<NodeCondition> conditions = new ArrayList<>();
Expand Down Expand Up @@ -88,7 +88,7 @@ public class NodeStatus implements Editable<NodeStatusBuilder> , KubernetesResou
public NodeStatus() {
}

public NodeStatus(List<NodeAddress> addresses, Map<String, io.fabric8.kubernetes.api.model.Quantity> allocatable, Map<String, io.fabric8.kubernetes.api.model.Quantity> capacity, List<NodeCondition> conditions, NodeConfigStatus config, NodeDaemonEndpoints daemonEndpoints, List<ContainerImage> images, NodeSystemInfo nodeInfo, String phase, List<NodeRuntimeHandler> runtimeHandlers, List<AttachedVolume> volumesAttached, List<String> volumesInUse) {
public NodeStatus(List<NodeAddress> addresses, Map<String, Quantity> allocatable, Map<String, Quantity> capacity, List<NodeCondition> conditions, NodeConfigStatus config, NodeDaemonEndpoints daemonEndpoints, List<ContainerImage> images, NodeSystemInfo nodeInfo, String phase, List<NodeRuntimeHandler> runtimeHandlers, List<AttachedVolume> volumesAttached, List<String> volumesInUse) {
super();
this.addresses = addresses;
this.allocatable = allocatable;
Expand Down Expand Up @@ -117,23 +117,23 @@ public void setAddresses(List<NodeAddress> addresses) {

@JsonProperty("allocatable")
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public Map<String, io.fabric8.kubernetes.api.model.Quantity> getAllocatable() {
public Map<String, Quantity> getAllocatable() {
return allocatable;
}

@JsonProperty("allocatable")
public void setAllocatable(Map<String, io.fabric8.kubernetes.api.model.Quantity> allocatable) {
public void setAllocatable(Map<String, Quantity> allocatable) {
this.allocatable = allocatable;
}

@JsonProperty("capacity")
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public Map<String, io.fabric8.kubernetes.api.model.Quantity> getCapacity() {
public Map<String, Quantity> getCapacity() {
return capacity;
}

@JsonProperty("capacity")
public void setCapacity(Map<String, io.fabric8.kubernetes.api.model.Quantity> capacity) {
public void setCapacity(Map<String, Quantity> capacity) {
this.capacity = capacity;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@
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;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import lombok.experimental.Accessors;
Expand All @@ -34,18 +38,33 @@
""
})
@Buildable(editableEnabled = false, validationEnabled = false, generateBuilderPackage = false, lazyCollectionInitEnabled = false, builderPackage = "io.fabric8.kubernetes.api.builder")
@TemplateTransformations({
@TemplateTransformation(value = "/manifest.vm", outputPath = "META-INF/services/io.fabric8.kubernetes.api.model.KubernetesResource", gather = true)
})
@Version("v1")
@Group("")
@Generated("jsonschema2pojo")
public class OwnerReference implements Editable<OwnerReferenceBuilder> , KubernetesResource
{

/**
*
* (Required)
*
*/
@JsonProperty("apiVersion")
private String apiVersion;
private String apiVersion = "v1";
@JsonProperty("blockOwnerDeletion")
private Boolean blockOwnerDeletion;
@JsonProperty("controller")
private Boolean controller;
/**
*
* (Required)
*
*/
@JsonProperty("kind")
private String kind;
private String kind = "OwnerReference";
@JsonProperty("name")
private String name;
@JsonProperty("uid")
Expand All @@ -70,11 +89,21 @@ public OwnerReference(String apiVersion, Boolean blockOwnerDeletion, Boolean con
this.uid = uid;
}

/**
*
* (Required)
*
*/
@JsonProperty("apiVersion")
public String getApiVersion() {
return apiVersion;
}

/**
*
* (Required)
*
*/
@JsonProperty("apiVersion")
public void setApiVersion(String apiVersion) {
this.apiVersion = apiVersion;
Expand All @@ -100,11 +129,21 @@ public void setController(Boolean controller) {
this.controller = controller;
}

/**
*
* (Required)
*
*/
@JsonProperty("kind")
public String getKind() {
return kind;
}

/**
*
* (Required)
*
*/
@JsonProperty("kind")
public void setKind(String kind) {
this.kind = kind;
Expand Down
Loading

0 comments on commit 6485ac1

Please sign in to comment.