Skip to content

Commit

Permalink
UPSTREAM: <carry>: filter out CustomResourceQuota paths from OpenAPI
Browse files Browse the repository at this point in the history
Origin-commit: b992ee2fcb5cd610e9242c3165908b6bc6e423f5

UPSTREAM: <carry>: filter out RBR and SCC paths from OpenAPI

Origin-commit: 5ce9a77a641ec9d0399226af572e429317d3daf6

UPSTREAM: <carry>: filter out RBR and SCC paths from OpenAPI

Origin-commit: 0ee08c7a5e138e8df2bd7d010e9ab59a6543cf63

Revise as per openshift/kubernetes-apiserver#12
  • Loading branch information
sttts authored and damemi committed Aug 27, 2021
1 parent a42cb17 commit cd0d7ea
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions staging/src/k8s.io/apiserver/pkg/server/routes/openapi.go
Expand Up @@ -17,6 +17,8 @@ limitations under the License.
package routes

import (
"strings"

restful "github.com/emicklei/go-restful"
"k8s.io/klog/v2"

Expand All @@ -34,10 +36,35 @@ type OpenAPI struct {

// Install adds the SwaggerUI webservice to the given mux.
func (oa OpenAPI) Install(c *restful.Container, mux *mux.PathRecorderMux) (*handler.OpenAPIService, *spec.Swagger) {
// we shadow ClustResourceQuotas, RoleBindingRestrictions, and SecurityContextContstraints
// with a CRD. This loop removes all CRQ,RBR, SCC paths
// from the OpenAPI spec such that they don't conflict with the CRD
// apiextensions-apiserver spec during merging.
oa.Config.IgnorePrefixes = append(oa.Config.IgnorePrefixes,
"/apis/quota.openshift.io/v1/clusterresourcequotas",
"/apis/security.openshift.io/v1/securitycontextconstraints",
"/apis/authorization.openshift.io/v1/rolebindingrestrictions",
"/apis/authorization.openshift.io/v1/namespaces/{namespace}/rolebindingrestrictions",
"/apis/authorization.openshift.io/v1/watch/namespaces/{namespace}/rolebindingrestrictions",
"/apis/authorization.openshift.io/v1/watch/rolebindingrestrictions")

spec, err := builder.BuildOpenAPISpec(c.RegisteredWebServices(), oa.Config)
if err != nil {
klog.Fatalf("Failed to build open api spec for root: %v", err)
}

// we shadow ClustResourceQuotas, RoleBindingRestrictions, and SecurityContextContstraints
// with a CRD. This loop removes all CRQ,RBR, SCC paths
// from the OpenAPI spec such that they don't conflict with the CRD
// apiextensions-apiserver spec during merging.
for pth := range spec.Paths.Paths {
if strings.HasPrefix(pth, "/apis/quota.openshift.io/v1/clusterresourcequotas") ||
strings.Contains(pth, "rolebindingrestrictions") ||
strings.HasPrefix(pth, "/apis/security.openshift.io/v1/securitycontextconstraints") {
delete(spec.Paths.Paths, pth)
}
}

spec.Definitions = handler.PruneDefaults(spec.Definitions)
openAPIVersionedService, err := handler.NewOpenAPIService(spec)
if err != nil {
Expand Down

0 comments on commit cd0d7ea

Please sign in to comment.