From 73087a0f4c5734c4f82cd2a68284b6620b6d45e9 Mon Sep 17 00:00:00 2001 From: Marc Nuri Date: Thu, 3 Oct 2024 18:39:04 +0200 Subject: [PATCH] chore: updated makefile rules for schema generation Explicit model generation is no longer needed Signed-off-by: Marc Nuri --- .github/workflows/e2e-tests.yml | 2 +- Makefile | 63 ++++++------------- .../openapi/generator/cmd/openapi.go | 2 +- .../generator/pkg/openapi/openapi-gen.go | 12 ++++ .../openapi/schemas/openshift-generated.json | 45 +++---------- 5 files changed, 43 insertions(+), 81 deletions(-) diff --git a/.github/workflows/e2e-tests.yml b/.github/workflows/e2e-tests.yml index f05a5794b6c..2f6dfe05638 100644 --- a/.github/workflows/e2e-tests.yml +++ b/.github/workflows/e2e-tests.yml @@ -58,7 +58,7 @@ jobs: java-version: '8' distribution: 'temurin' - name: Install Kubernetes Client - run: ./mvnw ${MAVEN_ARGS} clean install -DskipTests -Djacoco.skip=true + run: make quickly MAVEN_ARGS="${MAVEN_ARGS}" minikube_baremetal: name: Baremetal K8S diff --git a/Makefile b/Makefile index c58b6cb527c..fa2457475aa 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,9 @@ # limitations under the License. # -MAVEN_OPTIONS ?= +.DEFAULT_GOAL := quickly +MAVEN_ARGS ?= +override MAVEN_ARGS += -T 1C OPENAPI_DIR=$(realpath ./kubernetes-model-generator/openapi) OPENAPI_GENERATOR_DIR=$(OPENAPI_DIR)/generator OPENAPI_GENERATOR_BINARY_NAME=generator @@ -23,7 +25,7 @@ OPENAPI_SCHEMAS_DIR=$(OPENAPI_DIR)/schemas .PHONY: clean-java clean-java: - mvn $(MAVEN_OPTIONS) clean + mvn $(MAVEN_ARGS) clean .PHONY: clean clean: clean-java @@ -38,47 +40,7 @@ openapi-generate-schema: .PHONY: openapi-generate-java-classes openapi-generate-java-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 - cd kubernetes-model-generator/kubernetes-model-rbac && mvn -Pgenerate clean install - cd kubernetes-model-generator/kubernetes-model-admissionregistration && mvn -Pgenerate clean install - cd kubernetes-model-generator/kubernetes-model-apiextensions && mvn -Pgenerate clean install - cd kubernetes-model-generator/kubernetes-model-apps && mvn -Pgenerate clean install - cd kubernetes-model-generator/kubernetes-model-autoscaling && mvn -Pgenerate clean install - cd kubernetes-model-generator/kubernetes-model-batch && mvn -Pgenerate clean install - cd kubernetes-model-generator/kubernetes-model-certificates && mvn -Pgenerate clean install - cd kubernetes-model-generator/kubernetes-model-coordination && mvn -Pgenerate clean install - cd kubernetes-model-generator/kubernetes-model-discovery && mvn -Pgenerate clean install - cd kubernetes-model-generator/kubernetes-model-events && mvn -Pgenerate clean install - cd kubernetes-model-generator/kubernetes-model-extensions && mvn -Pgenerate clean install - cd kubernetes-model-generator/kubernetes-model-flowcontrol && mvn -Pgenerate clean install - cd kubernetes-model-generator/kubernetes-model-gatewayapi && mvn -Pgenerate clean install - cd kubernetes-model-generator/kubernetes-model-networking && mvn -Pgenerate clean install - cd kubernetes-model-generator/kubernetes-model-metrics && mvn -Pgenerate clean install - cd kubernetes-model-generator/kubernetes-model-node && mvn -Pgenerate clean install - cd kubernetes-model-generator/kubernetes-model-policy && mvn -Pgenerate clean install - cd kubernetes-model-generator/kubernetes-model-scheduling && mvn -Pgenerate clean install - cd kubernetes-model-generator/kubernetes-model-storageclass && mvn -Pgenerate clean install - cd kubernetes-model-generator/kubernetes-model-resource && mvn -Pgenerate clean install - cd kubernetes-model-generator/kubernetes-model-kustomize && mvn -Pgenerate clean install - cd kubernetes-model-generator/openshift-model-config && mvn -Pgenerate clean install - cd kubernetes-model-generator/openshift-model && mvn -Pgenerate clean install - cd kubernetes-model-generator/openshift-model-operator && mvn -Pgenerate clean install - cd kubernetes-model-generator/openshift-model-miscellaneous && mvn -Pgenerate clean install - cd kubernetes-model-generator/openshift-model-operatorhub && mvn -Pgenerate clean install - cd kubernetes-model-generator/openshift-model-console && mvn -Pgenerate clean install - cd kubernetes-model-generator/openshift-model-autoscaling && mvn -Pgenerate clean install - cd kubernetes-model-generator/openshift-model-machine && mvn -Pgenerate clean install - cd kubernetes-model-generator/openshift-model-machineconfiguration && mvn -Pgenerate clean install - cd kubernetes-model-generator/openshift-model-monitoring && mvn -Pgenerate clean install - cd kubernetes-model-generator/openshift-model-tuned && mvn -Pgenerate clean install - cd kubernetes-model-generator/openshift-model-whereabouts && mvn -Pgenerate clean install - cd kubernetes-model-generator/openshift-model-storageversionmigrator && mvn -Pgenerate clean install - cd kubernetes-model-generator/openshift-model-hive && mvn -Pgenerate clean install - cd kubernetes-model-generator/openshift-model-installer && mvn -Pgenerate clean install + cd kubernetes-model-generator && mvn $(MAVEN_ARGS) -Pgenerate clean install # Legacy generation of the model: TODO: remove .PHONY: generate-model-legacy @@ -90,4 +52,17 @@ generate-model: openapi-generate-schema openapi-generate-java-classes generate-m .PHONY: sonar sonar: - mvn $(MAVEN_OPTIONS) clean install sonar:sonar -Psonar + mvn $(MAVEN_ARGS) clean install -Psonar + mvn $(MAVEN_ARGS) sonar:sonar -Psonar + +.PHONY: format-license +format-license: + mvn $(MAVEN_ARGS) -N license:format + +.PHONY: format-java +format-java: + mvn $(MAVEN_ARGS) spotless:apply -Pitests + +.PHONY: +quickly: clean + mvn $(MAVEN_ARGS) install -DskipTests -Djacoco.skip=true diff --git a/kubernetes-model-generator/openapi/generator/cmd/openapi.go b/kubernetes-model-generator/openapi/generator/cmd/openapi.go index d564280526e..2b87dee1f8f 100644 --- a/kubernetes-model-generator/openapi/generator/cmd/openapi.go +++ b/kubernetes-model-generator/openapi/generator/cmd/openapi.go @@ -62,7 +62,7 @@ var openApiRun = func(cobraCmd *cobra.Command, args []string) { openshiftclusternetworkoperatorv1.GroupVersion.String(), openshiftclusternodetuningoperatorv1.SchemeGroupVersion.String(), openshifthivev1.SchemeGroupVersion.String(), - "install.openshift.io/" + openshiftinstallerv1.InstallConfigVersion + "(" + strings.Join(openshiftinstallerv1.PlatformNames, ",") + ")", + "install.openshift.io/" + openshiftinstallerv1.InstallConfigVersion + " (" + strings.Join(openshiftinstallerv1.PlatformNames, ", ") + ")", operatorframeworkv1alpha1.SchemeGroupVersion.String(), operatorframeworkv1.GroupVersion.String(), prometheusoperatorv1.SchemeGroupVersion.String(), diff --git a/kubernetes-model-generator/openapi/generator/pkg/openapi/openapi-gen.go b/kubernetes-model-generator/openapi/generator/pkg/openapi/openapi-gen.go index ee12d10da6b..a6020d928c8 100644 --- a/kubernetes-model-generator/openapi/generator/pkg/openapi/openapi-gen.go +++ b/kubernetes-model-generator/openapi/generator/pkg/openapi/openapi-gen.go @@ -48,11 +48,23 @@ func (g *GoGenerator) Generate() error { // // Allows to override the default kube-openapi generators.apiTypeFilterFunc with our own (see KubernetesFilterFunc). func (g *GoGenerator) KubernetesTargets(context *generator.Context) []generator.Target { + // Non-deterministic bug-fix + // ScopeType is sometimes considered enum and others isn't. Force it to be non enum to avoid issues + scopeType := context.Universe.Type(types.Name{Package: "k8s.io/api/admissionregistration/v1", Name: "ScopeType"}) + originalComments := scopeType.CommentLines + scopeType.CommentLines = make([]string, 0) + for _, comment := range originalComments { + if comment != "+enum" { + scopeType.CommentLines = append(scopeType.CommentLines, comment) + } + } + // Create a map of all the input packages for performance (queried later on) g.inputPkgs = make(map[string]bool) for _, inputPackage := range context.Inputs { g.inputPkgs[inputPackage] = true } + // Replace original Filter function with something that includes all Kubernetes Object types regardless of the comment tag openApiGenTargets := generators.GetTargets(context, &g.Args) for _, target := range openApiGenTargets { diff --git a/kubernetes-model-generator/openapi/schemas/openshift-generated.json b/kubernetes-model-generator/openapi/schemas/openshift-generated.json index 6642abed5ba..524802ce1b6 100644 --- a/kubernetes-model-generator/openapi/schemas/openshift-generated.json +++ b/kubernetes-model-generator/openapi/schemas/openshift-generated.json @@ -20653,13 +20653,8 @@ "x-kubernetes-list-type": "atomic" }, "scope": { - "description": "scope specifies the scope of this rule. Valid values are \"Cluster\", \"Namespaced\", and \"*\" \"Cluster\" means that only cluster-scoped resources will match this rule. Namespace API objects are cluster-scoped. \"Namespaced\" means that only namespaced resources will match this rule. \"*\" means that there are no scope restrictions. Subresources match the scope of their parent resource. Default is \"*\".\n\n\nPossible enum values:\n - `\"*\"` means that all scopes are included.\n - `\"Cluster\"` means that scope is limited to cluster-scoped objects. Namespace objects are cluster-scoped.\n - `\"Namespaced\"` means that scope is limited to namespaced objects.", - "type": "string", - "enum": [ - "*", - "Cluster", - "Namespaced" - ] + "description": "scope specifies the scope of this rule. Valid values are \"Cluster\", \"Namespaced\", and \"*\" \"Cluster\" means that only cluster-scoped resources will match this rule. Namespace API objects are cluster-scoped. \"Namespaced\" means that only namespaced resources will match this rule. \"*\" means that there are no scope restrictions. Subresources match the scope of their parent resource. Default is \"*\".", + "type": "string" } }, "x-fabric8-info": { @@ -20755,13 +20750,8 @@ "x-kubernetes-list-type": "atomic" }, "scope": { - "description": "scope specifies the scope of this rule. Valid values are \"Cluster\", \"Namespaced\", and \"*\" \"Cluster\" means that only cluster-scoped resources will match this rule. Namespace API objects are cluster-scoped. \"Namespaced\" means that only namespaced resources will match this rule. \"*\" means that there are no scope restrictions. Subresources match the scope of their parent resource. Default is \"*\".\n\n\nPossible enum values:\n - `\"*\"` means that all scopes are included.\n - `\"Cluster\"` means that scope is limited to cluster-scoped objects. Namespace objects are cluster-scoped.\n - `\"Namespaced\"` means that scope is limited to namespaced objects.", - "type": "string", - "enum": [ - "*", - "Cluster", - "Namespaced" - ] + "description": "scope specifies the scope of this rule. Valid values are \"Cluster\", \"Namespaced\", and \"*\" \"Cluster\" means that only cluster-scoped resources will match this rule. Namespace API objects are cluster-scoped. \"Namespaced\" means that only namespaced resources will match this rule. \"*\" means that there are no scope restrictions. Subresources match the scope of their parent resource. Default is \"*\".", + "type": "string" } }, "x-fabric8-info": { @@ -20820,13 +20810,8 @@ "x-kubernetes-list-type": "atomic" }, "scope": { - "description": "scope specifies the scope of this rule. Valid values are \"Cluster\", \"Namespaced\", and \"*\" \"Cluster\" means that only cluster-scoped resources will match this rule. Namespace API objects are cluster-scoped. \"Namespaced\" means that only namespaced resources will match this rule. \"*\" means that there are no scope restrictions. Subresources match the scope of their parent resource. Default is \"*\".\n\n\nPossible enum values:\n - `\"*\"` means that all scopes are included.\n - `\"Cluster\"` means that scope is limited to cluster-scoped objects. Namespace objects are cluster-scoped.\n - `\"Namespaced\"` means that scope is limited to namespaced objects.", - "type": "string", - "enum": [ - "*", - "Cluster", - "Namespaced" - ] + "description": "scope specifies the scope of this rule. Valid values are \"Cluster\", \"Namespaced\", and \"*\" \"Cluster\" means that only cluster-scoped resources will match this rule. Namespace API objects are cluster-scoped. \"Namespaced\" means that only namespaced resources will match this rule. \"*\" means that there are no scope restrictions. Subresources match the scope of their parent resource. Default is \"*\".", + "type": "string" } }, "x-fabric8-info": { @@ -21633,13 +21618,8 @@ "x-kubernetes-list-type": "atomic" }, "scope": { - "description": "scope specifies the scope of this rule. Valid values are \"Cluster\", \"Namespaced\", and \"*\" \"Cluster\" means that only cluster-scoped resources will match this rule. Namespace API objects are cluster-scoped. \"Namespaced\" means that only namespaced resources will match this rule. \"*\" means that there are no scope restrictions. Subresources match the scope of their parent resource. Default is \"*\".\n\n\nPossible enum values:\n - `\"*\"` means that all scopes are included.\n - `\"Cluster\"` means that scope is limited to cluster-scoped objects. Namespace objects are cluster-scoped.\n - `\"Namespaced\"` means that scope is limited to namespaced objects.", - "type": "string", - "enum": [ - "*", - "Cluster", - "Namespaced" - ] + "description": "scope specifies the scope of this rule. Valid values are \"Cluster\", \"Namespaced\", and \"*\" \"Cluster\" means that only cluster-scoped resources will match this rule. Namespace API objects are cluster-scoped. \"Namespaced\" means that only namespaced resources will match this rule. \"*\" means that there are no scope restrictions. Subresources match the scope of their parent resource. Default is \"*\".", + "type": "string" } }, "x-fabric8-info": { @@ -22425,13 +22405,8 @@ "x-kubernetes-list-type": "atomic" }, "scope": { - "description": "scope specifies the scope of this rule. Valid values are \"Cluster\", \"Namespaced\", and \"*\" \"Cluster\" means that only cluster-scoped resources will match this rule. Namespace API objects are cluster-scoped. \"Namespaced\" means that only namespaced resources will match this rule. \"*\" means that there are no scope restrictions. Subresources match the scope of their parent resource. Default is \"*\".\n\n\nPossible enum values:\n - `\"*\"` means that all scopes are included.\n - `\"Cluster\"` means that scope is limited to cluster-scoped objects. Namespace objects are cluster-scoped.\n - `\"Namespaced\"` means that scope is limited to namespaced objects.", - "type": "string", - "enum": [ - "*", - "Cluster", - "Namespaced" - ] + "description": "scope specifies the scope of this rule. Valid values are \"Cluster\", \"Namespaced\", and \"*\" \"Cluster\" means that only cluster-scoped resources will match this rule. Namespace API objects are cluster-scoped. \"Namespaced\" means that only namespaced resources will match this rule. \"*\" means that there are no scope restrictions. Subresources match the scope of their parent resource. Default is \"*\".", + "type": "string" } }, "x-fabric8-info": {