Remove build/verify scripts for swagger 1.2 API docs, API server swagger ui / swagger 1.2 config

Kubernetes-commit: 9229399bd6049bc7766829b436d5cb5fe0dfe2f1
This commit is contained in:
Jordan Liggitt 2019-01-15 10:44:36 -05:00 committed by Kubernetes Publisher
parent d55c9aeff1
commit 2109711572
10 changed files with 9 additions and 17235 deletions

View File

@ -56,7 +56,7 @@ type Attributes interface {
GetAPIVersion() string GetAPIVersion() string
// IsResourceRequest returns true for requests to API resources, like /api/v1/nodes, // IsResourceRequest returns true for requests to API resources, like /api/v1/nodes,
// and false for non-resource endpoints like /api, /healthz, and /swaggerapi // and false for non-resource endpoints like /api, /healthz
IsResourceRequest() bool IsResourceRequest() bool
// GetPath returns the path of the request // GetPath returns the path of the request

View File

@ -28,7 +28,6 @@ import (
"strings" "strings"
"time" "time"
"github.com/emicklei/go-restful-swagger12"
"github.com/go-openapi/spec" "github.com/go-openapi/spec"
"github.com/pborman/uuid" "github.com/pborman/uuid"
"k8s.io/klog" "k8s.io/klog"
@ -101,7 +100,6 @@ type Config struct {
AdmissionControl admission.Interface AdmissionControl admission.Interface
CorsAllowedOriginList []string CorsAllowedOriginList []string
EnableSwaggerUI bool
EnableIndex bool EnableIndex bool
EnableProfiling bool EnableProfiling bool
EnableDiscovery bool EnableDiscovery bool
@ -145,8 +143,6 @@ type Config struct {
Serializer runtime.NegotiatedSerializer Serializer runtime.NegotiatedSerializer
// OpenAPIConfig will be used in generating OpenAPI spec. This is nil by default. Use DefaultOpenAPIConfig for "working" defaults. // OpenAPIConfig will be used in generating OpenAPI spec. This is nil by default. Use DefaultOpenAPIConfig for "working" defaults.
OpenAPIConfig *openapicommon.Config OpenAPIConfig *openapicommon.Config
// SwaggerConfig will be used in generating Swagger spec. This is nil by default. Use DefaultSwaggerConfig for "working" defaults.
SwaggerConfig *swagger.Config
// RESTOptionsGetter is used to construct RESTStorage types via the generic registry. // RESTOptionsGetter is used to construct RESTStorage types via the generic registry.
RESTOptionsGetter genericregistry.RESTOptionsGetter RESTOptionsGetter genericregistry.RESTOptionsGetter
@ -279,7 +275,7 @@ func NewRecommendedConfig(codecs serializer.CodecFactory) *RecommendedConfig {
func DefaultOpenAPIConfig(getDefinitions openapicommon.GetOpenAPIDefinitions, defNamer *apiopenapi.DefinitionNamer) *openapicommon.Config { func DefaultOpenAPIConfig(getDefinitions openapicommon.GetOpenAPIDefinitions, defNamer *apiopenapi.DefinitionNamer) *openapicommon.Config {
return &openapicommon.Config{ return &openapicommon.Config{
ProtocolList: []string{"https"}, ProtocolList: []string{"https"},
IgnorePrefixes: []string{"/swaggerapi"}, IgnorePrefixes: []string{},
Info: &spec.Info{ Info: &spec.Info{
InfoProps: spec.InfoProps{ InfoProps: spec.InfoProps{
Title: "Generic API Server", Title: "Generic API Server",
@ -296,23 +292,6 @@ func DefaultOpenAPIConfig(getDefinitions openapicommon.GetOpenAPIDefinitions, de
} }
} }
// DefaultSwaggerConfig returns a default configuration without WebServiceURL and
// WebServices set.
func DefaultSwaggerConfig() *swagger.Config {
return &swagger.Config{
ApiPath: "/swaggerapi",
SwaggerPath: "/swaggerui/",
SwaggerFilePath: "/swagger-ui/",
SchemaFormatHandler: func(typeName string) string {
switch typeName {
case "metav1.Time", "*metav1.Time":
return "date-time"
}
return ""
},
}
}
func (c *AuthenticationInfo) ApplyClientCert(clientCAFile string, servingInfo *SecureServingInfo) error { func (c *AuthenticationInfo) ApplyClientCert(clientCAFile string, servingInfo *SecureServingInfo) error {
if servingInfo != nil { if servingInfo != nil {
if len(clientCAFile) > 0 { if len(clientCAFile) > 0 {
@ -403,13 +382,6 @@ func (c *Config) Complete(informers informers.SharedInformerFactory) CompletedCo
} }
} }
} }
if c.SwaggerConfig != nil && len(c.SwaggerConfig.WebServicesUrl) == 0 {
if c.SecureServing != nil {
c.SwaggerConfig.WebServicesUrl = "https://" + c.ExternalAddress
} else {
c.SwaggerConfig.WebServicesUrl = "http://" + c.ExternalAddress
}
}
if c.DiscoveryAddresses == nil { if c.DiscoveryAddresses == nil {
c.DiscoveryAddresses = discovery.DefaultAddresses{DefaultAddress: c.ExternalAddress} c.DiscoveryAddresses = discovery.DefaultAddresses{DefaultAddress: c.ExternalAddress}
} }
@ -466,7 +438,6 @@ func (c completedConfig) New(name string, delegationTarget DelegationTarget) (*G
listedPathProvider: apiServerHandler, listedPathProvider: apiServerHandler,
swaggerConfig: c.SwaggerConfig,
openAPIConfig: c.OpenAPIConfig, openAPIConfig: c.OpenAPIConfig,
postStartHooks: map[string]postStartHookEntry{}, postStartHooks: map[string]postStartHookEntry{},
@ -550,9 +521,6 @@ func installAPI(s *GenericAPIServer, c *Config) {
if c.EnableIndex { if c.EnableIndex {
routes.Index{}.Install(s.listedPathProvider, s.Handler.NonGoRestfulMux) routes.Index{}.Install(s.listedPathProvider, s.Handler.NonGoRestfulMux)
} }
if c.SwaggerConfig != nil && c.EnableSwaggerUI {
routes.SwaggerUI{}.Install(s.Handler.NonGoRestfulMux)
}
if c.EnableProfiling { if c.EnableProfiling {
routes.Profiling{}.Install(s.Handler.NonGoRestfulMux) routes.Profiling{}.Install(s.Handler.NonGoRestfulMux)
if c.EnableContentionProfiling { if c.EnableContentionProfiling {

View File

@ -38,7 +38,6 @@ func TestNewWithDelegate(t *testing.T) {
delegateConfig.PublicAddress = net.ParseIP("192.168.10.4") delegateConfig.PublicAddress = net.ParseIP("192.168.10.4")
delegateConfig.LegacyAPIGroupPrefixes = sets.NewString("/api") delegateConfig.LegacyAPIGroupPrefixes = sets.NewString("/api")
delegateConfig.LoopbackClientConfig = &rest.Config{} delegateConfig.LoopbackClientConfig = &rest.Config{}
delegateConfig.SwaggerConfig = DefaultSwaggerConfig()
clientset := fake.NewSimpleClientset() clientset := fake.NewSimpleClientset()
if clientset == nil { if clientset == nil {
t.Fatal("unable to create fake client set") t.Fatal("unable to create fake client set")
@ -69,7 +68,6 @@ func TestNewWithDelegate(t *testing.T) {
wrappingConfig.PublicAddress = net.ParseIP("192.168.10.4") wrappingConfig.PublicAddress = net.ParseIP("192.168.10.4")
wrappingConfig.LegacyAPIGroupPrefixes = sets.NewString("/api") wrappingConfig.LegacyAPIGroupPrefixes = sets.NewString("/api")
wrappingConfig.LoopbackClientConfig = &rest.Config{} wrappingConfig.LoopbackClientConfig = &rest.Config{}
wrappingConfig.SwaggerConfig = DefaultSwaggerConfig()
wrappingConfig.HealthzChecks = append(wrappingConfig.HealthzChecks, healthz.NamedCheck("wrapping-health", func(r *http.Request) error { wrappingConfig.HealthzChecks = append(wrappingConfig.HealthzChecks, healthz.NamedCheck("wrapping-health", func(r *http.Request) error {
return fmt.Errorf("wrapping failed healthcheck") return fmt.Errorf("wrapping failed healthcheck")
@ -109,8 +107,7 @@ func TestNewWithDelegate(t *testing.T) {
"/healthz/poststarthook/generic-apiserver-start-informers", "/healthz/poststarthook/generic-apiserver-start-informers",
"/healthz/poststarthook/wrapping-post-start-hook", "/healthz/poststarthook/wrapping-post-start-hook",
"/healthz/wrapping-health", "/healthz/wrapping-health",
"/metrics", "/metrics"
"/swaggerapi"
] ]
}`, t) }`, t)
checkPath(server.URL+"/healthz", http.StatusInternalServerError, `[+]ping ok checkPath(server.URL+"/healthz", http.StatusInternalServerError, `[+]ping ok

View File

@ -25,7 +25,6 @@ import (
"time" "time"
systemd "github.com/coreos/go-systemd/daemon" systemd "github.com/coreos/go-systemd/daemon"
"github.com/emicklei/go-restful-swagger12"
"k8s.io/klog" "k8s.io/klog"
"k8s.io/apimachinery/pkg/api/meta" "k8s.io/apimachinery/pkg/api/meta"
@ -121,7 +120,6 @@ type GenericAPIServer struct {
DiscoveryGroupManager discovery.GroupManager DiscoveryGroupManager discovery.GroupManager
// Enable swagger and/or OpenAPI if these configs are non-nil. // Enable swagger and/or OpenAPI if these configs are non-nil.
swaggerConfig *swagger.Config
openAPIConfig *openapicommon.Config openAPIConfig *openapicommon.Config
// PostStartHooks are each called after the server has started listening, in a separate go func for each // PostStartHooks are each called after the server has started listening, in a separate go func for each
@ -236,9 +234,6 @@ type preparedGenericAPIServer struct {
// PrepareRun does post API installation setup steps. // PrepareRun does post API installation setup steps.
func (s *GenericAPIServer) PrepareRun() preparedGenericAPIServer { func (s *GenericAPIServer) PrepareRun() preparedGenericAPIServer {
if s.swaggerConfig != nil {
routes.Swagger{Config: s.swaggerConfig}.Install(s.Handler.GoRestfulContainer)
}
if s.openAPIConfig != nil { if s.openAPIConfig != nil {
routes.OpenAPI{ routes.OpenAPI{
Config: s.openAPIConfig, Config: s.openAPIConfig,

View File

@ -137,7 +137,6 @@ func setUp(t *testing.T) (Config, *assert.Assertions) {
config.OpenAPIConfig = DefaultOpenAPIConfig(testGetOpenAPIDefinitions, openapinamer.NewDefinitionNamer(runtime.NewScheme())) config.OpenAPIConfig = DefaultOpenAPIConfig(testGetOpenAPIDefinitions, openapinamer.NewDefinitionNamer(runtime.NewScheme()))
config.OpenAPIConfig.Info.Version = "unversioned" config.OpenAPIConfig.Info.Version = "unversioned"
config.SwaggerConfig = DefaultSwaggerConfig()
sharedInformers := informers.NewSharedInformerFactory(clientset, config.LoopbackClientConfig.Timeout) sharedInformers := informers.NewSharedInformerFactory(clientset, config.LoopbackClientConfig.Timeout)
config.Complete(sharedInformers) config.Complete(sharedInformers)
@ -162,11 +161,6 @@ func TestNew(t *testing.T) {
// Verify many of the variables match their config counterparts // Verify many of the variables match their config counterparts
assert.Equal(s.legacyAPIGroupPrefixes, config.LegacyAPIGroupPrefixes) assert.Equal(s.legacyAPIGroupPrefixes, config.LegacyAPIGroupPrefixes)
assert.Equal(s.admissionControl, config.AdmissionControl) assert.Equal(s.admissionControl, config.AdmissionControl)
// these values get defaulted
assert.Equal(net.JoinHostPort(config.PublicAddress.String(), "443"), s.ExternalAddress)
assert.NotNil(s.swaggerConfig)
assert.Equal("http://"+s.ExternalAddress, s.swaggerConfig.WebServicesUrl)
} }
// Verifies that AddGroupVersions works as expected. // Verifies that AddGroupVersions works as expected.
@ -321,7 +315,7 @@ func TestInstallAPIGroups(t *testing.T) {
func TestPrepareRun(t *testing.T) { func TestPrepareRun(t *testing.T) {
s, config, assert := newMaster(t) s, config, assert := newMaster(t)
assert.NotNil(config.SwaggerConfig) assert.NotNil(config.OpenAPIConfig)
server := httptest.NewServer(s.Handler.Director) server := httptest.NewServer(s.Handler.Director)
defer server.Close() defer server.Close()
@ -330,8 +324,8 @@ func TestPrepareRun(t *testing.T) {
s.PrepareRun() s.PrepareRun()
s.RunPostStartHooks(done) s.RunPostStartHooks(done)
// swagger is installed in PrepareRun // openapi is installed in PrepareRun
resp, err := http.Get(server.URL + "/swaggerapi/") resp, err := http.Get(server.URL + "/openapi/v2")
assert.NoError(err) assert.NoError(err)
assert.Equal(http.StatusOK, resp.StatusCode) assert.Equal(http.StatusOK, resp.StatusCode)
@ -406,10 +400,8 @@ func TestNotRestRoutesHaveAuth(t *testing.T) {
config.LegacyAPIGroupPrefixes = sets.NewString("/apiPrefix") config.LegacyAPIGroupPrefixes = sets.NewString("/apiPrefix")
config.Authorization.Authorizer = &authz config.Authorization.Authorizer = &authz
config.EnableSwaggerUI = true
config.EnableIndex = true config.EnableIndex = true
config.EnableProfiling = true config.EnableProfiling = true
config.SwaggerConfig = DefaultSwaggerConfig()
kubeVersion := fakeVersion() kubeVersion := fakeVersion()
config.Version = &kubeVersion config.Version = &kubeVersion
@ -423,7 +415,6 @@ func TestNotRestRoutesHaveAuth(t *testing.T) {
route string route string
}{ }{
{"/"}, {"/"},
{"/swagger-ui/"},
{"/debug/pprof/"}, {"/debug/pprof/"},
{"/debug/flags/"}, {"/debug/flags/"},
{"/version"}, {"/version"},

View File

@ -26,7 +26,6 @@ import (
type FeatureOptions struct { type FeatureOptions struct {
EnableProfiling bool EnableProfiling bool
EnableContentionProfiling bool EnableContentionProfiling bool
EnableSwaggerUI bool
} }
func NewFeatureOptions() *FeatureOptions { func NewFeatureOptions() *FeatureOptions {
@ -35,7 +34,6 @@ func NewFeatureOptions() *FeatureOptions {
return &FeatureOptions{ return &FeatureOptions{
EnableProfiling: defaults.EnableProfiling, EnableProfiling: defaults.EnableProfiling,
EnableContentionProfiling: defaults.EnableContentionProfiling, EnableContentionProfiling: defaults.EnableContentionProfiling,
EnableSwaggerUI: defaults.EnableSwaggerUI,
} }
} }
@ -48,8 +46,9 @@ func (o *FeatureOptions) AddFlags(fs *pflag.FlagSet) {
"Enable profiling via web interface host:port/debug/pprof/") "Enable profiling via web interface host:port/debug/pprof/")
fs.BoolVar(&o.EnableContentionProfiling, "contention-profiling", o.EnableContentionProfiling, fs.BoolVar(&o.EnableContentionProfiling, "contention-profiling", o.EnableContentionProfiling,
"Enable lock contention profiling, if profiling is enabled") "Enable lock contention profiling, if profiling is enabled")
fs.BoolVar(&o.EnableSwaggerUI, "enable-swagger-ui", o.EnableSwaggerUI, dummy := false
"Enables swagger ui on the apiserver at /swagger-ui") fs.BoolVar(&dummy, "enable-swagger-ui", dummy, "Enables swagger ui on the apiserver at /swagger-ui")
fs.MarkDeprecated("enable-swagger-ui", "swagger 1.2 support has been removed")
} }
func (o *FeatureOptions) ApplyTo(c *server.Config) error { func (o *FeatureOptions) ApplyTo(c *server.Config) error {
@ -59,7 +58,6 @@ func (o *FeatureOptions) ApplyTo(c *server.Config) error {
c.EnableProfiling = o.EnableProfiling c.EnableProfiling = o.EnableProfiling
c.EnableContentionProfiling = o.EnableContentionProfiling c.EnableContentionProfiling = o.EnableContentionProfiling
c.EnableSwaggerUI = o.EnableSwaggerUI
return nil return nil
} }

View File

@ -1,12 +0,0 @@
The datafiles contained in these directories were generated by the script
```sh
hack/build-ui.sh
```
Do not edit by hand.
[![Analytics](https://kubernetes-site.appspot.com/UA-36037335-10/GitHub/pkg/genericapiserver/addons/data/README.md?pixel)]()
[![Analytics](https://kubernetes-site.appspot.com/UA-36037335-10/GitHub/pkg/genericapiserver/server/routes/data/README.md?pixel)]()

File diff suppressed because one or more lines are too long

View File

@ -1,36 +0,0 @@
/*
Copyright 2016 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package routes
import (
"github.com/emicklei/go-restful"
"github.com/emicklei/go-restful-swagger12"
)
// Swagger installs the /swaggerapi/ endpoint to allow schema discovery
// and traversal. It is optional to allow consumers of the Kubernetes GenericAPIServer to
// register their own web services into the Kubernetes mux prior to initialization
// of swagger, so that other resource types show up in the documentation.
type Swagger struct {
Config *swagger.Config
}
// Install adds the SwaggerUI webservice to the given mux.
func (s Swagger) Install(c *restful.Container) {
s.Config.WebServices = c.RegisteredWebServices()
swagger.RegisterSwaggerService(*s.Config, c)
}

View File

@ -1,40 +0,0 @@
/*
Copyright 2014 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package routes
import (
"net/http"
assetfs "github.com/elazarl/go-bindata-assetfs"
"k8s.io/apiserver/pkg/server/mux"
"k8s.io/apiserver/pkg/server/routes/data/swagger"
)
// SwaggerUI exposes files in third_party/swagger-ui/ under /swagger-ui.
type SwaggerUI struct{}
// Install adds the SwaggerUI webservice to the given mux.
func (l SwaggerUI) Install(c *mux.PathRecorderMux) {
fileServer := http.FileServer(&assetfs.AssetFS{
Asset: swagger.Asset,
AssetDir: swagger.AssetDir,
Prefix: "third_party/swagger-ui",
})
prefix := "/swagger-ui/"
c.HandlePrefix(prefix, http.StripPrefix(prefix, fileServer))
}