From 75ef612558af1519019d0c49df2d44eb94be8116 Mon Sep 17 00:00:00 2001 From: Marc Nuri Date: Mon, 22 Jul 2024 12:33:26 +0200 Subject: [PATCH] refactor: kubernetes-model-core generated from OpenAPI schemas Signed-off-by: Marc Nuri --- Makefile | 10 +- kubernetes-model-generator/generateModel.sh | 1 - .../kubernetes-model-core/Makefile | 27 --- .../cmd/generate/generate.go | 182 ------------------ .../kubernetes-model-core/pom.xml | 82 +++----- .../kubernetes/api/model/APIResourceList.java | 4 + .../kubernetes/api/model/LimitRangeItem.java | 32 +-- .../kubernetes/api/model/NodeStatus.java | 14 +- .../kubernetes/api/model/OwnerReference.java | 43 ++++- .../model/PersistentVolumeClaimStatus.java | 14 +- .../api/model/ResourceQuotaStatus.java | 14 +- .../api/model/ResourceRequirements.java | 14 +- .../kubernetes/api/model/TypeMeta.java | 43 ++++- .../api/model/VolumeResourceRequirements.java | 14 +- .../kubernetes/api/model/WatchEvent.java | 10 +- .../kubernetes/api/model/version/Info.java | 9 + .../schema/generator/GeneratorSettings.java | 11 +- kubernetes-model-generator/pom.xml | 26 +++ 18 files changed, 214 insertions(+), 336 deletions(-) delete mode 100644 kubernetes-model-generator/kubernetes-model-core/Makefile delete mode 100644 kubernetes-model-generator/kubernetes-model-core/cmd/generate/generate.go diff --git a/Makefile b/Makefile index 2444feba0c8..4278af7037d 100644 --- a/Makefile +++ b/Makefile @@ -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: diff --git a/kubernetes-model-generator/generateModel.sh b/kubernetes-model-generator/generateModel.sh index 74203087763..7b84bce102d 100755 --- a/kubernetes-model-generator/generateModel.sh +++ b/kubernetes-model-generator/generateModel.sh @@ -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" diff --git a/kubernetes-model-generator/kubernetes-model-core/Makefile b/kubernetes-model-generator/kubernetes-model-core/Makefile deleted file mode 100644 index c09a7003874..00000000000 --- a/kubernetes-model-generator/kubernetes-model-core/Makefile +++ /dev/null @@ -1,27 +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. -# - -SHELL := /bin/bash - -all: build - -build: gobuild - mvn -Pgenerate clean install -DskipTests - -gobuild: - CGO_ENABLED=0 GO15VENDOREXPERIMENT=1 go build -a ./cmd/generate/generate.go - ./generate > src/main/resources/schema/kube-schema.json - ./generate validation > src/main/resources/schema/validation-schema.json diff --git a/kubernetes-model-generator/kubernetes-model-core/cmd/generate/generate.go b/kubernetes-model-generator/kubernetes-model-core/cmd/generate/generate.go deleted file mode 100644 index 80b6baee55f..00000000000 --- a/kubernetes-model-generator/kubernetes-model-core/cmd/generate/generate.go +++ /dev/null @@ -1,182 +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 main - -import ( - "bytes" - "encoding/json" - "fmt" - "log" - "reflect" - "strings" - "time" - - kapi "k8s.io/api/core/v1" - "k8s.io/apimachinery/pkg/api/resource" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime" - apimachineryversion "k8s.io/apimachinery/pkg/version" - configapi "k8s.io/client-go/tools/clientcmd/api/v1" - aggregator "k8s.io/kube-aggregator/pkg/apis/apiregistration/v1" - - "os" - - "github.com/fabric8io/kubernetes-client/kubernetes-model-generator/pkg/schemagen" -) - -type Schema struct { - Info apimachineryversion.Info - APIGroup metav1.APIGroup - APIGroupList metav1.APIGroupList - APIResource metav1.APIResource - APIResourceList metav1.APIResourceList - APIVersions metav1.APIVersions - KubernetesList metav1.List - ObjectMeta metav1.ObjectMeta - TypeMeta metav1.TypeMeta - Status metav1.Status - Patch metav1.Patch - ListOptions metav1.ListOptions - DeleteOptions metav1.DeleteOptions - CreateOptions metav1.CreateOptions - UpdateOptions metav1.UpdateOptions - GetOptions metav1.GetOptions - PatchOptions metav1.PatchOptions - Time metav1.Time - MicroTime metav1.MicroTime - RootPaths metav1.RootPaths - GroupKind metav1.GroupKind - GroupVersionKind metav1.GroupVersionKind - GroupVersionResource metav1.GroupVersionResource - Quantity resource.Quantity - Condition metav1.Condition - WatchEvent metav1.WatchEvent - - PodList kapi.PodList - PodTemplateList kapi.PodTemplateList - PodExecOptions kapi.PodExecOptions - ReplicationControllerList kapi.ReplicationControllerList - ServiceList kapi.ServiceList - EndpointPort kapi.EndpointPort - Endpoints kapi.Endpoints - EndpointsList kapi.EndpointsList - Node kapi.Node - NodeList kapi.NodeList - EnvVar kapi.EnvVar - Event kapi.Event - EventList kapi.EventList - EventSeries kapi.EventSeries - EventSource kapi.EventSource - Namespace kapi.Namespace - NamespaceList kapi.NamespaceList - PersistentVolume kapi.PersistentVolume - PersistentVolumeList kapi.PersistentVolumeList - PersistentVolumeClaim kapi.PersistentVolumeClaim - PersistentVolumeClaimList kapi.PersistentVolumeClaimList - ResourceQuota kapi.ResourceQuota - ResourceQuotaList kapi.ResourceQuotaList - Secret kapi.Secret - SecretList kapi.SecretList - ServiceAccount kapi.ServiceAccount - ServiceAccountList kapi.ServiceAccountList - Binding kapi.Binding - LimitRangeList kapi.LimitRangeList - ComponentStatus kapi.ComponentStatus - ComponentStatusList kapi.ComponentStatusList - ContainerStatus kapi.ContainerStatus - ConfigMap kapi.ConfigMap - ConfigMapList kapi.ConfigMapList - Toleration kapi.Toleration - TopologySelectorTerm kapi.TopologySelectorTerm - Config configapi.Config - APIService aggregator.APIService - APIServiceList aggregator.APIServiceList -} - -func main() { - packages := []schemagen.PackageDescriptor{ - {"k8s.io/apimachinery/pkg/api/resource", "", "io.fabric8.kubernetes.api.model", "kubernetes_resource_", true}, - {"k8s.io/apimachinery/pkg/util/intstr", "", "io.fabric8.kubernetes.api.model", "kubernetes_apimachinery_pkg_util_intstr_", true}, - {"k8s.io/apimachinery/pkg/runtime", "", "io.fabric8.kubernetes.api.model.runtime", "kubernetes_apimachinery_pkg_runtime_", true}, - {"k8s.io/apimachinery/pkg/version", "", "io.fabric8.kubernetes.api.model.version", "kubernetes_apimachinery_pkg_version_", true}, - {"k8s.io/apimachinery/pkg/apis/meta/v1", "", "io.fabric8.kubernetes.api.model", "kubernetes_apimachinery_pkg_apis_", true}, - {"k8s.io/api/core/v1", "", "io.fabric8.kubernetes.api.model", "kubernetes_core_", true}, - {"k8s.io/kubernetes/pkg/util", "", "io.fabric8.kubernetes.api.model", "kubernetes_util_", true}, - {"k8s.io/kubernetes/pkg/api/errors", "", "io.fabric8.kubernetes.api.model", "kubernetes_errors_", true}, - {"k8s.io/client-go/tools/clientcmd/api/v1", "", "io.fabric8.kubernetes.api.model", "kubernetes_config_", true}, - {"k8s.io/kubernetes/pkg/api/unversioned", "", "io.fabric8.kubernetes.api.model", "api_", true}, - {"k8s.io/api/authentication/v1", "authentication.k8s.io", "io.fabric8.kubernetes.api.model.authentication", "kubernetes_authentication_", true}, - {"k8s.io/kube-aggregator/pkg/apis/apiregistration/v1", "apiregistration.k8s.io", "io.fabric8.kubernetes.api.model", "kubernetes_aggregator_", true}, - } - - typeMap := map[reflect.Type]reflect.Type{ - reflect.TypeOf(time.Time{}): reflect.TypeOf(""), - reflect.TypeOf(struct{}{}): reflect.TypeOf(""), - } - - // default the core raw to HasMetadata, rather than KubernetesResource - manualTypeMap := map[reflect.Type]string{ - reflect.TypeOf(runtime.RawExtension{}): "io.fabric8.kubernetes.api.model.HasMetadata", - } - - schema, err := schemagen.GenerateSchema(reflect.TypeOf(Schema{}), packages, typeMap, manualTypeMap, "core") - if err != nil { - fmt.Fprintf(os.Stderr, "An error occurred: %v", err) - return - } - - // since we default to HasMetadata we need specific overrides for watchevent and namedextension - resourceProp := schemagen.JSONPropertyDescriptor{ - ExistingJavaTypeDescriptor: &schemagen.ExistingJavaTypeDescriptor{ - ExistingJavaType: "io.fabric8.kubernetes.api.model.KubernetesResource", - }, - } - schema.Resources["watchevent"].Properties["object"] = resourceProp - schema.Resources["namedextension"].Properties["extension"] = resourceProp - - serdes := map[string]*schemagen.JavaSerDeDescriptor{ - "kubernetes_apimachinery_pkg_apis_MicroTime": &schemagen.JavaSerDeDescriptor{ - Serializer: "io.fabric8.kubernetes.api.model.MicroTimeSerDes.Serializer.class", - Deserializer: "io.fabric8.kubernetes.api.model.MicroTimeSerDes.Deserializer.class", - }, - } - - for definitionKey, descriptor := range serdes { - val := schema.Definitions[definitionKey] - val.JavaSerDeDescriptor = descriptor - schema.Definitions[definitionKey] = val - } - - args := os.Args[1:] - if len(args) < 1 || args[0] != "validation" { - schema.Resources = nil - } - - b, err := json.Marshal(&schema) - if err != nil { - log.Fatal(err) - } - result := string(b) - result = strings.Replace(result, "\"additionalProperty\":", "\"additionalProperties\":", -1) - - var out bytes.Buffer - err = json.Indent(&out, []byte(result), "", " ") - if err != nil { - log.Fatal(err) - } - - fmt.Println(out.String()) -} diff --git a/kubernetes-model-generator/kubernetes-model-core/pom.xml b/kubernetes-model-generator/kubernetes-model-core/pom.xml index 7dc585d80de..7eb4589c54f 100644 --- a/kubernetes-model-generator/kubernetes-model-core/pom.xml +++ b/kubernetes-model-generator/kubernetes-model-core/pom.xml @@ -130,74 +130,36 @@ - - - - org.codehaus.mojo - build-helper-maven-plugin - - - attach-artifacts - - false - - - - - - - generate - org.jsonschema2pojo - jsonschema2pojo-maven-plugin - - io.fabric8.kubernetes.jsonschema2pojo.KubernetesCoreTypeAnnotator + io.fabric8 + openapi-model-generator-maven-plugin + + + false + + ${project.basedir}/../openapi/schemas/kubernetes-1.30.0.json + ${project.basedir}/../openapi/schemas/api-machinery-extra.json + ${project.basedir}/../openapi/schemas/admission-registration.json + + + io.fabric8.kubernetes.api.model + io.fabric8.kubernetes.api.model + + + ^io\.k8s\.apimachinery\.pkg\.runtime\.RawExtension$ + + + ^io\.k8s\.api\.core\..*$ + ^io\.k8s\.apimachinery\..*$ + + - - maven-antrun-plugin - - - generate-sources - - - Removing the duplicate generated class - - - - - - - - - - - - - - - run - - - - diff --git a/kubernetes-model-generator/kubernetes-model-core/src/generated/java/io/fabric8/kubernetes/api/model/APIResourceList.java b/kubernetes-model-generator/kubernetes-model-core/src/generated/java/io/fabric8/kubernetes/api/model/APIResourceList.java index 684e8006678..0d4523678c2 100644 --- a/kubernetes-model-generator/kubernetes-model-core/src/generated/java/io/fabric8/kubernetes/api/model/APIResourceList.java +++ b/kubernetes-model-generator/kubernetes-model-core/src/generated/java/io/fabric8/kubernetes/api/model/APIResourceList.java @@ -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; @@ -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 , KubernetesResource { diff --git a/kubernetes-model-generator/kubernetes-model-core/src/generated/java/io/fabric8/kubernetes/api/model/LimitRangeItem.java b/kubernetes-model-generator/kubernetes-model-core/src/generated/java/io/fabric8/kubernetes/api/model/LimitRangeItem.java index 69e9b40cc14..e15a26f8a8c 100644 --- a/kubernetes-model-generator/kubernetes-model-core/src/generated/java/io/fabric8/kubernetes/api/model/LimitRangeItem.java +++ b/kubernetes-model-generator/kubernetes-model-core/src/generated/java/io/fabric8/kubernetes/api/model/LimitRangeItem.java @@ -40,19 +40,19 @@ public class LimitRangeItem implements Editable , Kuberne @JsonProperty("default") @JsonInclude(JsonInclude.Include.NON_EMPTY) - private Map _default = new LinkedHashMap<>(); + private Map _default = new LinkedHashMap<>(); @JsonProperty("defaultRequest") @JsonInclude(JsonInclude.Include.NON_EMPTY) - private Map defaultRequest = new LinkedHashMap<>(); + private Map defaultRequest = new LinkedHashMap<>(); @JsonProperty("max") @JsonInclude(JsonInclude.Include.NON_EMPTY) - private Map max = new LinkedHashMap<>(); + private Map max = new LinkedHashMap<>(); @JsonProperty("maxLimitRequestRatio") @JsonInclude(JsonInclude.Include.NON_EMPTY) - private Map maxLimitRequestRatio = new LinkedHashMap<>(); + private Map maxLimitRequestRatio = new LinkedHashMap<>(); @JsonProperty("min") @JsonInclude(JsonInclude.Include.NON_EMPTY) - private Map min = new LinkedHashMap<>(); + private Map min = new LinkedHashMap<>(); @JsonProperty("type") private String type; @JsonIgnore @@ -65,7 +65,7 @@ public class LimitRangeItem implements Editable , Kuberne public LimitRangeItem() { } - public LimitRangeItem(Map _default, Map defaultRequest, Map max, Map maxLimitRequestRatio, Map min, String type) { + public LimitRangeItem(Map _default, Map defaultRequest, Map max, Map maxLimitRequestRatio, Map min, String type) { super(); this._default = _default; this.defaultRequest = defaultRequest; @@ -77,56 +77,56 @@ public LimitRangeItem(Map _def @JsonProperty("default") @JsonInclude(JsonInclude.Include.NON_EMPTY) - public Map getDefault() { + public Map getDefault() { return _default; } @JsonProperty("default") - public void setDefault(Map _default) { + public void setDefault(Map _default) { this._default = _default; } @JsonProperty("defaultRequest") @JsonInclude(JsonInclude.Include.NON_EMPTY) - public Map getDefaultRequest() { + public Map getDefaultRequest() { return defaultRequest; } @JsonProperty("defaultRequest") - public void setDefaultRequest(Map defaultRequest) { + public void setDefaultRequest(Map defaultRequest) { this.defaultRequest = defaultRequest; } @JsonProperty("max") @JsonInclude(JsonInclude.Include.NON_EMPTY) - public Map getMax() { + public Map getMax() { return max; } @JsonProperty("max") - public void setMax(Map max) { + public void setMax(Map max) { this.max = max; } @JsonProperty("maxLimitRequestRatio") @JsonInclude(JsonInclude.Include.NON_EMPTY) - public Map getMaxLimitRequestRatio() { + public Map getMaxLimitRequestRatio() { return maxLimitRequestRatio; } @JsonProperty("maxLimitRequestRatio") - public void setMaxLimitRequestRatio(Map maxLimitRequestRatio) { + public void setMaxLimitRequestRatio(Map maxLimitRequestRatio) { this.maxLimitRequestRatio = maxLimitRequestRatio; } @JsonProperty("min") @JsonInclude(JsonInclude.Include.NON_EMPTY) - public Map getMin() { + public Map getMin() { return min; } @JsonProperty("min") - public void setMin(Map min) { + public void setMin(Map min) { this.min = min; } diff --git a/kubernetes-model-generator/kubernetes-model-core/src/generated/java/io/fabric8/kubernetes/api/model/NodeStatus.java b/kubernetes-model-generator/kubernetes-model-core/src/generated/java/io/fabric8/kubernetes/api/model/NodeStatus.java index 45aa54f0c41..419b2263bc6 100644 --- a/kubernetes-model-generator/kubernetes-model-core/src/generated/java/io/fabric8/kubernetes/api/model/NodeStatus.java +++ b/kubernetes-model-generator/kubernetes-model-core/src/generated/java/io/fabric8/kubernetes/api/model/NodeStatus.java @@ -51,10 +51,10 @@ public class NodeStatus implements Editable , KubernetesResou private List addresses = new ArrayList<>(); @JsonProperty("allocatable") @JsonInclude(JsonInclude.Include.NON_EMPTY) - private Map allocatable = new LinkedHashMap<>(); + private Map allocatable = new LinkedHashMap<>(); @JsonProperty("capacity") @JsonInclude(JsonInclude.Include.NON_EMPTY) - private Map capacity = new LinkedHashMap<>(); + private Map capacity = new LinkedHashMap<>(); @JsonProperty("conditions") @JsonInclude(JsonInclude.Include.NON_EMPTY) private List conditions = new ArrayList<>(); @@ -88,7 +88,7 @@ public class NodeStatus implements Editable , KubernetesResou public NodeStatus() { } - public NodeStatus(List addresses, Map allocatable, Map capacity, List conditions, NodeConfigStatus config, NodeDaemonEndpoints daemonEndpoints, List images, NodeSystemInfo nodeInfo, String phase, List runtimeHandlers, List volumesAttached, List volumesInUse) { + public NodeStatus(List addresses, Map allocatable, Map capacity, List conditions, NodeConfigStatus config, NodeDaemonEndpoints daemonEndpoints, List images, NodeSystemInfo nodeInfo, String phase, List runtimeHandlers, List volumesAttached, List volumesInUse) { super(); this.addresses = addresses; this.allocatable = allocatable; @@ -117,23 +117,23 @@ public void setAddresses(List addresses) { @JsonProperty("allocatable") @JsonInclude(JsonInclude.Include.NON_EMPTY) - public Map getAllocatable() { + public Map getAllocatable() { return allocatable; } @JsonProperty("allocatable") - public void setAllocatable(Map allocatable) { + public void setAllocatable(Map allocatable) { this.allocatable = allocatable; } @JsonProperty("capacity") @JsonInclude(JsonInclude.Include.NON_EMPTY) - public Map getCapacity() { + public Map getCapacity() { return capacity; } @JsonProperty("capacity") - public void setCapacity(Map capacity) { + public void setCapacity(Map capacity) { this.capacity = capacity; } diff --git a/kubernetes-model-generator/kubernetes-model-core/src/generated/java/io/fabric8/kubernetes/api/model/OwnerReference.java b/kubernetes-model-generator/kubernetes-model-core/src/generated/java/io/fabric8/kubernetes/api/model/OwnerReference.java index 8792bdfe564..813b1f8d730 100644 --- a/kubernetes-model-generator/kubernetes-model-core/src/generated/java/io/fabric8/kubernetes/api/model/OwnerReference.java +++ b/kubernetes-model-generator/kubernetes-model-core/src/generated/java/io/fabric8/kubernetes/api/model/OwnerReference.java @@ -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; @@ -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 , 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") @@ -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; @@ -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; diff --git a/kubernetes-model-generator/kubernetes-model-core/src/generated/java/io/fabric8/kubernetes/api/model/PersistentVolumeClaimStatus.java b/kubernetes-model-generator/kubernetes-model-core/src/generated/java/io/fabric8/kubernetes/api/model/PersistentVolumeClaimStatus.java index 4fd851cd3d2..80fb8a74d1f 100644 --- a/kubernetes-model-generator/kubernetes-model-core/src/generated/java/io/fabric8/kubernetes/api/model/PersistentVolumeClaimStatus.java +++ b/kubernetes-model-generator/kubernetes-model-core/src/generated/java/io/fabric8/kubernetes/api/model/PersistentVolumeClaimStatus.java @@ -50,10 +50,10 @@ public class PersistentVolumeClaimStatus implements Editable allocatedResourceStatuses = new LinkedHashMap<>(); @JsonProperty("allocatedResources") @JsonInclude(JsonInclude.Include.NON_EMPTY) - private Map allocatedResources = new LinkedHashMap<>(); + private Map allocatedResources = new LinkedHashMap<>(); @JsonProperty("capacity") @JsonInclude(JsonInclude.Include.NON_EMPTY) - private Map capacity = new LinkedHashMap<>(); + private Map capacity = new LinkedHashMap<>(); @JsonProperty("conditions") @JsonInclude(JsonInclude.Include.NON_EMPTY) private List conditions = new ArrayList<>(); @@ -73,7 +73,7 @@ public class PersistentVolumeClaimStatus implements Editable accessModes, Map allocatedResourceStatuses, Map allocatedResources, Map capacity, List conditions, String currentVolumeAttributesClassName, ModifyVolumeStatus modifyVolumeStatus, String phase) { + public PersistentVolumeClaimStatus(List accessModes, Map allocatedResourceStatuses, Map allocatedResources, Map capacity, List conditions, String currentVolumeAttributesClassName, ModifyVolumeStatus modifyVolumeStatus, String phase) { super(); this.accessModes = accessModes; this.allocatedResourceStatuses = allocatedResourceStatuses; @@ -109,23 +109,23 @@ public void setAllocatedResourceStatuses(Map allocatedResourceSt @JsonProperty("allocatedResources") @JsonInclude(JsonInclude.Include.NON_EMPTY) - public Map getAllocatedResources() { + public Map getAllocatedResources() { return allocatedResources; } @JsonProperty("allocatedResources") - public void setAllocatedResources(Map allocatedResources) { + public void setAllocatedResources(Map allocatedResources) { this.allocatedResources = allocatedResources; } @JsonProperty("capacity") @JsonInclude(JsonInclude.Include.NON_EMPTY) - public Map getCapacity() { + public Map getCapacity() { return capacity; } @JsonProperty("capacity") - public void setCapacity(Map capacity) { + public void setCapacity(Map capacity) { this.capacity = capacity; } diff --git a/kubernetes-model-generator/kubernetes-model-core/src/generated/java/io/fabric8/kubernetes/api/model/ResourceQuotaStatus.java b/kubernetes-model-generator/kubernetes-model-core/src/generated/java/io/fabric8/kubernetes/api/model/ResourceQuotaStatus.java index 061defc0bf0..cb5a60288be 100644 --- a/kubernetes-model-generator/kubernetes-model-core/src/generated/java/io/fabric8/kubernetes/api/model/ResourceQuotaStatus.java +++ b/kubernetes-model-generator/kubernetes-model-core/src/generated/java/io/fabric8/kubernetes/api/model/ResourceQuotaStatus.java @@ -36,10 +36,10 @@ public class ResourceQuotaStatus implements Editable @JsonProperty("hard") @JsonInclude(JsonInclude.Include.NON_EMPTY) - private Map hard = new LinkedHashMap<>(); + private Map hard = new LinkedHashMap<>(); @JsonProperty("used") @JsonInclude(JsonInclude.Include.NON_EMPTY) - private Map used = new LinkedHashMap<>(); + private Map used = new LinkedHashMap<>(); @JsonIgnore private Map additionalProperties = new LinkedHashMap(); @@ -50,7 +50,7 @@ public class ResourceQuotaStatus implements Editable public ResourceQuotaStatus() { } - public ResourceQuotaStatus(Map hard, Map used) { + public ResourceQuotaStatus(Map hard, Map used) { super(); this.hard = hard; this.used = used; @@ -58,23 +58,23 @@ public ResourceQuotaStatus(Map @JsonProperty("hard") @JsonInclude(JsonInclude.Include.NON_EMPTY) - public Map getHard() { + public Map getHard() { return hard; } @JsonProperty("hard") - public void setHard(Map hard) { + public void setHard(Map hard) { this.hard = hard; } @JsonProperty("used") @JsonInclude(JsonInclude.Include.NON_EMPTY) - public Map getUsed() { + public Map getUsed() { return used; } @JsonProperty("used") - public void setUsed(Map used) { + public void setUsed(Map used) { this.used = used; } diff --git a/kubernetes-model-generator/kubernetes-model-core/src/generated/java/io/fabric8/kubernetes/api/model/ResourceRequirements.java b/kubernetes-model-generator/kubernetes-model-core/src/generated/java/io/fabric8/kubernetes/api/model/ResourceRequirements.java index e8552796780..b142f9c191d 100644 --- a/kubernetes-model-generator/kubernetes-model-core/src/generated/java/io/fabric8/kubernetes/api/model/ResourceRequirements.java +++ b/kubernetes-model-generator/kubernetes-model-core/src/generated/java/io/fabric8/kubernetes/api/model/ResourceRequirements.java @@ -42,10 +42,10 @@ public class ResourceRequirements implements Editable claims = new ArrayList<>(); @JsonProperty("limits") @JsonInclude(JsonInclude.Include.NON_EMPTY) - private Map limits = new LinkedHashMap<>(); + private Map limits = new LinkedHashMap<>(); @JsonProperty("requests") @JsonInclude(JsonInclude.Include.NON_EMPTY) - private Map requests = new LinkedHashMap<>(); + private Map requests = new LinkedHashMap<>(); @JsonIgnore private Map additionalProperties = new LinkedHashMap(); @@ -56,7 +56,7 @@ public class ResourceRequirements implements Editable claims, Map limits, Map requests) { + public ResourceRequirements(List claims, Map limits, Map requests) { super(); this.claims = claims; this.limits = limits; @@ -76,23 +76,23 @@ public void setClaims(List claims) { @JsonProperty("limits") @JsonInclude(JsonInclude.Include.NON_EMPTY) - public Map getLimits() { + public Map getLimits() { return limits; } @JsonProperty("limits") - public void setLimits(Map limits) { + public void setLimits(Map limits) { this.limits = limits; } @JsonProperty("requests") @JsonInclude(JsonInclude.Include.NON_EMPTY) - public Map getRequests() { + public Map getRequests() { return requests; } @JsonProperty("requests") - public void setRequests(Map requests) { + public void setRequests(Map requests) { this.requests = requests; } diff --git a/kubernetes-model-generator/kubernetes-model-core/src/generated/java/io/fabric8/kubernetes/api/model/TypeMeta.java b/kubernetes-model-generator/kubernetes-model-core/src/generated/java/io/fabric8/kubernetes/api/model/TypeMeta.java index 3ad5b7e14f1..7abdc180689 100644 --- a/kubernetes-model-generator/kubernetes-model-core/src/generated/java/io/fabric8/kubernetes/api/model/TypeMeta.java +++ b/kubernetes-model-generator/kubernetes-model-core/src/generated/java/io/fabric8/kubernetes/api/model/TypeMeta.java @@ -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; @@ -30,14 +34,29 @@ "" }) @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 TypeMeta implements Editable , KubernetesResource { + /** + * + * (Required) + * + */ @JsonProperty("apiVersion") - private String apiVersion; + private String apiVersion = "v1"; + /** + * + * (Required) + * + */ @JsonProperty("kind") - private String kind; + private String kind = "TypeMeta"; @JsonIgnore private Map additionalProperties = new LinkedHashMap(); @@ -54,21 +73,41 @@ public TypeMeta(String apiVersion, String kind) { this.kind = kind; } + /** + * + * (Required) + * + */ @JsonProperty("apiVersion") public String getApiVersion() { return apiVersion; } + /** + * + * (Required) + * + */ @JsonProperty("apiVersion") public void setApiVersion(String apiVersion) { this.apiVersion = apiVersion; } + /** + * + * (Required) + * + */ @JsonProperty("kind") public String getKind() { return kind; } + /** + * + * (Required) + * + */ @JsonProperty("kind") public void setKind(String kind) { this.kind = kind; diff --git a/kubernetes-model-generator/kubernetes-model-core/src/generated/java/io/fabric8/kubernetes/api/model/VolumeResourceRequirements.java b/kubernetes-model-generator/kubernetes-model-core/src/generated/java/io/fabric8/kubernetes/api/model/VolumeResourceRequirements.java index d37d5f23faf..6ff825d0440 100644 --- a/kubernetes-model-generator/kubernetes-model-core/src/generated/java/io/fabric8/kubernetes/api/model/VolumeResourceRequirements.java +++ b/kubernetes-model-generator/kubernetes-model-core/src/generated/java/io/fabric8/kubernetes/api/model/VolumeResourceRequirements.java @@ -36,10 +36,10 @@ public class VolumeResourceRequirements implements Editable limits = new LinkedHashMap<>(); + private Map limits = new LinkedHashMap<>(); @JsonProperty("requests") @JsonInclude(JsonInclude.Include.NON_EMPTY) - private Map requests = new LinkedHashMap<>(); + private Map requests = new LinkedHashMap<>(); @JsonIgnore private Map additionalProperties = new LinkedHashMap(); @@ -50,7 +50,7 @@ public class VolumeResourceRequirements implements Editable limits, Map requests) { + public VolumeResourceRequirements(Map limits, Map requests) { super(); this.limits = limits; this.requests = requests; @@ -58,23 +58,23 @@ public VolumeResourceRequirements(Map getLimits() { + public Map getLimits() { return limits; } @JsonProperty("limits") - public void setLimits(Map limits) { + public void setLimits(Map limits) { this.limits = limits; } @JsonProperty("requests") @JsonInclude(JsonInclude.Include.NON_EMPTY) - public Map getRequests() { + public Map getRequests() { return requests; } @JsonProperty("requests") - public void setRequests(Map requests) { + public void setRequests(Map requests) { this.requests = requests; } diff --git a/kubernetes-model-generator/kubernetes-model-core/src/generated/java/io/fabric8/kubernetes/api/model/WatchEvent.java b/kubernetes-model-generator/kubernetes-model-core/src/generated/java/io/fabric8/kubernetes/api/model/WatchEvent.java index a9a0ca00a97..c86b669b395 100644 --- a/kubernetes-model-generator/kubernetes-model-core/src/generated/java/io/fabric8/kubernetes/api/model/WatchEvent.java +++ b/kubernetes-model-generator/kubernetes-model-core/src/generated/java/io/fabric8/kubernetes/api/model/WatchEvent.java @@ -31,11 +31,11 @@ }) @Buildable(editableEnabled = false, validationEnabled = false, generateBuilderPackage = false, lazyCollectionInitEnabled = false, builderPackage = "io.fabric8.kubernetes.api.builder") @Generated("jsonschema2pojo") -public class WatchEvent implements Editable , io.fabric8.kubernetes.api.model.KubernetesResource +public class WatchEvent implements Editable , KubernetesResource { @JsonProperty("object") - private io.fabric8.kubernetes.api.model.KubernetesResource object; + private KubernetesResource object; @JsonProperty("type") private String type; @JsonIgnore @@ -48,19 +48,19 @@ public class WatchEvent implements Editable , io.fabric8.kube public WatchEvent() { } - public WatchEvent(io.fabric8.kubernetes.api.model.KubernetesResource object, String type) { + public WatchEvent(KubernetesResource object, String type) { super(); this.object = object; this.type = type; } @JsonProperty("object") - public io.fabric8.kubernetes.api.model.KubernetesResource getObject() { + public KubernetesResource getObject() { return object; } @JsonProperty("object") - public void setObject(io.fabric8.kubernetes.api.model.KubernetesResource object) { + public void setObject(KubernetesResource object) { this.object = object; } diff --git a/kubernetes-model-generator/kubernetes-model-core/src/generated/java/io/fabric8/kubernetes/api/model/version/Info.java b/kubernetes-model-generator/kubernetes-model-core/src/generated/java/io/fabric8/kubernetes/api/model/version/Info.java index e71018f3a26..b56f8c5382d 100644 --- a/kubernetes-model-generator/kubernetes-model-core/src/generated/java/io/fabric8/kubernetes/api/model/version/Info.java +++ b/kubernetes-model-generator/kubernetes-model-core/src/generated/java/io/fabric8/kubernetes/api/model/version/Info.java @@ -13,7 +13,11 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import io.fabric8.kubernetes.api.builder.Editable; import io.fabric8.kubernetes.api.model.KubernetesResource; +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; @@ -38,6 +42,11 @@ "" }) @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 Info implements Editable , KubernetesResource { diff --git a/kubernetes-model-generator/openapi/maven-plugin/src/main/java/io/fabric8/kubernetes/schema/generator/GeneratorSettings.java b/kubernetes-model-generator/openapi/maven-plugin/src/main/java/io/fabric8/kubernetes/schema/generator/GeneratorSettings.java index 250131f09bb..fdb7a203a77 100644 --- a/kubernetes-model-generator/openapi/maven-plugin/src/main/java/io/fabric8/kubernetes/schema/generator/GeneratorSettings.java +++ b/kubernetes-model-generator/openapi/maven-plugin/src/main/java/io/fabric8/kubernetes/schema/generator/GeneratorSettings.java @@ -203,11 +203,11 @@ private static Map computeApiVersions(OpenAPI openAPI) { apiVersions.put(ref.replaceFirst("#/components/schemas/", ""), apiVersionBuilder.build()); } } - // api machinery components always tagged as core v1 + // api machinery + core components always tagged as core v1 // TODO: see if we want to omit the addition of group and version altogether in the future openAPI.getComponents().getSchemas().entrySet().stream() - .filter(GeneratorSettings::isApplicableApiMachineryComponent) - .forEach(e -> apiVersions.put(e.getKey(), ApiVersion.builder().group("").version("v1").build())); + .filter(GeneratorSettings::isApplicableApiMachineryOrCoreComponent) + .forEach(e -> apiVersions.putIfAbsent(e.getKey(), ApiVersion.builder().group("").version("v1").build())); } return apiVersions; } @@ -227,8 +227,9 @@ private static boolean isApplicablePath(PathItem pathItem) { pathParameters(post).stream().map(Parameter::getName).anyMatch("name"::equals); } - private static boolean isApplicableApiMachineryComponent(Map.Entry componentSchema) { - if (!componentSchema.getKey().startsWith("io.k8s.apimachinery.pkg.apis")) { + private static boolean isApplicableApiMachineryOrCoreComponent(Map.Entry componentSchema) { + if (!componentSchema.getKey().startsWith("io.k8s.apimachinery.pkg.apis") + && !componentSchema.getKey().startsWith("io.k8s.api.core.v1.PodExecOptions")) { return false; } if (componentSchema.getValue().getProperties() == null) { diff --git a/kubernetes-model-generator/pom.xml b/kubernetes-model-generator/pom.xml index 9fa17f2a993..3788ffa89ae 100644 --- a/kubernetes-model-generator/pom.xml +++ b/kubernetes-model-generator/pom.xml @@ -140,6 +140,32 @@ + + io.fabric8 + openapi-model-generator-maven-plugin + ${project.version} + + + ${project.basedir} + io.fabric8.kubernetes.api.model + io.fabric8.kubernetes.api.builder + true + false + + io.fabric8.kubernetes.api.model + io.fabric8.kubernetes.api.model + io.fabric8.kubernetes.api.model + + + + + + + generate-model + + + + org.codehaus.mojo build-helper-maven-plugin