address lavalamp's comments

This commit is contained in:
Chao Xu 2015-09-11 17:20:02 -07:00
parent f734a6f038
commit c733124920
8 changed files with 26 additions and 12 deletions

View File

@ -35,7 +35,6 @@ import (
"k8s.io/kubernetes/pkg/api" "k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/latest" "k8s.io/kubernetes/pkg/api/latest"
"k8s.io/kubernetes/pkg/api/meta" "k8s.io/kubernetes/pkg/api/meta"
"k8s.io/kubernetes/pkg/api/registered"
"k8s.io/kubernetes/pkg/apiserver" "k8s.io/kubernetes/pkg/apiserver"
"k8s.io/kubernetes/pkg/capabilities" "k8s.io/kubernetes/pkg/capabilities"
client "k8s.io/kubernetes/pkg/client/unversioned" 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. // This takes preference over api/all, if specified.
enableExp := s.getRuntimeConfigValue("experimental/v1", false) 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{ clientConfig := &client.Config{
Host: net.JoinHostPort(s.InsecureBindAddress.String(), strconv.Itoa(s.InsecurePort)), Host: net.JoinHostPort(s.InsecureBindAddress.String(), strconv.Itoa(s.InsecurePort)),
Version: s.StorageVersion, Version: s.StorageVersion,
@ -351,8 +346,11 @@ func (s *APIServer) Run(_ []string) error {
var expEtcdStorage storage.Interface var expEtcdStorage storage.Interface
if enableExp { 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 { if err != nil {
glog.Fatalf("Invalid experimental storage version or misconfigured etcd: %v", err) glog.Fatalf("Invalid experimental storage version or misconfigured etcd: %v", err)
} }

View File

@ -14,6 +14,8 @@ See the License for the specific language governing permissions and
limitations under the License. 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 package install
import ( import (

View File

@ -25,14 +25,19 @@ import (
) )
var ( var (
allGroups = GroupMetaMap{} allGroups = GroupMetaMap{}
Group = allGroups.Group // Group is a shortcut to allGroups.Group.
Group = allGroups.Group
// RegisterGroup is a shortcut to allGroups.RegisterGroup.
RegisterGroup = 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 type GroupMetaMap map[string]*GroupMeta
// RegisterGroup registers a group to GroupMetaMap.
func (g GroupMetaMap) RegisterGroup(group string) (*GroupMeta, error) { func (g GroupMetaMap) RegisterGroup(group string) (*GroupMeta, error) {
_, found := g[group] _, found := g[group]
if found { if found {
@ -45,6 +50,8 @@ func (g GroupMetaMap) RegisterGroup(group string) (*GroupMeta, error) {
return g[group], nil 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) { func (g GroupMetaMap) Group(group string) (*GroupMeta, error) {
groupMeta, found := g[group] groupMeta, found := g[group]
if !found { if !found {
@ -100,5 +107,7 @@ type GroupMeta struct {
// Kubernetes versions. // Kubernetes versions.
RESTMapper meta.RESTMapper 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) InterfacesFor func(version string) (*meta.VersionInterfaces, error)
} }

View File

@ -14,6 +14,8 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
// This is made a separate package and should only be imported by tests, because
// it imports testapi
package fake package fake
import ( import (

View File

@ -33,7 +33,6 @@ import (
"github.com/golang/glog" "github.com/golang/glog"
"k8s.io/kubernetes/pkg/api" "k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/latest" "k8s.io/kubernetes/pkg/api/latest"
"k8s.io/kubernetes/pkg/api/registered"
"k8s.io/kubernetes/pkg/runtime" "k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/util" "k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/pkg/util/sets" "k8s.io/kubernetes/pkg/util/sets"
@ -142,7 +141,7 @@ func New(c *Config) (*Client, error) {
return nil, err return nil, err
} }
if len(registered.GroupVersionsForGroup("experimental")) == 0 { if _, err := latest.Group("experimental"); err != nil {
return &Client{RESTClient: client, ExperimentalClient: nil}, nil return &Client{RESTClient: client, ExperimentalClient: nil}, nil
} }
experimentalConfig := *c experimentalConfig := *c

View File

@ -16,6 +16,7 @@ limitations under the License.
package unversioned package unversioned
// These imports are the API groups the client will support.
import ( import (
_ "k8s.io/kubernetes/pkg/api/install" _ "k8s.io/kubernetes/pkg/api/install"
_ "k8s.io/kubernetes/pkg/expapi/install" _ "k8s.io/kubernetes/pkg/expapi/install"

View File

@ -14,6 +14,8 @@ See the License for the specific language governing permissions and
limitations under the License. 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 package install
import ( import (

View File

@ -16,6 +16,7 @@ limitations under the License.
package master package master
// These imports are the API groups the API server will support.
import ( import (
_ "k8s.io/kubernetes/pkg/api/install" _ "k8s.io/kubernetes/pkg/api/install"
_ "k8s.io/kubernetes/pkg/expapi/install" _ "k8s.io/kubernetes/pkg/expapi/install"