@@ -17,6 +17,8 @@ limitations under the License.
17
17
package routes
18
18
19
19
import (
20
+ "strings"
21
+
20
22
restful "github.com/emicklei/go-restful/v3"
21
23
"k8s.io/klog/v2"
22
24
@@ -38,10 +40,35 @@ type OpenAPI struct {
38
40
39
41
// Install adds the SwaggerUI webservice to the given mux.
40
42
func (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
+
41
55
spec , err := builder2 .BuildOpenAPISpecFromRoutes (restfuladapter .AdaptWebServices (c .RegisteredWebServices ()), oa .Config )
42
56
if err != nil {
43
57
klog .Fatalf ("Failed to build open api spec for root: %v" , err )
44
58
}
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
+
45
72
spec .Definitions = handler .PruneDefaults (spec .Definitions )
46
73
openAPIVersionedService := handler .NewOpenAPIService (spec )
47
74
openAPIVersionedService .RegisterOpenAPIVersionedService ("/openapi/v2" , mux )
0 commit comments