mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-04 04:08:16 +00:00 
			
		
		
		
	genericapiserver: unify swagger and openapi in config
This commit is contained in:
		@@ -274,11 +274,11 @@ func Run(s *options.ServerRunOptions) error {
 | 
				
			|||||||
	genericConfig.Authenticator = apiAuthenticator
 | 
						genericConfig.Authenticator = apiAuthenticator
 | 
				
			||||||
	genericConfig.Authorizer = apiAuthorizer
 | 
						genericConfig.Authorizer = apiAuthorizer
 | 
				
			||||||
	genericConfig.AdmissionControl = admissionController
 | 
						genericConfig.AdmissionControl = admissionController
 | 
				
			||||||
	genericConfig.OpenAPIConfig.Info.Title = "Kubernetes"
 | 
						genericConfig.OpenAPIConfig = genericapiserver.DefaultOpenAPIConfig(generatedopenapi.OpenAPIDefinitions)
 | 
				
			||||||
	genericConfig.OpenAPIConfig.Definitions = generatedopenapi.OpenAPIDefinitions
 | 
					 | 
				
			||||||
	genericConfig.EnableOpenAPISupport = true
 | 
					 | 
				
			||||||
	genericConfig.EnableMetrics = true
 | 
					 | 
				
			||||||
	genericConfig.OpenAPIConfig.SecurityDefinitions = securityDefinitions
 | 
						genericConfig.OpenAPIConfig.SecurityDefinitions = securityDefinitions
 | 
				
			||||||
 | 
						genericConfig.OpenAPIConfig.Info.Title = "Kubernetes"
 | 
				
			||||||
 | 
						genericConfig.SwaggerConfig = genericapiserver.DefaultSwaggerConfig()
 | 
				
			||||||
 | 
						genericConfig.EnableMetrics = true
 | 
				
			||||||
	genericConfig.LongRunningFunc = filters.BasicLongRunningRequestCheck(
 | 
						genericConfig.LongRunningFunc = filters.BasicLongRunningRequestCheck(
 | 
				
			||||||
		sets.NewString("watch", "proxy"),
 | 
							sets.NewString("watch", "proxy"),
 | 
				
			||||||
		sets.NewString("attach", "exec", "proxy", "log", "portforward"),
 | 
							sets.NewString("attach", "exec", "proxy", "log", "portforward"),
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -111,6 +111,8 @@ func (serverOptions *ServerRunOptions) Run(stopCh <-chan struct{}) error {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	config.Authorizer = authorizer.NewAlwaysAllowAuthorizer()
 | 
						config.Authorizer = authorizer.NewAlwaysAllowAuthorizer()
 | 
				
			||||||
 | 
						config.SwaggerConfig = genericapiserver.DefaultSwaggerConfig()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	s, err := config.Complete().New()
 | 
						s, err := config.Complete().New()
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return fmt.Errorf("Error in bringing up the server: %v", err)
 | 
							return fmt.Errorf("Error in bringing up the server: %v", err)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -165,9 +165,9 @@ func Run(s *options.ServerRunOptions) error {
 | 
				
			|||||||
	genericConfig.Authenticator = apiAuthenticator
 | 
						genericConfig.Authenticator = apiAuthenticator
 | 
				
			||||||
	genericConfig.Authorizer = apiAuthorizer
 | 
						genericConfig.Authorizer = apiAuthorizer
 | 
				
			||||||
	genericConfig.AdmissionControl = admissionController
 | 
						genericConfig.AdmissionControl = admissionController
 | 
				
			||||||
	genericConfig.OpenAPIConfig.Definitions = openapi.OpenAPIDefinitions
 | 
						genericConfig.OpenAPIConfig = genericapiserver.DefaultOpenAPIConfig(openapi.OpenAPIDefinitions)
 | 
				
			||||||
	genericConfig.EnableOpenAPISupport = true
 | 
					 | 
				
			||||||
	genericConfig.OpenAPIConfig.SecurityDefinitions = securityDefinitions
 | 
						genericConfig.OpenAPIConfig.SecurityDefinitions = securityDefinitions
 | 
				
			||||||
 | 
						genericConfig.SwaggerConfig = genericapiserver.DefaultSwaggerConfig()
 | 
				
			||||||
	genericConfig.LongRunningFunc = filters.BasicLongRunningRequestCheck(
 | 
						genericConfig.LongRunningFunc = filters.BasicLongRunningRequestCheck(
 | 
				
			||||||
		sets.NewString("watch", "proxy"),
 | 
							sets.NewString("watch", "proxy"),
 | 
				
			||||||
		sets.NewString("attach", "exec", "proxy", "log", "portforward"),
 | 
							sets.NewString("attach", "exec", "proxy", "log", "portforward"),
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -32,6 +32,7 @@ import (
 | 
				
			|||||||
	"strings"
 | 
						"strings"
 | 
				
			||||||
	"time"
 | 
						"time"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"github.com/emicklei/go-restful/swagger"
 | 
				
			||||||
	"github.com/go-openapi/spec"
 | 
						"github.com/go-openapi/spec"
 | 
				
			||||||
	"github.com/golang/glog"
 | 
						"github.com/golang/glog"
 | 
				
			||||||
	"github.com/pborman/uuid"
 | 
						"github.com/pborman/uuid"
 | 
				
			||||||
@@ -55,7 +56,7 @@ import (
 | 
				
			|||||||
	apiserverauthorizer "k8s.io/kubernetes/pkg/genericapiserver/authorizer"
 | 
						apiserverauthorizer "k8s.io/kubernetes/pkg/genericapiserver/authorizer"
 | 
				
			||||||
	genericfilters "k8s.io/kubernetes/pkg/genericapiserver/filters"
 | 
						genericfilters "k8s.io/kubernetes/pkg/genericapiserver/filters"
 | 
				
			||||||
	"k8s.io/kubernetes/pkg/genericapiserver/mux"
 | 
						"k8s.io/kubernetes/pkg/genericapiserver/mux"
 | 
				
			||||||
	"k8s.io/kubernetes/pkg/genericapiserver/openapi/common"
 | 
						openapicommon "k8s.io/kubernetes/pkg/genericapiserver/openapi/common"
 | 
				
			||||||
	"k8s.io/kubernetes/pkg/genericapiserver/options"
 | 
						"k8s.io/kubernetes/pkg/genericapiserver/options"
 | 
				
			||||||
	"k8s.io/kubernetes/pkg/genericapiserver/routes"
 | 
						"k8s.io/kubernetes/pkg/genericapiserver/routes"
 | 
				
			||||||
	genericvalidation "k8s.io/kubernetes/pkg/genericapiserver/validation"
 | 
						genericvalidation "k8s.io/kubernetes/pkg/genericapiserver/validation"
 | 
				
			||||||
@@ -94,7 +95,6 @@ type Config struct {
 | 
				
			|||||||
	AdmissionControl      admission.Interface
 | 
						AdmissionControl      admission.Interface
 | 
				
			||||||
	CorsAllowedOriginList []string
 | 
						CorsAllowedOriginList []string
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	EnableSwaggerSupport bool
 | 
					 | 
				
			||||||
	EnableSwaggerUI bool
 | 
						EnableSwaggerUI bool
 | 
				
			||||||
	EnableIndex     bool
 | 
						EnableIndex     bool
 | 
				
			||||||
	EnableProfiling bool
 | 
						EnableProfiling bool
 | 
				
			||||||
@@ -102,7 +102,6 @@ type Config struct {
 | 
				
			|||||||
	EnableContentionProfiling bool
 | 
						EnableContentionProfiling bool
 | 
				
			||||||
	EnableGarbageCollection   bool
 | 
						EnableGarbageCollection   bool
 | 
				
			||||||
	EnableMetrics             bool
 | 
						EnableMetrics             bool
 | 
				
			||||||
	EnableOpenAPISupport      bool
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Version will enable the /version endpoint if non-nil
 | 
						// Version will enable the /version endpoint if non-nil
 | 
				
			||||||
	Version *version.Info
 | 
						Version *version.Info
 | 
				
			||||||
@@ -136,8 +135,11 @@ type Config struct {
 | 
				
			|||||||
	// Serializer is required and provides the interface for serializing and converting objects to and from the wire
 | 
						// Serializer is required and provides the interface for serializing and converting objects to and from the wire
 | 
				
			||||||
	// The default (api.Codecs) usually works fine.
 | 
						// The default (api.Codecs) usually works fine.
 | 
				
			||||||
	Serializer runtime.NegotiatedSerializer
 | 
						Serializer runtime.NegotiatedSerializer
 | 
				
			||||||
	// OpenAPIConfig will be used in generating OpenAPI spec.  This has "working" defaults.
 | 
						// OpenAPIConfig will be used in generating OpenAPI spec. This is nil by default. Use DefaultOpenAPIConfig for "working" defaults.
 | 
				
			||||||
	OpenAPIConfig *common.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
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// If specified, requests will be allocated a random timeout between this value, and twice this value.
 | 
						// If specified, requests will be allocated a random timeout between this value, and twice this value.
 | 
				
			||||||
	// Note that it is up to the request handlers to ignore or honor this timeout. In seconds.
 | 
						// Note that it is up to the request handlers to ignore or honor this timeout. In seconds.
 | 
				
			||||||
	MinRequestTimeout int
 | 
						MinRequestTimeout int
 | 
				
			||||||
@@ -202,10 +204,23 @@ func NewConfig() *Config {
 | 
				
			|||||||
		BuildHandlerChainsFunc: DefaultBuildHandlerChain,
 | 
							BuildHandlerChainsFunc: DefaultBuildHandlerChain,
 | 
				
			||||||
		LegacyAPIGroupPrefixes: sets.NewString(DefaultLegacyAPIPrefix),
 | 
							LegacyAPIGroupPrefixes: sets.NewString(DefaultLegacyAPIPrefix),
 | 
				
			||||||
		HealthzChecks:          []healthz.HealthzChecker{healthz.PingHealthz},
 | 
							HealthzChecks:          []healthz.HealthzChecker{healthz.PingHealthz},
 | 
				
			||||||
 | 
					 | 
				
			||||||
		EnableIndex:            true,
 | 
							EnableIndex:            true,
 | 
				
			||||||
		EnableSwaggerSupport: true,
 | 
					
 | 
				
			||||||
		OpenAPIConfig: &common.Config{
 | 
							// Default to treating watch as a long-running operation
 | 
				
			||||||
 | 
							// Generic API servers have no inherent long-running subresources
 | 
				
			||||||
 | 
							LongRunningFunc: genericfilters.BasicLongRunningRequestCheck(sets.NewString("watch"), sets.NewString()),
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// this keeps the defaults in sync
 | 
				
			||||||
 | 
						defaultOptions := options.NewServerRunOptions()
 | 
				
			||||||
 | 
						// unset fields that can be overridden to avoid setting values so that we won't end up with lingering values.
 | 
				
			||||||
 | 
						// TODO we probably want to run the defaults the other way.  A default here drives it in the CLI flags
 | 
				
			||||||
 | 
						defaultOptions.AuditLogPath = ""
 | 
				
			||||||
 | 
						return config.ApplyOptions(defaultOptions)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func DefaultOpenAPIConfig(definitions *openapicommon.OpenAPIDefinitions) *openapicommon.Config {
 | 
				
			||||||
 | 
						return &openapicommon.Config{
 | 
				
			||||||
		ProtocolList:   []string{"https"},
 | 
							ProtocolList:   []string{"https"},
 | 
				
			||||||
		IgnorePrefixes: []string{"/swaggerapi"},
 | 
							IgnorePrefixes: []string{"/swaggerapi"},
 | 
				
			||||||
		Info: &spec.Info{
 | 
							Info: &spec.Info{
 | 
				
			||||||
@@ -220,19 +235,25 @@ func NewConfig() *Config {
 | 
				
			|||||||
			},
 | 
								},
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
		GetOperationIDAndTags: apiserveropenapi.GetOperationIDAndTags,
 | 
							GetOperationIDAndTags: apiserveropenapi.GetOperationIDAndTags,
 | 
				
			||||||
		},
 | 
							Definitions:           definitions,
 | 
				
			||||||
 | 
					 | 
				
			||||||
		// Default to treating watch as a long-running operation
 | 
					 | 
				
			||||||
		// Generic API servers have no inherent long-running subresources
 | 
					 | 
				
			||||||
		LongRunningFunc: genericfilters.BasicLongRunningRequestCheck(sets.NewString("watch"), sets.NewString()),
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// this keeps the defaults in sync
 | 
					// DefaultSwaggerConfig returns a default configuration without WebServiceURL and
 | 
				
			||||||
	defaultOptions := options.NewServerRunOptions()
 | 
					// WebServices set.
 | 
				
			||||||
	// unset fields that can be overridden to avoid setting values so that we won't end up with lingering values.
 | 
					func DefaultSwaggerConfig() *swagger.Config {
 | 
				
			||||||
	// TODO we probably want to run the defaults the other way.  A default here drives it in the CLI flags
 | 
						return &swagger.Config{
 | 
				
			||||||
	defaultOptions.AuditLogPath = ""
 | 
							ApiPath:         "/swaggerapi/",
 | 
				
			||||||
	return config.ApplyOptions(defaultOptions)
 | 
							SwaggerPath:     "/swaggerui/",
 | 
				
			||||||
 | 
							SwaggerFilePath: "/swagger-ui/",
 | 
				
			||||||
 | 
							SchemaFormatHandler: func(typeName string) string {
 | 
				
			||||||
 | 
								switch typeName {
 | 
				
			||||||
 | 
								case "metav1.Time", "*metav1.Time":
 | 
				
			||||||
 | 
									return "date-time"
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								return ""
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (c *Config) ApplySecureServingOptions(secureServing *options.SecureServingOptions) (*Config, error) {
 | 
					func (c *Config) ApplySecureServingOptions(secureServing *options.SecureServingOptions) (*Config, error) {
 | 
				
			||||||
@@ -442,8 +463,8 @@ func (c *Config) Complete() completedConfig {
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
		c.ExternalAddress = hostAndPort
 | 
							c.ExternalAddress = hostAndPort
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	// All APIs will have the same authentication for now.
 | 
					 | 
				
			||||||
	if c.OpenAPIConfig != nil && c.OpenAPIConfig.SecurityDefinitions != nil {
 | 
						if c.OpenAPIConfig != nil && c.OpenAPIConfig.SecurityDefinitions != nil {
 | 
				
			||||||
 | 
							// Setup OpenAPI security: all APIs will have the same authentication for now.
 | 
				
			||||||
		c.OpenAPIConfig.DefaultSecurity = []map[string][]string{}
 | 
							c.OpenAPIConfig.DefaultSecurity = []map[string][]string{}
 | 
				
			||||||
		keys := []string{}
 | 
							keys := []string{}
 | 
				
			||||||
		for k := range *c.OpenAPIConfig.SecurityDefinitions {
 | 
							for k := range *c.OpenAPIConfig.SecurityDefinitions {
 | 
				
			||||||
@@ -464,6 +485,13 @@ func (c *Config) Complete() completedConfig {
 | 
				
			|||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						if c.SwaggerConfig != nil && len(c.SwaggerConfig.WebServicesUrl) == 0 {
 | 
				
			||||||
 | 
							if c.SecureServingInfo != nil {
 | 
				
			||||||
 | 
								c.SwaggerConfig.WebServicesUrl = "https://" + c.ExternalAddress
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								c.SwaggerConfig.WebServicesUrl = "http://" + c.ExternalAddress
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	if c.DiscoveryAddresses == nil {
 | 
						if c.DiscoveryAddresses == nil {
 | 
				
			||||||
		c.DiscoveryAddresses = DefaultDiscoveryAddresses{DefaultAddress: c.ExternalAddress}
 | 
							c.DiscoveryAddresses = DefaultDiscoveryAddresses{DefaultAddress: c.ExternalAddress}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -531,7 +559,6 @@ func (c completedConfig) New() (*GenericAPIServer, error) {
 | 
				
			|||||||
		Serializer:             c.Serializer,
 | 
							Serializer:             c.Serializer,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		minRequestTimeout: time.Duration(c.MinRequestTimeout) * time.Second,
 | 
							minRequestTimeout: time.Duration(c.MinRequestTimeout) * time.Second,
 | 
				
			||||||
		enableSwaggerSupport: c.EnableSwaggerSupport,
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
		SecureServingInfo:   c.SecureServingInfo,
 | 
							SecureServingInfo:   c.SecureServingInfo,
 | 
				
			||||||
		InsecureServingInfo: c.InsecureServingInfo,
 | 
							InsecureServingInfo: c.InsecureServingInfo,
 | 
				
			||||||
@@ -539,7 +566,7 @@ func (c completedConfig) New() (*GenericAPIServer, error) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
		apiGroupsForDiscovery: map[string]metav1.APIGroup{},
 | 
							apiGroupsForDiscovery: map[string]metav1.APIGroup{},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		enableOpenAPISupport: c.EnableOpenAPISupport,
 | 
							swaggerConfig: c.SwaggerConfig,
 | 
				
			||||||
		openAPIConfig: c.OpenAPIConfig,
 | 
							openAPIConfig: c.OpenAPIConfig,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		postStartHooks: map[string]postStartHookEntry{},
 | 
							postStartHooks: map[string]postStartHookEntry{},
 | 
				
			||||||
@@ -583,7 +610,7 @@ func (s *GenericAPIServer) installAPI(c *Config) {
 | 
				
			|||||||
	if c.EnableIndex {
 | 
						if c.EnableIndex {
 | 
				
			||||||
		routes.Index{}.Install(s.HandlerContainer)
 | 
							routes.Index{}.Install(s.HandlerContainer)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if c.EnableSwaggerSupport && c.EnableSwaggerUI {
 | 
						if c.SwaggerConfig != nil && c.EnableSwaggerUI {
 | 
				
			||||||
		routes.SwaggerUI{}.Install(s.HandlerContainer)
 | 
							routes.SwaggerUI{}.Install(s.HandlerContainer)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if c.EnableProfiling {
 | 
						if c.EnableProfiling {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -27,6 +27,7 @@ import (
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	systemd "github.com/coreos/go-systemd/daemon"
 | 
						systemd "github.com/coreos/go-systemd/daemon"
 | 
				
			||||||
	"github.com/emicklei/go-restful"
 | 
						"github.com/emicklei/go-restful"
 | 
				
			||||||
 | 
						"github.com/emicklei/go-restful/swagger"
 | 
				
			||||||
	"github.com/golang/glog"
 | 
						"github.com/golang/glog"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"k8s.io/kubernetes/pkg/admission"
 | 
						"k8s.io/kubernetes/pkg/admission"
 | 
				
			||||||
@@ -38,7 +39,7 @@ import (
 | 
				
			|||||||
	"k8s.io/kubernetes/pkg/apiserver"
 | 
						"k8s.io/kubernetes/pkg/apiserver"
 | 
				
			||||||
	"k8s.io/kubernetes/pkg/client/restclient"
 | 
						"k8s.io/kubernetes/pkg/client/restclient"
 | 
				
			||||||
	genericmux "k8s.io/kubernetes/pkg/genericapiserver/mux"
 | 
						genericmux "k8s.io/kubernetes/pkg/genericapiserver/mux"
 | 
				
			||||||
	"k8s.io/kubernetes/pkg/genericapiserver/openapi/common"
 | 
						openapicommon "k8s.io/kubernetes/pkg/genericapiserver/openapi/common"
 | 
				
			||||||
	"k8s.io/kubernetes/pkg/genericapiserver/routes"
 | 
						"k8s.io/kubernetes/pkg/genericapiserver/routes"
 | 
				
			||||||
	"k8s.io/kubernetes/pkg/healthz"
 | 
						"k8s.io/kubernetes/pkg/healthz"
 | 
				
			||||||
	"k8s.io/kubernetes/pkg/runtime"
 | 
						"k8s.io/kubernetes/pkg/runtime"
 | 
				
			||||||
@@ -86,12 +87,6 @@ type GenericAPIServer struct {
 | 
				
			|||||||
	// minRequestTimeout is how short the request timeout can be.  This is used to build the RESTHandler
 | 
						// minRequestTimeout is how short the request timeout can be.  This is used to build the RESTHandler
 | 
				
			||||||
	minRequestTimeout time.Duration
 | 
						minRequestTimeout time.Duration
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// enableSwaggerSupport indicates that swagger should be served.  This is currently separate because
 | 
					 | 
				
			||||||
	// the API group routes are created *after* initialization and you can't generate the swagger routes until
 | 
					 | 
				
			||||||
	// after those are available.
 | 
					 | 
				
			||||||
	// TODO eventually we should be able to factor this out to take place during initialization.
 | 
					 | 
				
			||||||
	enableSwaggerSupport bool
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// legacyAPIGroupPrefixes is used to set up URL parsing for authorization and for validating requests
 | 
						// legacyAPIGroupPrefixes is used to set up URL parsing for authorization and for validating requests
 | 
				
			||||||
	// to InstallLegacyAPIGroup
 | 
						// to InstallLegacyAPIGroup
 | 
				
			||||||
	legacyAPIGroupPrefixes sets.String
 | 
						legacyAPIGroupPrefixes sets.String
 | 
				
			||||||
@@ -131,10 +126,9 @@ type GenericAPIServer struct {
 | 
				
			|||||||
	apiGroupsForDiscoveryLock sync.RWMutex
 | 
						apiGroupsForDiscoveryLock sync.RWMutex
 | 
				
			||||||
	apiGroupsForDiscovery     map[string]metav1.APIGroup
 | 
						apiGroupsForDiscovery     map[string]metav1.APIGroup
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// See Config.$name for documentation of these flags
 | 
						// Enable swagger and/or OpenAPI if these configs are non-nil.
 | 
				
			||||||
 | 
						swaggerConfig *swagger.Config
 | 
				
			||||||
	enableOpenAPISupport bool
 | 
						openAPIConfig *openapicommon.Config
 | 
				
			||||||
	openAPIConfig        *common.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
 | 
				
			||||||
	// with no guaranteee of ordering between them.  The map key is a name used for error reporting.
 | 
						// with no guaranteee of ordering between them.  The map key is a name used for error reporting.
 | 
				
			||||||
@@ -174,10 +168,10 @@ 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.enableSwaggerSupport {
 | 
						if s.swaggerConfig != nil {
 | 
				
			||||||
		routes.Swagger{ExternalAddress: s.ExternalAddress}.Install(s.HandlerContainer)
 | 
							routes.Swagger{Config: s.swaggerConfig}.Install(s.HandlerContainer)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if s.enableOpenAPISupport {
 | 
						if s.openAPIConfig != nil {
 | 
				
			||||||
		routes.OpenAPI{
 | 
							routes.OpenAPI{
 | 
				
			||||||
			Config: s.openAPIConfig,
 | 
								Config: s.openAPIConfig,
 | 
				
			||||||
		}.Install(s.HandlerContainer)
 | 
							}.Install(s.HandlerContainer)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -58,15 +58,14 @@ func setUp(t *testing.T) (*etcdtesting.EtcdTestServer, Config, *assert.Assertion
 | 
				
			|||||||
	config.RequestContextMapper = api.NewRequestContextMapper()
 | 
						config.RequestContextMapper = api.NewRequestContextMapper()
 | 
				
			||||||
	config.LegacyAPIGroupPrefixes = sets.NewString("/api")
 | 
						config.LegacyAPIGroupPrefixes = sets.NewString("/api")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	config.EnableOpenAPISupport = true
 | 
						config.OpenAPIConfig = DefaultOpenAPIConfig(openapigen.OpenAPIDefinitions)
 | 
				
			||||||
	config.EnableSwaggerSupport = true
 | 
					 | 
				
			||||||
	config.OpenAPIConfig.Definitions = openapigen.OpenAPIDefinitions
 | 
					 | 
				
			||||||
	config.OpenAPIConfig.Info = &spec.Info{
 | 
						config.OpenAPIConfig.Info = &spec.Info{
 | 
				
			||||||
		InfoProps: spec.InfoProps{
 | 
							InfoProps: spec.InfoProps{
 | 
				
			||||||
			Title:   "Kubernetes",
 | 
								Title:   "Kubernetes",
 | 
				
			||||||
			Version: "unversioned",
 | 
								Version: "unversioned",
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						config.SwaggerConfig = DefaultSwaggerConfig()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return etcdServer, *config, assert.New(t)
 | 
						return etcdServer, *config, assert.New(t)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -88,13 +87,14 @@ func TestNew(t *testing.T) {
 | 
				
			|||||||
	defer etcdserver.Terminate(t)
 | 
						defer etcdserver.Terminate(t)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Verify many of the variables match their config counterparts
 | 
						// Verify many of the variables match their config counterparts
 | 
				
			||||||
	assert.Equal(s.enableSwaggerSupport, config.EnableSwaggerSupport)
 | 
					 | 
				
			||||||
	assert.Equal(s.legacyAPIGroupPrefixes, config.LegacyAPIGroupPrefixes)
 | 
						assert.Equal(s.legacyAPIGroupPrefixes, config.LegacyAPIGroupPrefixes)
 | 
				
			||||||
	assert.Equal(s.admissionControl, config.AdmissionControl)
 | 
						assert.Equal(s.admissionControl, config.AdmissionControl)
 | 
				
			||||||
	assert.Equal(s.RequestContextMapper(), config.RequestContextMapper)
 | 
						assert.Equal(s.RequestContextMapper(), config.RequestContextMapper)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// these values get defaulted
 | 
						// these values get defaulted
 | 
				
			||||||
	assert.Equal(s.ExternalAddress, net.JoinHostPort(config.PublicAddress.String(), "6443"))
 | 
						assert.Equal(net.JoinHostPort(config.PublicAddress.String(), "6443"), 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.
 | 
				
			||||||
@@ -270,8 +270,8 @@ func TestPrepareRun(t *testing.T) {
 | 
				
			|||||||
	s, etcdserver, config, assert := newMaster(t)
 | 
						s, etcdserver, config, assert := newMaster(t)
 | 
				
			||||||
	defer etcdserver.Terminate(t)
 | 
						defer etcdserver.Terminate(t)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	assert.True(config.EnableSwaggerSupport)
 | 
						assert.NotNil(config.SwaggerConfig)
 | 
				
			||||||
	assert.True(config.EnableOpenAPISupport)
 | 
						assert.NotNil(config.OpenAPIConfig)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	server := httptest.NewServer(s.HandlerContainer.ServeMux)
 | 
						server := httptest.NewServer(s.HandlerContainer.ServeMux)
 | 
				
			||||||
	defer server.Close()
 | 
						defer server.Close()
 | 
				
			||||||
@@ -369,7 +369,7 @@ func TestNotRestRoutesHaveAuth(t *testing.T) {
 | 
				
			|||||||
	config.EnableSwaggerUI = true
 | 
						config.EnableSwaggerUI = true
 | 
				
			||||||
	config.EnableIndex = true
 | 
						config.EnableIndex = true
 | 
				
			||||||
	config.EnableProfiling = true
 | 
						config.EnableProfiling = true
 | 
				
			||||||
	config.EnableSwaggerSupport = true
 | 
						config.SwaggerConfig = DefaultSwaggerConfig()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	kubeVersion := version.Get()
 | 
						kubeVersion := version.Get()
 | 
				
			||||||
	config.Version = &kubeVersion
 | 
						config.Version = &kubeVersion
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -27,23 +27,11 @@ import (
 | 
				
			|||||||
// register their own web services into the Kubernetes mux prior to initialization
 | 
					// register their own web services into the Kubernetes mux prior to initialization
 | 
				
			||||||
// of swagger, so that other resource types show up in the documentation.
 | 
					// of swagger, so that other resource types show up in the documentation.
 | 
				
			||||||
type Swagger struct {
 | 
					type Swagger struct {
 | 
				
			||||||
	ExternalAddress string
 | 
						Config *swagger.Config
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Install adds the SwaggerUI webservice to the given mux.
 | 
					// Install adds the SwaggerUI webservice to the given mux.
 | 
				
			||||||
func (s Swagger) Install(c *mux.APIContainer) {
 | 
					func (s Swagger) Install(c *mux.APIContainer) {
 | 
				
			||||||
	swagger.RegisterSwaggerService(swagger.Config{
 | 
						s.Config.WebServices = c.RegisteredWebServices()
 | 
				
			||||||
		WebServicesUrl:  "https://" + s.ExternalAddress,
 | 
						swagger.RegisterSwaggerService(*s.Config, c.Container)
 | 
				
			||||||
		WebServices:     c.RegisteredWebServices(),
 | 
					 | 
				
			||||||
		ApiPath:         "/swaggerapi/",
 | 
					 | 
				
			||||||
		SwaggerPath:     "/swaggerui/",
 | 
					 | 
				
			||||||
		SwaggerFilePath: "/swagger-ui/",
 | 
					 | 
				
			||||||
		SchemaFormatHandler: func(typeName string) string {
 | 
					 | 
				
			||||||
			switch typeName {
 | 
					 | 
				
			||||||
			case "metav1.Time", "*metav1.Time":
 | 
					 | 
				
			||||||
				return "date-time"
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
			return ""
 | 
					 | 
				
			||||||
		},
 | 
					 | 
				
			||||||
	}, c.Container)
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,48 +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 (
 | 
					 | 
				
			||||||
	"net/http"
 | 
					 | 
				
			||||||
	"testing"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	"github.com/stretchr/testify/assert"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	genericmux "k8s.io/kubernetes/pkg/genericapiserver/mux"
 | 
					 | 
				
			||||||
)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// TestInstallSwaggerAPI verifies that the swagger api is added
 | 
					 | 
				
			||||||
// at the proper endpoint.
 | 
					 | 
				
			||||||
func TestInstallSwaggerAPI(t *testing.T) {
 | 
					 | 
				
			||||||
	assert := assert.New(t)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// Install swagger and test
 | 
					 | 
				
			||||||
	c := genericmux.NewAPIContainer(http.NewServeMux(), nil)
 | 
					 | 
				
			||||||
	Swagger{ExternalAddress: "1.2.3.4"}.Install(c)
 | 
					 | 
				
			||||||
	ws := c.RegisteredWebServices()
 | 
					 | 
				
			||||||
	if assert.NotEqual(0, len(ws), "SwaggerAPI not installed.") {
 | 
					 | 
				
			||||||
		assert.Equal("/swaggerapi/", ws[0].RootPath(), "SwaggerAPI did not install to the proper path. %s != /swaggerapi", ws[0].RootPath())
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// Empty externalHost verification
 | 
					 | 
				
			||||||
	c = genericmux.NewAPIContainer(http.NewServeMux(), nil)
 | 
					 | 
				
			||||||
	Swagger{ExternalAddress: ""}.Install(c)
 | 
					 | 
				
			||||||
	ws = c.RegisteredWebServices()
 | 
					 | 
				
			||||||
	if assert.NotEqual(0, len(ws), "SwaggerAPI not installed.") {
 | 
					 | 
				
			||||||
		assert.Equal("/swaggerapi/", ws[0].RootPath(), "SwaggerAPI did not install to the proper path. %s != /swaggerapi", ws[0].RootPath())
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -314,15 +314,16 @@ func TestValidOpenAPISpec(t *testing.T) {
 | 
				
			|||||||
	_, etcdserver, config, assert := setUp(t)
 | 
						_, etcdserver, config, assert := setUp(t)
 | 
				
			||||||
	defer etcdserver.Terminate(t)
 | 
						defer etcdserver.Terminate(t)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	config.GenericConfig.OpenAPIConfig.Definitions = openapigen.OpenAPIDefinitions
 | 
					 | 
				
			||||||
	config.GenericConfig.EnableOpenAPISupport = true
 | 
					 | 
				
			||||||
	config.GenericConfig.EnableIndex = true
 | 
						config.GenericConfig.EnableIndex = true
 | 
				
			||||||
 | 
						config.GenericConfig.OpenAPIConfig = genericapiserver.DefaultOpenAPIConfig(openapigen.OpenAPIDefinitions)
 | 
				
			||||||
	config.GenericConfig.OpenAPIConfig.Info = &spec.Info{
 | 
						config.GenericConfig.OpenAPIConfig.Info = &spec.Info{
 | 
				
			||||||
		InfoProps: spec.InfoProps{
 | 
							InfoProps: spec.InfoProps{
 | 
				
			||||||
			Title:   "Kubernetes",
 | 
								Title:   "Kubernetes",
 | 
				
			||||||
			Version: "unversioned",
 | 
								Version: "unversioned",
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						config.GenericConfig.SwaggerConfig = genericapiserver.DefaultSwaggerConfig()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	master, err := config.Complete().New()
 | 
						master, err := config.Complete().New()
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		t.Fatalf("Error in bringing up the master: %v", err)
 | 
							t.Fatalf("Error in bringing up the master: %v", err)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -184,8 +184,7 @@ func startMasterOrDie(masterConfig *master.Config, incomingServer *httptest.Serv
 | 
				
			|||||||
		masterConfig = NewMasterConfig()
 | 
							masterConfig = NewMasterConfig()
 | 
				
			||||||
		masterConfig.GenericConfig.EnableProfiling = true
 | 
							masterConfig.GenericConfig.EnableProfiling = true
 | 
				
			||||||
		masterConfig.GenericConfig.EnableMetrics = true
 | 
							masterConfig.GenericConfig.EnableMetrics = true
 | 
				
			||||||
		masterConfig.GenericConfig.EnableSwaggerSupport = true
 | 
							masterConfig.GenericConfig.OpenAPIConfig = genericapiserver.DefaultOpenAPIConfig(openapi.OpenAPIDefinitions)
 | 
				
			||||||
		masterConfig.GenericConfig.EnableOpenAPISupport = true
 | 
					 | 
				
			||||||
		masterConfig.GenericConfig.OpenAPIConfig.Info = &spec.Info{
 | 
							masterConfig.GenericConfig.OpenAPIConfig.Info = &spec.Info{
 | 
				
			||||||
			InfoProps: spec.InfoProps{
 | 
								InfoProps: spec.InfoProps{
 | 
				
			||||||
				Title:   "Kubernetes",
 | 
									Title:   "Kubernetes",
 | 
				
			||||||
@@ -198,6 +197,7 @@ func startMasterOrDie(masterConfig *master.Config, incomingServer *httptest.Serv
 | 
				
			|||||||
			},
 | 
								},
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		masterConfig.GenericConfig.OpenAPIConfig.Definitions = openapi.OpenAPIDefinitions
 | 
							masterConfig.GenericConfig.OpenAPIConfig.Definitions = openapi.OpenAPIDefinitions
 | 
				
			||||||
 | 
							masterConfig.GenericConfig.SwaggerConfig = genericapiserver.DefaultSwaggerConfig()
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// set the loopback client config
 | 
						// set the loopback client config
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -28,7 +28,6 @@ import (
 | 
				
			|||||||
func TestMasterExportsSymbols(t *testing.T) {
 | 
					func TestMasterExportsSymbols(t *testing.T) {
 | 
				
			||||||
	_ = &master.Config{
 | 
						_ = &master.Config{
 | 
				
			||||||
		GenericConfig: &genericapiserver.Config{
 | 
							GenericConfig: &genericapiserver.Config{
 | 
				
			||||||
			EnableSwaggerSupport: false,
 | 
					 | 
				
			||||||
			EnableMetrics: true,
 | 
								EnableMetrics: true,
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
		EnableCoreControllers: false,
 | 
							EnableCoreControllers: false,
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user