Skip to content

Commit

Permalink
refactor: openshift-model-operatorhub 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 Oct 2, 2024
1 parent fa135b9 commit cfaf175
Show file tree
Hide file tree
Showing 542 changed files with 509 additions and 72,430 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ func (g *GoGenerator) Generate() error {
)
}

// KubernetesTargets wrapper function around kube-openapi's generators.GetTargets function.
//
// Allows to override the default kube-openapi generators.apiTypeFilterFunc with our own (see KubernetesFilterFunc).
func (g *GoGenerator) KubernetesTargets(context *generator.Context) []generator.Target {
// Create a map of all the input packages for performance (queried later on)
g.inputPkgs = make(map[string]bool)
Expand All @@ -59,8 +62,16 @@ func (g *GoGenerator) KubernetesTargets(context *generator.Context) []generator.
return openApiGenTargets
}

// KubernetesFilterFunc
// KubernetesFilterFunc function to filter out types that are not Kubernetes Objects,
// Lists, or nested structs within those.
//
// Adaptation of https://github.com/kubernetes/kube-openapi/blob/9e1beecbcb384a484fb5cbd41024f316d51fdfac/pkg/generators/openapi.go#L106
//
// The original function only takes into account those structs that have been tagged with +k8s:openapi-gen=true
// or that belong to a package that has been tagged with +k8s:openapi-gen=true
//
// The default behavior is fine for most packages, however, some of them lack these annotations.
// While the upstream projects are fixed, we need to provide a workaround to generate the complete OpenAPI definitions.
func (g *GoGenerator) KubernetesFilterFunc(c *generator.Context, t *types.Type) bool {
// Skip types that are not structs
if t.Kind != types.Struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ package openshift

// PackagePatterns are the patterns required for OpenShift GO and JSON OpenAPI generation
var PackagePatterns = []string{
// Always import Kubernetes base packages as they are required by the rest of APIs
"k8s.io/apimachinery/pkg/apis/meta/v...",
"k8s.io/api/.../v...",
// OpenShift APIs
"github.com/openshift/api/.../v...",
// CRDs don't provide info for reused types
"github.com/operator-framework/api/pkg/operators/v...",
"github.com/openshift/cluster-network-operator/pkg/apis/.../v...",
// Always import Kubernetes base packages as they are required by the rest of APIs
"k8s.io/apimachinery/pkg/apis/meta/v...",
"k8s.io/api/.../v...",
}
22 changes: 14 additions & 8 deletions kubernetes-model-generator/openshift-model-operatorhub/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@
<groupId>io.fabric8</groupId>
<artifactId>kubernetes-model-core</artifactId>
</dependency>
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>kubernetes-model-admissionregistration</artifactId>
</dependency>
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>kubernetes-model-apps</artifactId>
</dependency>
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>kubernetes-model-rbac</artifactId>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
Expand All @@ -58,22 +70,16 @@
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>openapi-model-generator-maven-plugin</artifactId>
<configuration >
<configuration>
<settings combine.self="append">
<schemas>
<schema>${openapi.schema.openshift-latest}</schema>
<schema>${openapi.schema.openshift-generated}</schema>
</schemas>
<packageMappings combine.self="append">
<io.k8s.api>io.fabric8.kubernetes.api.model</io.k8s.api>
<io.openshift.operatorhub>io.fabric8.openshift.api.model.operatorhub</io.openshift.operatorhub>
<com.coreos.operators>io.fabric8.openshift.api.model.operatorhub</com.coreos.operators>
<com.github.operator-framework.api.pkg.operators>io.fabric8.openshift.api.model.operatorhub</com.github.operator-framework.api.pkg.operators>
<com.github.operator-framework.operator-lifecycle-manager.pkg.package-server.apis.operators>io.fabric8.openshift.api.model.operatorhub.lifecyclemanager</com.github.operator-framework.operator-lifecycle-manager.pkg.package-server.apis.operators>
</packageMappings>
<includeGenerationRegexes>
<includeGenerationRegex>^com\.coreos\.operators\..*$</includeGenerationRegex>
<includeGenerationRegex>^com\.github\.operator-framework\.api\.pkg\.operators\.v1alpha1\..*$</includeGenerationRegex>
<includeGenerationRegex>^com\.github\.operator-framework\.operator-lifecycle-manager\.pkg\.package-server\.apis\.operators\..*$</includeGenerationRegex>
</includeGenerationRegexes>
</settings>
</configuration>
Expand Down
Loading

0 comments on commit cfaf175

Please sign in to comment.