diff --git a/hack/update-openapi-spec.sh b/hack/update-openapi-spec.sh index 5dd36eef16..572089126a 100755 --- a/hack/update-openapi-spec.sh +++ b/hack/update-openapi-spec.sh @@ -83,7 +83,7 @@ fi kube::log::status "Updating " ${OPENAPI_ROOT_DIR} -curl -w "\n" -fs "${API_HOST}:${API_PORT}/swagger.json" > "${OPENAPI_ROOT_DIR}/swagger.json" +curl -w "\n" -fs "${API_HOST}:${API_PORT}/openapi/v2" > "${OPENAPI_ROOT_DIR}/swagger.json" kube::log::status "SUCCESS" diff --git a/pkg/master/master_openapi_test.go b/pkg/master/master_openapi_test.go index 5f0d4327c4..ca7cd48aa8 100644 --- a/pkg/master/master_openapi_test.go +++ b/pkg/master/master_openapi_test.go @@ -61,7 +61,7 @@ func TestValidOpenAPISpec(t *testing.T) { // make sure swagger.json is not registered before calling PrepareRun. server := httptest.NewServer(master.GenericAPIServer.Handler.Director) defer server.Close() - resp, err := http.Get(server.URL + "/swagger.json") + resp, err := http.Get(server.URL + "/openapi/v2") if !assert.NoError(err) { t.Errorf("unexpected error: %v", err) } @@ -69,7 +69,7 @@ func TestValidOpenAPISpec(t *testing.T) { master.GenericAPIServer.PrepareRun() - resp, err = http.Get(server.URL + "/swagger.json") + resp, err = http.Get(server.URL + "/openapi/v2") if !assert.NoError(err) { t.Errorf("unexpected error: %v", err) } @@ -84,7 +84,7 @@ func TestValidOpenAPISpec(t *testing.T) { } // Validate OpenApi spec - doc, err := loads.Spec(server.URL + "/swagger.json") + doc, err := loads.Spec(server.URL + "/openapi/v2") if assert.NoError(err) { validator := validate.NewSpecValidator(doc.Schema(), strfmt.Default) res, warns := validator.Validate(doc) diff --git a/plugin/pkg/auth/authorizer/rbac/bootstrappolicy/policy.go b/plugin/pkg/auth/authorizer/rbac/bootstrappolicy/policy.go index 6eadce8d9a..6f5ebcac80 100644 --- a/plugin/pkg/auth/authorizer/rbac/bootstrappolicy/policy.go +++ b/plugin/pkg/auth/authorizer/rbac/bootstrappolicy/policy.go @@ -199,9 +199,6 @@ func ClusterRoles() []rbacv1.ClusterRole { Rules: []rbacv1.PolicyRule{ rbacv1helpers.NewRule("get").URLs( "/healthz", "/version", "/version/", - // do not expand this pattern for openapi discovery docs - // move to a single openapi endpoint that takes accept/accept-encoding headers - "/swagger.json", "/swagger-2.0.0.pb-v1", "/openapi", "/openapi/*", "/api", "/api/*", "/apis", "/apis/*", diff --git a/plugin/pkg/auth/authorizer/rbac/bootstrappolicy/testdata/cluster-roles.yaml b/plugin/pkg/auth/authorizer/rbac/bootstrappolicy/testdata/cluster-roles.yaml index 6a1fc69407..ea35a1b4b4 100644 --- a/plugin/pkg/auth/authorizer/rbac/bootstrappolicy/testdata/cluster-roles.yaml +++ b/plugin/pkg/auth/authorizer/rbac/bootstrappolicy/testdata/cluster-roles.yaml @@ -550,8 +550,6 @@ items: - /healthz - /openapi - /openapi/* - - /swagger-2.0.0.pb-v1 - - /swagger.json - /version - /version/ verbs: diff --git a/staging/src/k8s.io/apiserver/pkg/server/routes/openapi.go b/staging/src/k8s.io/apiserver/pkg/server/routes/openapi.go index 934bbf84a0..4d0cc3ee45 100644 --- a/staging/src/k8s.io/apiserver/pkg/server/routes/openapi.go +++ b/staging/src/k8s.io/apiserver/pkg/server/routes/openapi.go @@ -32,14 +32,7 @@ type OpenAPI struct { // Install adds the SwaggerUI webservice to the given mux. func (oa OpenAPI) Install(c *restful.Container, mux *mux.PathRecorderMux) { - // NOTE: [DEPRECATION] We will announce deprecation for format-separated endpoints for OpenAPI spec, - // and switch to a single /openapi/v2 endpoint in Kubernetes 1.10. The design doc and deprecation process - // are tracked at: https://docs.google.com/document/d/19lEqE9lc4yHJ3WJAJxS_G7TcORIJXGHyq3wpwcH28nU. - _, err := handler.BuildAndRegisterOpenAPIService("/swagger.json", c.RegisteredWebServices(), oa.Config, mux) - if err != nil { - klog.Fatalf("Failed to register open api spec for root: %v", err) - } - _, err = handler.BuildAndRegisterOpenAPIVersionedService("/openapi/v2", c.RegisteredWebServices(), oa.Config, mux) + _, err := handler.BuildAndRegisterOpenAPIVersionedService("/openapi/v2", c.RegisteredWebServices(), oa.Config, mux) if err != nil { klog.Fatalf("Failed to register versioned open api spec for root: %v", err) } diff --git a/staging/src/k8s.io/kube-aggregator/pkg/controllers/openapi/aggregator.go b/staging/src/k8s.io/kube-aggregator/pkg/controllers/openapi/aggregator.go index 4c1f75bd6d..4b72536a50 100644 --- a/staging/src/k8s.io/kube-aggregator/pkg/controllers/openapi/aggregator.go +++ b/staging/src/k8s.io/kube-aggregator/pkg/controllers/openapi/aggregator.go @@ -51,7 +51,6 @@ type specAggregator struct { openAPISpecs map[string]*openAPISpecInfo // provided for dynamic OpenAPI spec - openAPIService *handler.OpenAPIService openAPIVersionedService *handler.OpenAPIService } @@ -110,14 +109,6 @@ func BuildAndRegisterAggregator(downloader *Downloader, delegationTarget server. } // Install handler - // NOTE: [DEPRECATION] We will announce deprecation for format-separated endpoints for OpenAPI spec, - // and switch to a single /openapi/v2 endpoint in Kubernetes 1.10. The design doc and deprecation process - // are tracked at: https://docs.google.com/document/d/19lEqE9lc4yHJ3WJAJxS_G7TcORIJXGHyq3wpwcH28nU. - s.openAPIService, err = handler.RegisterOpenAPIService( - specToServe, "/swagger.json", pathHandler) - if err != nil { - return nil, err - } s.openAPIVersionedService, err = handler.RegisterOpenAPIVersionedService( specToServe, "/openapi/v2", pathHandler) if err != nil { @@ -216,24 +207,13 @@ func (s *specAggregator) buildOpenAPISpec() (specToReturn *spec.Swagger, err err // updateOpenAPISpec aggregates all OpenAPI specs. It is not thread-safe. The caller is responsible to hold proper locks. func (s *specAggregator) updateOpenAPISpec() error { - if s.openAPIService == nil || s.openAPIVersionedService == nil { - // openAPIVersionedService and deprecated openAPIService should be initialized together - if !(s.openAPIService == nil && s.openAPIVersionedService == nil) { - return fmt.Errorf("unexpected openapi service initialization error") - } + if s.openAPIVersionedService == nil { return nil } specToServe, err := s.buildOpenAPISpec() if err != nil { return err } - // openAPIService.UpdateSpec and openAPIVersionedService.UpdateSpec read the same swagger spec - // serially and update their local caches separately. Both endpoints will have same spec in - // their caches if the caller is holding proper locks. - err = s.openAPIService.UpdateSpec(specToServe) - if err != nil { - return err - } return s.openAPIVersionedService.UpdateSpec(specToServe) } diff --git a/staging/src/k8s.io/kube-aggregator/pkg/controllers/openapi/downloader.go b/staging/src/k8s.io/kube-aggregator/pkg/controllers/openapi/downloader.go index 3824401534..ea25e10ff1 100644 --- a/staging/src/k8s.io/kube-aggregator/pkg/controllers/openapi/downloader.go +++ b/staging/src/k8s.io/kube-aggregator/pkg/controllers/openapi/downloader.go @@ -29,7 +29,7 @@ import ( "k8s.io/apiserver/pkg/endpoints/request" ) -// Downloader is the OpenAPI downloader type. It will try to download spec from /swagger.json endpoint. +// Downloader is the OpenAPI downloader type. It will try to download spec from /openapi/v2 or /swagger.json endpoint. type Downloader struct { } @@ -89,7 +89,7 @@ func etagFor(data []byte) string { return fmt.Sprintf("%s%X\"", locallyGeneratedEtagPrefix, sha512.Sum512(data)) } -// Download downloads openAPI spec from /swagger.json endpoint of the given handler. +// Download downloads openAPI spec from /openapi/v2 or /swagger.json endpoint of the given handler. // httpStatus is only valid if err == nil func (s *Downloader) Download(handler http.Handler, etag string) (returnSpec *spec.Swagger, newEtag string, httpStatus int, err error) { handler = s.handlerWithUser(handler, &user.DefaultInfo{Name: aggregatorUser}) diff --git a/test/integration/master/kube_apiserver_test.go b/test/integration/master/kube_apiserver_test.go index 050b2f7584..5b31317d93 100644 --- a/test/integration/master/kube_apiserver_test.go +++ b/test/integration/master/kube_apiserver_test.go @@ -96,11 +96,11 @@ func TestOpenAPIDelegationChainPlumbing(t *testing.T) { t.Fatalf("unexpected error: %v", err) } - result := kubeclient.RESTClient().Get().AbsPath("/swagger.json").Do() + result := kubeclient.RESTClient().Get().AbsPath("/openapi/v2").Do() status := 0 result.StatusCode(&status) if status != http.StatusOK { - t.Fatalf("GET /swagger.json failed: expected status=%d, got=%d", http.StatusOK, status) + t.Fatalf("GET /openapi/v2 failed: expected status=%d, got=%d", http.StatusOK, status) } raw, err := result.Raw()