From c733124920bf09f2637781da910129dea8e92b46 Mon Sep 17 00:00:00 2001 From: Chao Xu Date: Fri, 11 Sep 2015 17:20:02 -0700 Subject: [PATCH] address lavalamp's comments --- cmd/kube-apiserver/app/server.go | 12 +++++------- pkg/api/install/install.go | 2 ++ pkg/api/latest/latest.go | 15 ++++++++++++--- pkg/client/unversioned/fake/fake.go | 2 ++ pkg/client/unversioned/helper.go | 3 +-- pkg/client/unversioned/import_known_versions.go | 1 + pkg/expapi/install/install.go | 2 ++ pkg/master/import_known_versions.go | 1 + 8 files changed, 26 insertions(+), 12 deletions(-) diff --git a/cmd/kube-apiserver/app/server.go b/cmd/kube-apiserver/app/server.go index 464f6ddf701..e5dfde1eb1e 100644 --- a/cmd/kube-apiserver/app/server.go +++ b/cmd/kube-apiserver/app/server.go @@ -35,7 +35,6 @@ import ( "k8s.io/kubernetes/pkg/api" "k8s.io/kubernetes/pkg/api/latest" "k8s.io/kubernetes/pkg/api/meta" - "k8s.io/kubernetes/pkg/api/registered" "k8s.io/kubernetes/pkg/apiserver" "k8s.io/kubernetes/pkg/capabilities" client "k8s.io/kubernetes/pkg/client/unversioned" @@ -331,10 +330,6 @@ func (s *APIServer) Run(_ []string) error { // This takes preference over api/all, if specified. enableExp := s.getRuntimeConfigValue("experimental/v1", false) - if enableExp && len(registered.GroupVersionsForGroup("experimental")) == 0 { - glog.Fatalf("experimental API is enabled in runtime config, but not registered throught environment variable KUBE_API_VERSIONS") - } - clientConfig := &client.Config{ Host: net.JoinHostPort(s.InsecureBindAddress.String(), strconv.Itoa(s.InsecurePort)), Version: s.StorageVersion, @@ -351,8 +346,11 @@ func (s *APIServer) Run(_ []string) error { var expEtcdStorage storage.Interface if enableExp { - expEtcdStorage, err = newEtcd(s.EtcdConfigFile, s.EtcdServerList, latest.GroupOrDie("experimental").InterfacesFor, latest.GroupOrDie("experimental").Version, s.ExpStorageVersion, s.EtcdPathPrefix) - + g, err := latest.Group("experimental") + if err != nil { + glog.Fatalf("experimental API is enabled in runtime config, but not enabled in the environment variable KUBE_API_VERSIONS. Error: %v", err) + } + expEtcdStorage, err = newEtcd(s.EtcdConfigFile, s.EtcdServerList, g.InterfacesFor, g.Version, s.ExpStorageVersion, s.EtcdPathPrefix) if err != nil { glog.Fatalf("Invalid experimental storage version or misconfigured etcd: %v", err) } diff --git a/pkg/api/install/install.go b/pkg/api/install/install.go index 9bf4895e05e..14293ac14dc 100644 --- a/pkg/api/install/install.go +++ b/pkg/api/install/install.go @@ -14,6 +14,8 @@ See the License for the specific language governing permissions and limitations under the License. */ +// Package install installs the v1 monolithic api, making it available as an +// option to all of the API encoding/decoding machinery. package install import ( diff --git a/pkg/api/latest/latest.go b/pkg/api/latest/latest.go index cdbdeb4af2f..250b7783aac 100644 --- a/pkg/api/latest/latest.go +++ b/pkg/api/latest/latest.go @@ -25,14 +25,19 @@ import ( ) var ( - allGroups = GroupMetaMap{} - Group = allGroups.Group + allGroups = GroupMetaMap{} + // Group is a shortcut to allGroups.Group. + Group = allGroups.Group + // RegisterGroup is a shortcut to allGroups.RegisterGroup. RegisterGroup = allGroups.RegisterGroup - GroupOrDie = allGroups.GroupOrDie + // GroupOrDie is a shortcut to allGroups.GroupOrDie. + GroupOrDie = allGroups.GroupOrDie ) +// GroupMetaMap is a map between group names and their metadata. type GroupMetaMap map[string]*GroupMeta +// RegisterGroup registers a group to GroupMetaMap. func (g GroupMetaMap) RegisterGroup(group string) (*GroupMeta, error) { _, found := g[group] if found { @@ -45,6 +50,8 @@ func (g GroupMetaMap) RegisterGroup(group string) (*GroupMeta, error) { return g[group], nil } +// Group returns the metadata of a group if the gruop is registered, otherwise +// an erorr is returned. func (g GroupMetaMap) Group(group string) (*GroupMeta, error) { groupMeta, found := g[group] if !found { @@ -100,5 +107,7 @@ type GroupMeta struct { // Kubernetes versions. RESTMapper meta.RESTMapper + // InterfacesFor returns the default Codec and ResourceVersioner for a given version + // string, or an error if the version is not known. InterfacesFor func(version string) (*meta.VersionInterfaces, error) } diff --git a/pkg/client/unversioned/fake/fake.go b/pkg/client/unversioned/fake/fake.go index 404b8f52a1e..8e77910a649 100644 --- a/pkg/client/unversioned/fake/fake.go +++ b/pkg/client/unversioned/fake/fake.go @@ -14,6 +14,8 @@ See the License for the specific language governing permissions and limitations under the License. */ +// This is made a separate package and should only be imported by tests, because +// it imports testapi package fake import ( diff --git a/pkg/client/unversioned/helper.go b/pkg/client/unversioned/helper.go index 66a3ef283e8..c762abbc6fe 100644 --- a/pkg/client/unversioned/helper.go +++ b/pkg/client/unversioned/helper.go @@ -33,7 +33,6 @@ import ( "github.com/golang/glog" "k8s.io/kubernetes/pkg/api" "k8s.io/kubernetes/pkg/api/latest" - "k8s.io/kubernetes/pkg/api/registered" "k8s.io/kubernetes/pkg/runtime" "k8s.io/kubernetes/pkg/util" "k8s.io/kubernetes/pkg/util/sets" @@ -142,7 +141,7 @@ func New(c *Config) (*Client, error) { return nil, err } - if len(registered.GroupVersionsForGroup("experimental")) == 0 { + if _, err := latest.Group("experimental"); err != nil { return &Client{RESTClient: client, ExperimentalClient: nil}, nil } experimentalConfig := *c diff --git a/pkg/client/unversioned/import_known_versions.go b/pkg/client/unversioned/import_known_versions.go index b7f257282b4..ff98189c44d 100644 --- a/pkg/client/unversioned/import_known_versions.go +++ b/pkg/client/unversioned/import_known_versions.go @@ -16,6 +16,7 @@ limitations under the License. package unversioned +// These imports are the API groups the client will support. import ( _ "k8s.io/kubernetes/pkg/api/install" _ "k8s.io/kubernetes/pkg/expapi/install" diff --git a/pkg/expapi/install/install.go b/pkg/expapi/install/install.go index 0b29cbfc188..8b81f441a47 100644 --- a/pkg/expapi/install/install.go +++ b/pkg/expapi/install/install.go @@ -14,6 +14,8 @@ See the License for the specific language governing permissions and limitations under the License. */ +// Package install installs the experimental API group, making it available as +// an option to all of the API encoding/decoding machinery. package install import ( diff --git a/pkg/master/import_known_versions.go b/pkg/master/import_known_versions.go index 4daf0bd37db..31464878942 100644 --- a/pkg/master/import_known_versions.go +++ b/pkg/master/import_known_versions.go @@ -16,6 +16,7 @@ limitations under the License. package master +// These imports are the API groups the API server will support. import ( _ "k8s.io/kubernetes/pkg/api/install" _ "k8s.io/kubernetes/pkg/expapi/install"