@@ -17,6 +17,8 @@ limitations under the License.
1717package routes
1818
1919import (
20+ "strings"
21+
2022 restful "github.com/emicklei/go-restful/v3"
2123 "k8s.io/klog/v2"
2224
@@ -38,10 +40,35 @@ type OpenAPI struct {
3840
3941// Install adds the SwaggerUI webservice to the given mux.
4042func (oa OpenAPI ) InstallV2 (c * restful.Container , mux * mux.PathRecorderMux ) (* handler.OpenAPIService , * spec.Swagger ) {
43+ // we shadow ClustResourceQuotas, RoleBindingRestrictions, and SecurityContextContstraints
44+ // with a CRD. This loop removes all CRQ,RBR, SCC paths
45+ // from the OpenAPI spec such that they don't conflict with the CRD
46+ // apiextensions-apiserver spec during merging.
47+ oa .Config .IgnorePrefixes = append (oa .Config .IgnorePrefixes ,
48+ "/apis/quota.openshift.io/v1/clusterresourcequotas" ,
49+ "/apis/security.openshift.io/v1/securitycontextconstraints" ,
50+ "/apis/authorization.openshift.io/v1/rolebindingrestrictions" ,
51+ "/apis/authorization.openshift.io/v1/namespaces/{namespace}/rolebindingrestrictions" ,
52+ "/apis/authorization.openshift.io/v1/watch/namespaces/{namespace}/rolebindingrestrictions" ,
53+ "/apis/authorization.openshift.io/v1/watch/rolebindingrestrictions" )
54+
4155 spec , err := builder2 .BuildOpenAPISpecFromRoutes (restfuladapter .AdaptWebServices (c .RegisteredWebServices ()), oa .Config )
4256 if err != nil {
4357 klog .Fatalf ("Failed to build open api spec for root: %v" , err )
4458 }
59+
60+ // we shadow ClustResourceQuotas, RoleBindingRestrictions, and SecurityContextContstraints
61+ // with a CRD. This loop removes all CRQ,RBR, SCC paths
62+ // from the OpenAPI spec such that they don't conflict with the CRD
63+ // apiextensions-apiserver spec during merging.
64+ for pth := range spec .Paths .Paths {
65+ if strings .HasPrefix (pth , "/apis/quota.openshift.io/v1/clusterresourcequotas" ) ||
66+ strings .Contains (pth , "rolebindingrestrictions" ) ||
67+ strings .HasPrefix (pth , "/apis/security.openshift.io/v1/securitycontextconstraints" ) {
68+ delete (spec .Paths .Paths , pth )
69+ }
70+ }
71+
4572 spec .Definitions = handler .PruneDefaults (spec .Definitions )
4673 openAPIVersionedService := handler .NewOpenAPIService (spec )
4774 openAPIVersionedService .RegisterOpenAPIVersionedService ("/openapi/v2" , mux )
0 commit comments