mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-01 07:47:56 +00:00
make version an explicit choice so zero config and customized work
This commit is contained in:
parent
c301ac9c7d
commit
5a9b16d40a
@ -57,6 +57,7 @@ import (
|
|||||||
"k8s.io/kubernetes/pkg/registry/cachesize"
|
"k8s.io/kubernetes/pkg/registry/cachesize"
|
||||||
"k8s.io/kubernetes/pkg/serviceaccount"
|
"k8s.io/kubernetes/pkg/serviceaccount"
|
||||||
"k8s.io/kubernetes/pkg/util/wait"
|
"k8s.io/kubernetes/pkg/util/wait"
|
||||||
|
"k8s.io/kubernetes/pkg/version"
|
||||||
authenticatorunion "k8s.io/kubernetes/plugin/pkg/auth/authenticator/request/union"
|
authenticatorunion "k8s.io/kubernetes/plugin/pkg/auth/authenticator/request/union"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -293,6 +294,8 @@ func Run(s *options.APIServer) error {
|
|||||||
glog.Fatalf("Failed to initialize plugins: %v", err)
|
glog.Fatalf("Failed to initialize plugins: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
kubeVersion := version.Get()
|
||||||
|
genericConfig.Version = &kubeVersion
|
||||||
genericConfig.LoopbackClientConfig = selfClientConfig
|
genericConfig.LoopbackClientConfig = selfClientConfig
|
||||||
genericConfig.Authenticator = apiAuthenticator
|
genericConfig.Authenticator = apiAuthenticator
|
||||||
genericConfig.SupportsBasicAuth = len(s.BasicAuthFile) > 0
|
genericConfig.SupportsBasicAuth = len(s.BasicAuthFile) > 0
|
||||||
|
@ -46,6 +46,7 @@ import (
|
|||||||
"k8s.io/kubernetes/pkg/registry/generic/registry"
|
"k8s.io/kubernetes/pkg/registry/generic/registry"
|
||||||
"k8s.io/kubernetes/pkg/routes"
|
"k8s.io/kubernetes/pkg/routes"
|
||||||
"k8s.io/kubernetes/pkg/util/wait"
|
"k8s.io/kubernetes/pkg/util/wait"
|
||||||
|
"k8s.io/kubernetes/pkg/version"
|
||||||
authenticatorunion "k8s.io/kubernetes/plugin/pkg/auth/authenticator/request/union"
|
authenticatorunion "k8s.io/kubernetes/plugin/pkg/auth/authenticator/request/union"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -183,6 +184,9 @@ func Run(s *options.ServerRunOptions) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Fatalf("Failed to initialize plugins: %v", err)
|
glog.Fatalf("Failed to initialize plugins: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
kubeVersion := version.Get()
|
||||||
|
genericConfig.Version = &kubeVersion
|
||||||
genericConfig.LoopbackClientConfig = selfClientConfig
|
genericConfig.LoopbackClientConfig = selfClientConfig
|
||||||
genericConfig.Authenticator = apiAuthenticator
|
genericConfig.Authenticator = apiAuthenticator
|
||||||
genericConfig.SupportsBasicAuth = len(s.BasicAuthFile) > 0
|
genericConfig.SupportsBasicAuth = len(s.BasicAuthFile) > 0
|
||||||
|
@ -55,6 +55,7 @@ import (
|
|||||||
certutil "k8s.io/kubernetes/pkg/util/cert"
|
certutil "k8s.io/kubernetes/pkg/util/cert"
|
||||||
utilnet "k8s.io/kubernetes/pkg/util/net"
|
utilnet "k8s.io/kubernetes/pkg/util/net"
|
||||||
"k8s.io/kubernetes/pkg/util/sets"
|
"k8s.io/kubernetes/pkg/util/sets"
|
||||||
|
"k8s.io/kubernetes/pkg/version"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -77,11 +78,12 @@ type Config struct {
|
|||||||
// allow downstream consumers to disable the index route
|
// allow downstream consumers to disable the index route
|
||||||
EnableIndex bool
|
EnableIndex bool
|
||||||
EnableProfiling bool
|
EnableProfiling bool
|
||||||
EnableVersion bool
|
|
||||||
EnableGarbageCollection bool
|
EnableGarbageCollection bool
|
||||||
APIGroupPrefix string
|
|
||||||
CorsAllowedOriginList []string
|
Version *version.Info
|
||||||
Authenticator authenticator.Request
|
APIGroupPrefix string
|
||||||
|
CorsAllowedOriginList []string
|
||||||
|
Authenticator authenticator.Request
|
||||||
// TODO(roberthbailey): Remove once the server no longer supports http basic auth.
|
// TODO(roberthbailey): Remove once the server no longer supports http basic auth.
|
||||||
SupportsBasicAuth bool
|
SupportsBasicAuth bool
|
||||||
Authorizer authorizer.Authorizer
|
Authorizer authorizer.Authorizer
|
||||||
@ -213,7 +215,6 @@ func NewConfig() *Config {
|
|||||||
|
|
||||||
EnableIndex: true,
|
EnableIndex: true,
|
||||||
EnableSwaggerSupport: true,
|
EnableSwaggerSupport: true,
|
||||||
EnableVersion: true,
|
|
||||||
OpenAPIConfig: &common.Config{
|
OpenAPIConfig: &common.Config{
|
||||||
ProtocolList: []string{"https"},
|
ProtocolList: []string{"https"},
|
||||||
IgnorePrefixes: []string{"/swaggerapi"},
|
IgnorePrefixes: []string{"/swaggerapi"},
|
||||||
@ -471,9 +472,7 @@ func (s *GenericAPIServer) installAPI(c *Config) {
|
|||||||
if c.EnableProfiling {
|
if c.EnableProfiling {
|
||||||
routes.Profiling{}.Install(s.HandlerContainer)
|
routes.Profiling{}.Install(s.HandlerContainer)
|
||||||
}
|
}
|
||||||
if c.EnableVersion {
|
routes.Version{Version: c.Version}.Install(s.HandlerContainer)
|
||||||
routes.Version{}.Install(s.HandlerContainer)
|
|
||||||
}
|
|
||||||
s.HandlerContainer.Add(s.DynamicApisDiscovery())
|
s.HandlerContainer.Add(s.DynamicApisDiscovery())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,6 +42,7 @@ import (
|
|||||||
etcdtesting "k8s.io/kubernetes/pkg/storage/etcd/testing"
|
etcdtesting "k8s.io/kubernetes/pkg/storage/etcd/testing"
|
||||||
utilnet "k8s.io/kubernetes/pkg/util/net"
|
utilnet "k8s.io/kubernetes/pkg/util/net"
|
||||||
"k8s.io/kubernetes/pkg/util/sets"
|
"k8s.io/kubernetes/pkg/util/sets"
|
||||||
|
"k8s.io/kubernetes/pkg/version"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
@ -230,7 +231,9 @@ func TestNotRestRoutesHaveAuth(t *testing.T) {
|
|||||||
config.EnableIndex = true
|
config.EnableIndex = true
|
||||||
config.EnableProfiling = true
|
config.EnableProfiling = true
|
||||||
config.EnableSwaggerSupport = true
|
config.EnableSwaggerSupport = true
|
||||||
config.EnableVersion = true
|
|
||||||
|
kubeVersion := version.Get()
|
||||||
|
config.Version = &kubeVersion
|
||||||
|
|
||||||
s, err := config.SkipComplete().New()
|
s, err := config.SkipComplete().New()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -27,16 +27,22 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Version provides a webservice with version information.
|
// Version provides a webservice with version information.
|
||||||
type Version struct{}
|
type Version struct {
|
||||||
|
Version *version.Info
|
||||||
|
}
|
||||||
|
|
||||||
// Install registers the APIServer's `/version` handler.
|
// Install registers the APIServer's `/version` handler.
|
||||||
func (v Version) Install(c *mux.APIContainer) {
|
func (v Version) Install(c *mux.APIContainer) {
|
||||||
|
if v.Version == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// Set up a service to return the git code version.
|
// Set up a service to return the git code version.
|
||||||
versionWS := new(restful.WebService)
|
versionWS := new(restful.WebService)
|
||||||
versionWS.Path("/version")
|
versionWS.Path("/version")
|
||||||
versionWS.Doc("git code version from which this is built")
|
versionWS.Doc("git code version from which this is built")
|
||||||
versionWS.Route(
|
versionWS.Route(
|
||||||
versionWS.GET("/").To(handleVersion).
|
versionWS.GET("/").To(v.handleVersion).
|
||||||
Doc("get the code version").
|
Doc("get the code version").
|
||||||
Operation("getCodeVersion").
|
Operation("getCodeVersion").
|
||||||
Produces(restful.MIME_JSON).
|
Produces(restful.MIME_JSON).
|
||||||
@ -47,6 +53,6 @@ func (v Version) Install(c *mux.APIContainer) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// handleVersion writes the server's version information.
|
// handleVersion writes the server's version information.
|
||||||
func handleVersion(req *restful.Request, resp *restful.Response) {
|
func (v Version) handleVersion(req *restful.Request, resp *restful.Response) {
|
||||||
apiserver.WriteRawJSON(http.StatusOK, version.Get(), resp.ResponseWriter)
|
apiserver.WriteRawJSON(http.StatusOK, *v.Version, resp.ResponseWriter)
|
||||||
}
|
}
|
||||||
|
@ -83,6 +83,8 @@ func setUp(t *testing.T) (*Master, *etcdtesting.EtcdTestServer, Config, *assert.
|
|||||||
resourceEncoding.SetVersionEncoding(certificates.GroupName, *testapi.Certificates.GroupVersion(), unversioned.GroupVersion{Group: certificates.GroupName, Version: runtime.APIVersionInternal})
|
resourceEncoding.SetVersionEncoding(certificates.GroupName, *testapi.Certificates.GroupVersion(), unversioned.GroupVersion{Group: certificates.GroupName, Version: runtime.APIVersionInternal})
|
||||||
storageFactory := genericapiserver.NewDefaultStorageFactory(*storageConfig, testapi.StorageMediaType(), api.Codecs, resourceEncoding, DefaultAPIResourceConfigSource())
|
storageFactory := genericapiserver.NewDefaultStorageFactory(*storageConfig, testapi.StorageMediaType(), api.Codecs, resourceEncoding, DefaultAPIResourceConfigSource())
|
||||||
|
|
||||||
|
kubeVersion := version.Get()
|
||||||
|
config.GenericConfig.Version = &kubeVersion
|
||||||
config.StorageFactory = storageFactory
|
config.StorageFactory = storageFactory
|
||||||
config.GenericConfig.LoopbackClientConfig = &restclient.Config{APIPath: "/api", ContentConfig: restclient.ContentConfig{NegotiatedSerializer: api.Codecs}}
|
config.GenericConfig.LoopbackClientConfig = &restclient.Config{APIPath: "/api", ContentConfig: restclient.ContentConfig{NegotiatedSerializer: api.Codecs}}
|
||||||
config.GenericConfig.APIResourceConfigSource = DefaultAPIResourceConfigSource()
|
config.GenericConfig.APIResourceConfigSource = DefaultAPIResourceConfigSource()
|
||||||
@ -94,7 +96,6 @@ func setUp(t *testing.T) (*Master, *etcdtesting.EtcdTestServer, Config, *assert.
|
|||||||
config.GenericConfig.ProxyDialer = func(network, addr string) (net.Conn, error) { return nil, nil }
|
config.GenericConfig.ProxyDialer = func(network, addr string) (net.Conn, error) { return nil, nil }
|
||||||
config.GenericConfig.ProxyTLSClientConfig = &tls.Config{}
|
config.GenericConfig.ProxyTLSClientConfig = &tls.Config{}
|
||||||
config.GenericConfig.RequestContextMapper = api.NewRequestContextMapper()
|
config.GenericConfig.RequestContextMapper = api.NewRequestContextMapper()
|
||||||
config.GenericConfig.EnableVersion = true
|
|
||||||
config.GenericConfig.LoopbackClientConfig = &restclient.Config{APIPath: "/api", ContentConfig: restclient.ContentConfig{NegotiatedSerializer: api.Codecs}}
|
config.GenericConfig.LoopbackClientConfig = &restclient.Config{APIPath: "/api", ContentConfig: restclient.ContentConfig{NegotiatedSerializer: api.Codecs}}
|
||||||
config.EnableCoreControllers = false
|
config.EnableCoreControllers = false
|
||||||
|
|
||||||
|
@ -61,6 +61,7 @@ import (
|
|||||||
"k8s.io/kubernetes/pkg/runtime"
|
"k8s.io/kubernetes/pkg/runtime"
|
||||||
"k8s.io/kubernetes/pkg/storage/storagebackend"
|
"k8s.io/kubernetes/pkg/storage/storagebackend"
|
||||||
"k8s.io/kubernetes/pkg/util/wait"
|
"k8s.io/kubernetes/pkg/util/wait"
|
||||||
|
"k8s.io/kubernetes/pkg/version"
|
||||||
"k8s.io/kubernetes/pkg/watch"
|
"k8s.io/kubernetes/pkg/watch"
|
||||||
"k8s.io/kubernetes/plugin/pkg/admission/admit"
|
"k8s.io/kubernetes/plugin/pkg/admission/admit"
|
||||||
authenticatorunion "k8s.io/kubernetes/plugin/pkg/auth/authenticator/request/union"
|
authenticatorunion "k8s.io/kubernetes/plugin/pkg/auth/authenticator/request/union"
|
||||||
@ -344,6 +345,8 @@ func NewMasterConfig() *master.Config {
|
|||||||
NewSingleContentTypeSerializer(api.Scheme, testapi.Storage.Codec(), runtime.ContentTypeJSON))
|
NewSingleContentTypeSerializer(api.Scheme, testapi.Storage.Codec(), runtime.ContentTypeJSON))
|
||||||
|
|
||||||
genericConfig := genericapiserver.NewConfig()
|
genericConfig := genericapiserver.NewConfig()
|
||||||
|
kubeVersion := version.Get()
|
||||||
|
genericConfig.Version = &kubeVersion
|
||||||
genericConfig.APIResourceConfigSource = master.DefaultAPIResourceConfigSource()
|
genericConfig.APIResourceConfigSource = master.DefaultAPIResourceConfigSource()
|
||||||
genericConfig.Authorizer = authorizer.NewAlwaysAllowAuthorizer()
|
genericConfig.Authorizer = authorizer.NewAlwaysAllowAuthorizer()
|
||||||
genericConfig.AdmissionControl = admit.NewAlwaysAdmit()
|
genericConfig.AdmissionControl = admit.NewAlwaysAdmit()
|
||||||
|
Loading…
Reference in New Issue
Block a user