Add (stopgap) support for an experimental API prefix.

This commit is contained in:
Muhammed Uluyol
2015-07-29 16:15:24 -07:00
parent a101aa175d
commit 58a875ac2c
31 changed files with 529 additions and 110 deletions

View File

@@ -36,6 +36,7 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/admission"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/meta"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/rest"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1"
"github.com/GoogleCloudPlatform/kubernetes/pkg/apiserver"
@@ -43,6 +44,7 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/auth/authorizer"
"github.com/GoogleCloudPlatform/kubernetes/pkg/auth/handlers"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
explatest "github.com/GoogleCloudPlatform/kubernetes/pkg/expapi/latest"
"github.com/GoogleCloudPlatform/kubernetes/pkg/fields"
"github.com/GoogleCloudPlatform/kubernetes/pkg/healthz"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
@@ -89,22 +91,25 @@ const (
// Config is a structure used to configure a Master.
type Config struct {
DatabaseStorage storage.Interface
EventTTL time.Duration
MinionRegexp string
KubeletClient client.KubeletClient
DatabaseStorage storage.Interface
ExpDatabaseStorage storage.Interface
EventTTL time.Duration
MinionRegexp string
KubeletClient client.KubeletClient
// allow downstream consumers to disable the core controller loops
EnableCoreControllers bool
EnableLogsSupport bool
EnableUISupport bool
// allow downstream consumers to disable swagger
EnableSwaggerSupport bool
// allow v1 to be conditionally disabled
// allow api versions to be conditionally disabled
DisableV1 bool
EnableExp bool
// allow downstream consumers to disable the index route
EnableIndex bool
EnableProfiling bool
APIPrefix string
ExpAPIPrefix string
CorsAllowedOriginList util.StringList
Authenticator authenticator.Request
// TODO(roberthbailey): Remove once the server no longer supports http basic auth.
@@ -181,12 +186,14 @@ type Master struct {
enableSwaggerSupport bool
enableProfiling bool
apiPrefix string
expAPIPrefix string
corsAllowedOriginList util.StringList
authenticator authenticator.Request
authorizer authorizer.Authorizer
admissionControl admission.Interface
masterCount int
v1 bool
exp bool
requestContextMapper api.RequestContextMapper
// External host is the name that should be used in external (public internet) URLs for this master
@@ -227,11 +234,8 @@ type Master struct {
// NewEtcdStorage returns a storage.Interface for the provided arguments or an error if the version
// is incorrect.
func NewEtcdStorage(client tools.EtcdClient, version string, prefix string) (etcdStorage storage.Interface, err error) {
if version == "" {
version = latest.Version
}
versionInterfaces, err := latest.InterfacesFor(version)
func NewEtcdStorage(client tools.EtcdClient, interfacesFunc meta.VersionInterfacesFunc, version, prefix string) (etcdStorage storage.Interface, err error) {
versionInterfaces, err := interfacesFunc(version)
if err != nil {
return etcdStorage, err
}
@@ -337,11 +341,13 @@ func New(c *Config) *Master {
enableSwaggerSupport: c.EnableSwaggerSupport,
enableProfiling: c.EnableProfiling,
apiPrefix: c.APIPrefix,
expAPIPrefix: c.ExpAPIPrefix,
corsAllowedOriginList: c.CorsAllowedOriginList,
authenticator: c.Authenticator,
authorizer: c.Authorizer,
admissionControl: c.AdmissionControl,
v1: !c.DisableV1,
exp: c.EnableExp,
requestContextMapper: c.RequestContextMapper,
cacheTimeout: c.CacheTimeout,
@@ -566,6 +572,16 @@ func (m *Master) init(c *Config) {
requestInfoResolver := &apiserver.APIRequestInfoResolver{util.NewStringSet(strings.TrimPrefix(defaultVersion.Root, "/")), defaultVersion.Mapper}
apiserver.InstallServiceErrorHandler(m.handlerContainer, requestInfoResolver, apiVersions)
if m.exp {
expVersion := m.expapi(c)
if err := expVersion.InstallREST(m.handlerContainer); err != nil {
glog.Fatalf("Unable to setup experimental api: %v", err)
}
apiserver.AddApiWebService(m.handlerContainer, c.ExpAPIPrefix, []string{expVersion.Version})
expRequestInfoResolver := &apiserver.APIRequestInfoResolver{util.NewStringSet(strings.TrimPrefix(expVersion.Root, "/")), expVersion.Mapper}
apiserver.InstallServiceErrorHandler(m.handlerContainer, expRequestInfoResolver, []string{expVersion.Version})
}
// Register root handler.
// We do not register this using restful Webservice since we do not want to surface this in api docs.
// Allow master to be embedded in contexts which already have something registered at the root
@@ -760,6 +776,30 @@ func (m *Master) api_v1() *apiserver.APIGroupVersion {
return version
}
// expapi returns the resources and codec for the experimental api
func (m *Master) expapi(c *Config) *apiserver.APIGroupVersion {
storage := map[string]rest.Storage{}
return &apiserver.APIGroupVersion{
Root: m.expAPIPrefix,
Creater: api.Scheme,
Convertor: api.Scheme,
Typer: api.Scheme,
Mapper: explatest.RESTMapper,
Codec: explatest.Codec,
Linker: explatest.SelfLinker,
Storage: storage,
Version: explatest.Version,
Admit: m.admissionControl,
Context: m.requestContextMapper,
ProxyDialerFn: m.dialer,
MinRequestTimeout: m.minRequestTimeout,
}
}
// findExternalAddress returns ExternalIP of provided node with fallback to LegacyHostIP.
func findExternalAddress(node *api.Node) (string, error) {
var fallback string

View File

@@ -21,6 +21,7 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest"
explatest "github.com/GoogleCloudPlatform/kubernetes/pkg/expapi/latest"
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/registrytest"
etcdstorage "github.com/GoogleCloudPlatform/kubernetes/pkg/storage/etcd"
"github.com/GoogleCloudPlatform/kubernetes/pkg/tools"
@@ -33,6 +34,7 @@ func TestGetServersToValidate(t *testing.T) {
fakeClient := tools.NewFakeEtcdClient(t)
fakeClient.Machines = []string{"http://machine1:4001", "http://machine2", "http://machine3:4003"}
config.DatabaseStorage = etcdstorage.NewEtcdStorage(fakeClient, latest.Codec, etcdtest.PathPrefix())
config.ExpDatabaseStorage = etcdstorage.NewEtcdStorage(fakeClient, explatest.Codec, etcdtest.PathPrefix())
master.nodeRegistry = registrytest.NewMinionRegistry([]string{"node1", "node2"}, api.NodeResources{})