Skip to content

Commit 85fc2b8

Browse files
authored
Merge pull request #12 from p0lyn0mial/openapi-fix-openshift-api-1-19
fix filtering out CustomResourceQuota paths from OpenAPI
2 parents a5e0645 + 3b9a005 commit 85fc2b8

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

pkg/server/routes/openapi.go

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ limitations under the License.
1717
package routes
1818

1919
import (
20-
"strings"
21-
2220
restful "github.com/emicklei/go-restful"
2321
"github.com/go-openapi/spec"
2422
"k8s.io/klog/v2"
@@ -36,6 +34,17 @@ type OpenAPI struct {
3634

3735
// Install adds the SwaggerUI webservice to the given mux.
3836
func (oa OpenAPI) Install(c *restful.Container, mux *mux.PathRecorderMux) (*handler.OpenAPIService, *spec.Swagger) {
37+
// we shadow ClustResourceQuotas, RoleBindingRestrictions, and SecurityContextContstraints
38+
// with a CRD. This loop removes all CRQ,RBR, SCC paths
39+
// from the OpenAPI spec such that they don't conflict with the CRD
40+
// apiextensions-apiserver spec during merging.
41+
oa.Config.IgnorePrefixes = append(oa.Config.IgnorePrefixes,
42+
"/apis/quota.openshift.io/v1/clusterresourcequotas",
43+
"/apis/security.openshift.io/v1/securitycontextconstraints",
44+
"/apis/authorization.openshift.io/v1/rolebindingrestrictions",
45+
"/apis/authorization.openshift.io/v1/namespaces/{namespace}/rolebindingrestrictions",
46+
"/apis/authorization.openshift.io/v1/watch/namespaces/{namespace}/rolebindingrestrictions",
47+
"/apis/authorization.openshift.io/v1/watch/rolebindingrestrictions")
3948
spec, err := builder.BuildOpenAPISpec(c.RegisteredWebServices(), oa.Config)
4049
if err != nil {
4150
klog.Fatalf("Failed to build open api spec for root: %v", err)
@@ -46,18 +55,6 @@ func (oa OpenAPI) Install(c *restful.Container, mux *mux.PathRecorderMux) (*hand
4655
klog.Fatalf("Failed to create OpenAPIService: %v", err)
4756
}
4857

49-
// we shadow ClustResourceQuotas, RoleBindingRestrictions, and SecurityContextContstraints
50-
// with a CRD. This loop removes all CRQ,RBR, SCC paths
51-
// from the OpenAPI spec such that they don't conflict with the CRD
52-
// apiextensions-apiserver spec during merging.
53-
for pth := range spec.Paths.Paths {
54-
if strings.HasPrefix(pth, "/apis/quota.openshift.io/v1/clusterresourcequotas") ||
55-
strings.Contains(pth, "rolebindingrestrictions") ||
56-
strings.HasPrefix(pth, "/apis/security.openshift.io/v1/securitycontextconstraints") {
57-
delete(spec.Paths.Paths, pth)
58-
}
59-
}
60-
6158
err = openAPIVersionedService.RegisterOpenAPIVersionedService("/openapi/v2", mux)
6259
if err != nil {
6360
klog.Fatalf("Failed to register versioned open api spec for root: %v", err)

0 commit comments

Comments
 (0)