From a125a671409ce4f25200aae3867f5e8002b31e07 Mon Sep 17 00:00:00 2001 From: Marc Nuri Date: Mon, 22 Jul 2024 15:53:13 +0200 Subject: [PATCH] refactor: kubernetes-model-rbac generated from OpenAPI schemas Signed-off-by: Marc Nuri --- Makefile | 1 + kubernetes-model-generator/generateModel.sh | 1 - .../kubernetes-model-rbac/Makefile | 27 ------ .../cmd/generate/generate.go | 85 ------------------- .../kubernetes-model-rbac/pom.xml | 34 ++++---- .../api/model/rbac/AggregationRule.java | 11 +-- .../api/model/rbac/ClusterRole.java | 11 +-- .../api/model/rbac/ClusterRoleBinding.java | 11 +-- .../kubernetes/api/model/rbac/Role.java | 11 +-- .../api/model/rbac/RoleBinding.java | 11 +-- 10 files changed, 46 insertions(+), 157 deletions(-) delete mode 100644 kubernetes-model-generator/kubernetes-model-rbac/Makefile delete mode 100644 kubernetes-model-generator/kubernetes-model-rbac/cmd/generate/generate.go diff --git a/Makefile b/Makefile index 4278af7037d..c537bda12fa 100644 --- a/Makefile +++ b/Makefile @@ -35,6 +35,7 @@ generate-openapi-classes: 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 + cd kubernetes-model-generator/kubernetes-model-rbac && mvn -Pgenerate clean install # Legacy generation of the model: TODO: remove .PHONY: generate-model-legacy diff --git a/kubernetes-model-generator/generateModel.sh b/kubernetes-model-generator/generateModel.sh index 7b84bce102d..d08242e20ef 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-rbac" "kubernetes-model-admissionregistration" "kubernetes-model-apiextensions" "kubernetes-model-apps" diff --git a/kubernetes-model-generator/kubernetes-model-rbac/Makefile b/kubernetes-model-generator/kubernetes-model-rbac/Makefile deleted file mode 100644 index c09a7003874..00000000000 --- a/kubernetes-model-generator/kubernetes-model-rbac/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-rbac/cmd/generate/generate.go b/kubernetes-model-generator/kubernetes-model-rbac/cmd/generate/generate.go deleted file mode 100644 index 702775b3bec..00000000000 --- a/kubernetes-model-generator/kubernetes-model-rbac/cmd/generate/generate.go +++ /dev/null @@ -1,85 +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" - - rbac "k8s.io/api/rbac/v1" - - "log" - "reflect" - "strings" - "time" - - "os" - - "github.com/fabric8io/kubernetes-client/kubernetes-model-generator/pkg/schemagen" -) - -type Schema struct { - AggregationRule rbac.AggregationRule - Role rbac.Role - RoleList rbac.RoleList - RoleBinding rbac.RoleBinding - RoleBindingList rbac.RoleBindingList - ClusterRole rbac.ClusterRole - ClusterRoleList rbac.ClusterRoleList - ClusterRoleBinding rbac.ClusterRoleBinding - ClusterRoleBindingList rbac.ClusterRoleBindingList -} - -func main() { - packages := []schemagen.PackageDescriptor{ - {"k8s.io/apimachinery/pkg/util/intstr", "", "io.fabric8.kubernetes.api.model", "kubernetes_apimachinery_pkg_util_intstr_", false}, - {"k8s.io/apimachinery/pkg/runtime", "", "io.fabric8.kubernetes.api.model.runtime", "kubernetes_apimachinery_pkg_runtime_", false}, - {"k8s.io/apimachinery/pkg/version", "", "io.fabric8.kubernetes.api.model.version", "kubernetes_apimachinery_pkg_version_", false}, - {"k8s.io/apimachinery/pkg/apis/meta/v1", "", "io.fabric8.kubernetes.api.model", "kubernetes_apimachinery_", false}, - {"k8s.io/api/rbac/v1", "rbac.authorization.k8s.io", "io.fabric8.kubernetes.api.model.rbac", "kubernetes_rbac_v1_", true}, - } - - typeMap := map[reflect.Type]reflect.Type{ - reflect.TypeOf(time.Time{}): reflect.TypeOf(""), - reflect.TypeOf(struct{}{}): reflect.TypeOf(""), - } - schema, err := schemagen.GenerateSchema(reflect.TypeOf(Schema{}), packages, typeMap, map[reflect.Type]string{},"rbac") - if err != nil { - fmt.Fprintf(os.Stderr, "An error occurred: %v", err) - return - } - - 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-rbac/pom.xml b/kubernetes-model-generator/kubernetes-model-rbac/pom.xml index 56b46816d6b..ab0206a75d5 100644 --- a/kubernetes-model-generator/kubernetes-model-rbac/pom.xml +++ b/kubernetes-model-generator/kubernetes-model-rbac/pom.xml @@ -49,31 +49,27 @@ - - - - org.codehaus.mojo - build-helper-maven-plugin - - - attach-artifacts - - false - - - - - - - generate - org.jsonschema2pojo - jsonschema2pojo-maven-plugin + io.fabric8 + openapi-model-generator-maven-plugin + + + + ${project.basedir}/../openapi/schemas/kubernetes-1.30.0.json + + + io.fabric8.kubernetes.api.model.rbac + + + ^io\.k8s\.api\.rbac\..*$ + + + diff --git a/kubernetes-model-generator/kubernetes-model-rbac/src/generated/java/io/fabric8/kubernetes/api/model/rbac/AggregationRule.java b/kubernetes-model-generator/kubernetes-model-rbac/src/generated/java/io/fabric8/kubernetes/api/model/rbac/AggregationRule.java index 77f6a06b728..d11fecb883b 100644 --- a/kubernetes-model-generator/kubernetes-model-rbac/src/generated/java/io/fabric8/kubernetes/api/model/rbac/AggregationRule.java +++ b/kubernetes-model-generator/kubernetes-model-rbac/src/generated/java/io/fabric8/kubernetes/api/model/rbac/AggregationRule.java @@ -17,6 +17,7 @@ import io.fabric8.kubernetes.api.model.Container; import io.fabric8.kubernetes.api.model.IntOrString; import io.fabric8.kubernetes.api.model.KubernetesResource; +import io.fabric8.kubernetes.api.model.LabelSelector; import io.fabric8.kubernetes.api.model.LocalObjectReference; import io.fabric8.kubernetes.api.model.ObjectMeta; import io.fabric8.kubernetes.api.model.ObjectReference; @@ -42,7 +43,7 @@ }) @Buildable(editableEnabled = false, validationEnabled = false, generateBuilderPackage = false, lazyCollectionInitEnabled = false, builderPackage = "io.fabric8.kubernetes.api.builder", refs = { @BuildableReference(ObjectMeta.class), - @BuildableReference(io.fabric8.kubernetes.api.model.LabelSelector.class), + @BuildableReference(LabelSelector.class), @BuildableReference(Container.class), @BuildableReference(PodTemplateSpec.class), @BuildableReference(ResourceRequirements.class), @@ -57,7 +58,7 @@ public class AggregationRule implements Editable , Kuber @JsonProperty("clusterRoleSelectors") @JsonInclude(JsonInclude.Include.NON_EMPTY) - private List clusterRoleSelectors = new ArrayList<>(); + private List clusterRoleSelectors = new ArrayList<>(); @JsonIgnore private Map additionalProperties = new LinkedHashMap(); @@ -68,19 +69,19 @@ public class AggregationRule implements Editable , Kuber public AggregationRule() { } - public AggregationRule(List clusterRoleSelectors) { + public AggregationRule(List clusterRoleSelectors) { super(); this.clusterRoleSelectors = clusterRoleSelectors; } @JsonProperty("clusterRoleSelectors") @JsonInclude(JsonInclude.Include.NON_EMPTY) - public List getClusterRoleSelectors() { + public List getClusterRoleSelectors() { return clusterRoleSelectors; } @JsonProperty("clusterRoleSelectors") - public void setClusterRoleSelectors(List clusterRoleSelectors) { + public void setClusterRoleSelectors(List clusterRoleSelectors) { this.clusterRoleSelectors = clusterRoleSelectors; } diff --git a/kubernetes-model-generator/kubernetes-model-rbac/src/generated/java/io/fabric8/kubernetes/api/model/rbac/ClusterRole.java b/kubernetes-model-generator/kubernetes-model-rbac/src/generated/java/io/fabric8/kubernetes/api/model/rbac/ClusterRole.java index 473d2bafbe3..4d774e13aed 100644 --- a/kubernetes-model-generator/kubernetes-model-rbac/src/generated/java/io/fabric8/kubernetes/api/model/rbac/ClusterRole.java +++ b/kubernetes-model-generator/kubernetes-model-rbac/src/generated/java/io/fabric8/kubernetes/api/model/rbac/ClusterRole.java @@ -19,6 +19,7 @@ import io.fabric8.kubernetes.api.model.IntOrString; import io.fabric8.kubernetes.api.model.LabelSelector; import io.fabric8.kubernetes.api.model.LocalObjectReference; +import io.fabric8.kubernetes.api.model.ObjectMeta; import io.fabric8.kubernetes.api.model.ObjectReference; import io.fabric8.kubernetes.api.model.PersistentVolumeClaim; import io.fabric8.kubernetes.api.model.PodTemplateSpec; @@ -49,7 +50,7 @@ "" }) @Buildable(editableEnabled = false, validationEnabled = false, generateBuilderPackage = false, lazyCollectionInitEnabled = false, builderPackage = "io.fabric8.kubernetes.api.builder", refs = { - @BuildableReference(io.fabric8.kubernetes.api.model.ObjectMeta.class), + @BuildableReference(ObjectMeta.class), @BuildableReference(LabelSelector.class), @BuildableReference(Container.class), @BuildableReference(PodTemplateSpec.class), @@ -85,7 +86,7 @@ public class ClusterRole implements Editable , HasMetadata @JsonProperty("kind") private String kind = "ClusterRole"; @JsonProperty("metadata") - private io.fabric8.kubernetes.api.model.ObjectMeta metadata; + private ObjectMeta metadata; @JsonProperty("rules") @JsonInclude(JsonInclude.Include.NON_EMPTY) private List rules = new ArrayList<>(); @@ -99,7 +100,7 @@ public class ClusterRole implements Editable , HasMetadata public ClusterRole() { } - public ClusterRole(AggregationRule aggregationRule, String apiVersion, String kind, io.fabric8.kubernetes.api.model.ObjectMeta metadata, List rules) { + public ClusterRole(AggregationRule aggregationRule, String apiVersion, String kind, ObjectMeta metadata, List rules) { super(); this.aggregationRule = aggregationRule; this.apiVersion = apiVersion; @@ -159,12 +160,12 @@ public void setKind(String kind) { } @JsonProperty("metadata") - public io.fabric8.kubernetes.api.model.ObjectMeta getMetadata() { + public ObjectMeta getMetadata() { return metadata; } @JsonProperty("metadata") - public void setMetadata(io.fabric8.kubernetes.api.model.ObjectMeta metadata) { + public void setMetadata(ObjectMeta metadata) { this.metadata = metadata; } diff --git a/kubernetes-model-generator/kubernetes-model-rbac/src/generated/java/io/fabric8/kubernetes/api/model/rbac/ClusterRoleBinding.java b/kubernetes-model-generator/kubernetes-model-rbac/src/generated/java/io/fabric8/kubernetes/api/model/rbac/ClusterRoleBinding.java index 9a3aca05723..2f275621b93 100644 --- a/kubernetes-model-generator/kubernetes-model-rbac/src/generated/java/io/fabric8/kubernetes/api/model/rbac/ClusterRoleBinding.java +++ b/kubernetes-model-generator/kubernetes-model-rbac/src/generated/java/io/fabric8/kubernetes/api/model/rbac/ClusterRoleBinding.java @@ -19,6 +19,7 @@ import io.fabric8.kubernetes.api.model.IntOrString; import io.fabric8.kubernetes.api.model.LabelSelector; import io.fabric8.kubernetes.api.model.LocalObjectReference; +import io.fabric8.kubernetes.api.model.ObjectMeta; import io.fabric8.kubernetes.api.model.ObjectReference; import io.fabric8.kubernetes.api.model.PersistentVolumeClaim; import io.fabric8.kubernetes.api.model.PodTemplateSpec; @@ -49,7 +50,7 @@ "" }) @Buildable(editableEnabled = false, validationEnabled = false, generateBuilderPackage = false, lazyCollectionInitEnabled = false, builderPackage = "io.fabric8.kubernetes.api.builder", refs = { - @BuildableReference(io.fabric8.kubernetes.api.model.ObjectMeta.class), + @BuildableReference(ObjectMeta.class), @BuildableReference(LabelSelector.class), @BuildableReference(Container.class), @BuildableReference(PodTemplateSpec.class), @@ -83,7 +84,7 @@ public class ClusterRoleBinding implements Editable , @JsonProperty("kind") private String kind = "ClusterRoleBinding"; @JsonProperty("metadata") - private io.fabric8.kubernetes.api.model.ObjectMeta metadata; + private ObjectMeta metadata; @JsonProperty("roleRef") private RoleRef roleRef; @JsonProperty("subjects") @@ -99,7 +100,7 @@ public class ClusterRoleBinding implements Editable , public ClusterRoleBinding() { } - public ClusterRoleBinding(String apiVersion, String kind, io.fabric8.kubernetes.api.model.ObjectMeta metadata, RoleRef roleRef, List subjects) { + public ClusterRoleBinding(String apiVersion, String kind, ObjectMeta metadata, RoleRef roleRef, List subjects) { super(); this.apiVersion = apiVersion; this.kind = kind; @@ -149,12 +150,12 @@ public void setKind(String kind) { } @JsonProperty("metadata") - public io.fabric8.kubernetes.api.model.ObjectMeta getMetadata() { + public ObjectMeta getMetadata() { return metadata; } @JsonProperty("metadata") - public void setMetadata(io.fabric8.kubernetes.api.model.ObjectMeta metadata) { + public void setMetadata(ObjectMeta metadata) { this.metadata = metadata; } diff --git a/kubernetes-model-generator/kubernetes-model-rbac/src/generated/java/io/fabric8/kubernetes/api/model/rbac/Role.java b/kubernetes-model-generator/kubernetes-model-rbac/src/generated/java/io/fabric8/kubernetes/api/model/rbac/Role.java index dc3edbefb61..e5f5c8140ec 100644 --- a/kubernetes-model-generator/kubernetes-model-rbac/src/generated/java/io/fabric8/kubernetes/api/model/rbac/Role.java +++ b/kubernetes-model-generator/kubernetes-model-rbac/src/generated/java/io/fabric8/kubernetes/api/model/rbac/Role.java @@ -20,6 +20,7 @@ import io.fabric8.kubernetes.api.model.LabelSelector; import io.fabric8.kubernetes.api.model.LocalObjectReference; import io.fabric8.kubernetes.api.model.Namespaced; +import io.fabric8.kubernetes.api.model.ObjectMeta; import io.fabric8.kubernetes.api.model.ObjectReference; import io.fabric8.kubernetes.api.model.PersistentVolumeClaim; import io.fabric8.kubernetes.api.model.PodTemplateSpec; @@ -49,7 +50,7 @@ "" }) @Buildable(editableEnabled = false, validationEnabled = false, generateBuilderPackage = false, lazyCollectionInitEnabled = false, builderPackage = "io.fabric8.kubernetes.api.builder", refs = { - @BuildableReference(io.fabric8.kubernetes.api.model.ObjectMeta.class), + @BuildableReference(ObjectMeta.class), @BuildableReference(LabelSelector.class), @BuildableReference(Container.class), @BuildableReference(PodTemplateSpec.class), @@ -83,7 +84,7 @@ public class Role implements Editable , HasMetadata, Namespaced @JsonProperty("kind") private String kind = "Role"; @JsonProperty("metadata") - private io.fabric8.kubernetes.api.model.ObjectMeta metadata; + private ObjectMeta metadata; @JsonProperty("rules") @JsonInclude(JsonInclude.Include.NON_EMPTY) private List rules = new ArrayList<>(); @@ -97,7 +98,7 @@ public class Role implements Editable , HasMetadata, Namespaced public Role() { } - public Role(String apiVersion, String kind, io.fabric8.kubernetes.api.model.ObjectMeta metadata, List rules) { + public Role(String apiVersion, String kind, ObjectMeta metadata, List rules) { super(); this.apiVersion = apiVersion; this.kind = kind; @@ -146,12 +147,12 @@ public void setKind(String kind) { } @JsonProperty("metadata") - public io.fabric8.kubernetes.api.model.ObjectMeta getMetadata() { + public ObjectMeta getMetadata() { return metadata; } @JsonProperty("metadata") - public void setMetadata(io.fabric8.kubernetes.api.model.ObjectMeta metadata) { + public void setMetadata(ObjectMeta metadata) { this.metadata = metadata; } diff --git a/kubernetes-model-generator/kubernetes-model-rbac/src/generated/java/io/fabric8/kubernetes/api/model/rbac/RoleBinding.java b/kubernetes-model-generator/kubernetes-model-rbac/src/generated/java/io/fabric8/kubernetes/api/model/rbac/RoleBinding.java index 3ba9f6c96ee..b81692da553 100644 --- a/kubernetes-model-generator/kubernetes-model-rbac/src/generated/java/io/fabric8/kubernetes/api/model/rbac/RoleBinding.java +++ b/kubernetes-model-generator/kubernetes-model-rbac/src/generated/java/io/fabric8/kubernetes/api/model/rbac/RoleBinding.java @@ -20,6 +20,7 @@ import io.fabric8.kubernetes.api.model.LabelSelector; import io.fabric8.kubernetes.api.model.LocalObjectReference; import io.fabric8.kubernetes.api.model.Namespaced; +import io.fabric8.kubernetes.api.model.ObjectMeta; import io.fabric8.kubernetes.api.model.ObjectReference; import io.fabric8.kubernetes.api.model.PersistentVolumeClaim; import io.fabric8.kubernetes.api.model.PodTemplateSpec; @@ -50,7 +51,7 @@ "" }) @Buildable(editableEnabled = false, validationEnabled = false, generateBuilderPackage = false, lazyCollectionInitEnabled = false, builderPackage = "io.fabric8.kubernetes.api.builder", refs = { - @BuildableReference(io.fabric8.kubernetes.api.model.ObjectMeta.class), + @BuildableReference(ObjectMeta.class), @BuildableReference(LabelSelector.class), @BuildableReference(Container.class), @BuildableReference(PodTemplateSpec.class), @@ -84,7 +85,7 @@ public class RoleBinding implements Editable , HasMetadata, @JsonProperty("kind") private String kind = "RoleBinding"; @JsonProperty("metadata") - private io.fabric8.kubernetes.api.model.ObjectMeta metadata; + private ObjectMeta metadata; @JsonProperty("roleRef") private RoleRef roleRef; @JsonProperty("subjects") @@ -100,7 +101,7 @@ public class RoleBinding implements Editable , HasMetadata, public RoleBinding() { } - public RoleBinding(String apiVersion, String kind, io.fabric8.kubernetes.api.model.ObjectMeta metadata, RoleRef roleRef, List subjects) { + public RoleBinding(String apiVersion, String kind, ObjectMeta metadata, RoleRef roleRef, List subjects) { super(); this.apiVersion = apiVersion; this.kind = kind; @@ -150,12 +151,12 @@ public void setKind(String kind) { } @JsonProperty("metadata") - public io.fabric8.kubernetes.api.model.ObjectMeta getMetadata() { + public ObjectMeta getMetadata() { return metadata; } @JsonProperty("metadata") - public void setMetadata(io.fabric8.kubernetes.api.model.ObjectMeta metadata) { + public void setMetadata(ObjectMeta metadata) { this.metadata = metadata; }