Skip to content

Commit

Permalink
refactor: openshift-model 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 authored Sep 30, 2024
1 parent af75b61 commit d1fe13c
Show file tree
Hide file tree
Showing 38 changed files with 3,654 additions and 355 deletions.
2 changes: 2 additions & 0 deletions doc/MIGRATION-v7.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ It is no longer published, the `io.fabric8:kubernetes-client-api` or `io.fabric8

Some of the types and packages have been moved to more suiting modules and package names.

- `io.openshift.helm` API group is now part of the `openshift-model-miscellaneus` module.

### Service Catalog removed (operator.openshift.io) <a href="#service-catalog-removed" id="service-catalog-removed"/>

The operator.openshift.io APIs have been deprecated since OpenShift 4.1.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;

import java.util.Collections;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
Expand Down Expand Up @@ -167,8 +165,9 @@ void createRoleBindingRestriction() {
RoleBindingRestriction roleBindingRestriction = new RoleBindingRestrictionBuilder()
.withNewMetadata().withName(name).endMetadata()
.withNewSpec()
.withGrouprestriction(
Collections.singletonMap("groups", Collections.singletonList("groups-rolebindingrestriction")))
.withNewGrouprestriction()
.addToGroups("groups-rolebindingrestriction")
.endGrouprestriction()
.endSpec()
.build();

Expand Down
11 changes: 0 additions & 11 deletions kubernetes-model-generator/openapi/generator/cmd/reflection.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@ package main

import (
"github.com/getkin/kin-openapi/openapi3"
openshiftauthorizationv1 "github.com/openshift/api/authorization/v1"
openshiftmachinev1 "github.com/openshift/api/machine/v1"
openshiftmachinev1alpha1 "github.com/openshift/api/machine/v1alpha1"
openshiftsecurityv1 "github.com/openshift/api/security/v1"
"github.com/spf13/cobra"
admissionV1 "k8s.io/api/admission/v1"
admissionV1Beta1 "k8s.io/api/admission/v1beta1"
Expand Down Expand Up @@ -121,21 +119,12 @@ var reflectionRun = func(cmd *cobra.Command, args []string) {
reflect.TypeOf(metricsV1Beta1.PodMetricsList{}): {true, metricsV1Beta1.SchemeGroupVersion.String(), "pods", true},
reflect.TypeOf(metricsV1Beta1.PodMetrics{}): {false, metricsV1Beta1.SchemeGroupVersion.String(), "pods", true},
}, "metrics"),
NewTypeSchema([]reflect.Type{
reflect.TypeOf(openshiftauthorizationv1.SubjectAccessReviewResponse{}),
reflect.TypeOf(openshiftauthorizationv1.ResourceAccessReviewResponse{}),
}, "openshift-authorization"),
// Provider Specs are not included in OpenAPI https://docs.openshift.com/container-platform/4.16/machine_management/index.html#machine-mgmt-intro-managing-compute_overview-of-machine-management
NewPathSchema(map[reflect.Type]ApiVersion{
reflect.TypeOf(openshiftmachinev1alpha1.OpenstackProviderSpec{}): {false, openshiftmachinev1alpha1.GroupVersion.String(), "openstackproviderspecs", true},
reflect.TypeOf(openshiftmachinev1.NutanixMachineProviderConfig{}): {false, openshiftmachinev1.GroupVersion.String(), "nutanixmachineproviderconfigs", true},
reflect.TypeOf(openshiftmachinev1.PowerVSMachineProviderConfig{}): {false, openshiftmachinev1.GroupVersion.String(), "powervsmachineproviderconfigs", true},
}, "openshift-machine"),
// OpenAPI spec contains incomplete information for SecurityContextConstraints (only nested inline until certain level)
NewPathSchema(map[reflect.Type]ApiVersion{
reflect.TypeOf(openshiftsecurityv1.SecurityContextConstraintsList{}): {true, openshiftsecurityv1.GroupVersion.String(), "securitycontextconstraints", false},
reflect.TypeOf(openshiftsecurityv1.SecurityContextConstraints{}): {false, openshiftsecurityv1.GroupVersion.String(), "securitycontextconstraints", false},
}, "openshift-security"),
}
generate(schemas, targetDirectory)
}
Expand Down
25 changes: 20 additions & 5 deletions kubernetes-model-generator/openapi/generator/pkg/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ const genClient = "+genclient"
const genClientPrefix = genClient + ":"
const groupNamePrefix = "+groupName="

var listType = types.ParseFullyQualifiedName("k8s.io/apimachinery/pkg/apis/meta/v1.ListMeta")
var listMeta = types.ParseFullyQualifiedName("k8s.io/apimachinery/pkg/apis/meta/v1.ListMeta")
var typeMeta = types.ParseFullyQualifiedName("k8s.io/apimachinery/pkg/apis/meta/v1.TypeMeta")

type Module struct {
Name string
Expand Down Expand Up @@ -111,18 +112,32 @@ func groupName(pkg *types.Package) string {
}

func resolveType(typ *types.Type) string {
// Check if the type is a top-level type (Object)
// types with a genClient annotation are always objects
// types with a listType are always lists
// types with metaType are always lists or objects
for _, c := range append(typ.CommentLines, typ.SecondClosestCommentLines...) {
if strings.TrimSpace(c) == genClient {
return "object"
}
}
// Check if the type is a list
isList := false
isObject := false
for _, m := range typ.Members {
if m.Type.Name == listType {
return "list"
if m.Type.Name == listMeta {
isList = true
// stop iterating, if it's a list then it's not an object
break
} else if m.Type.Name == typeMeta {
isObject = true
// keep iterating, maybe it's a list
}
}
if isList {
return "list"
}
if isObject {
return "object"
}
return "nested"
}

Expand Down

This file was deleted.

Loading

0 comments on commit d1fe13c

Please sign in to comment.