Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
7a83ce60
Commit
7a83ce60
authored
Dec 09, 2015
by
deads2k
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor group registration
parent
430be9ff
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
185 additions
and
108 deletions
+185
-108
install.go
...idl/client-gen/testdata/apis/testgroup/install/install.go
+26
-22
install.go
pkg/api/install/install.go
+41
-24
latest.go
pkg/api/latest/latest.go
+11
-12
install.go
pkg/apis/componentconfig/install/install.go
+35
-16
install.go
pkg/apis/extensions/install/install.go
+36
-17
install.go
pkg/apis/metrics/install/install.go
+36
-17
No files found.
cmd/libs/go2idl/client-gen/testdata/apis/testgroup/install/install.go
View file @
7a83ce60
...
@@ -37,33 +37,39 @@ const importPrefix = "k8s.io/kubernetes/pkg/apis/testgroup"
...
@@ -37,33 +37,39 @@ const importPrefix = "k8s.io/kubernetes/pkg/apis/testgroup"
var
accessor
=
meta
.
NewAccessor
()
var
accessor
=
meta
.
NewAccessor
()
const
groupName
=
"testgroup"
// availableVersions lists all known external versions for this group from most preferred to least preferred
var
availableVersions
=
[]
unversioned
.
GroupVersion
{{
Group
:
groupName
,
Version
:
"v1"
}}
func
init
()
{
func
init
()
{
registered
.
RegisteredGroupVersions
=
append
(
registered
.
RegisteredGroupVersions
,
v1
.
SchemeGroupVersion
)
registered
.
RegisteredGroupVersions
=
append
(
registered
.
RegisteredGroupVersions
,
v1
.
SchemeGroupVersion
)
groupMeta
,
err
:=
latest
.
RegisterGroup
(
"testgroup"
)
if
err
!=
nil
{
externalVersions
:=
availableVersions
preferredExternalVersion
:=
externalVersions
[
0
]
groupMeta
:=
latest
.
GroupMeta
{
GroupVersion
:
preferredExternalVersion
,
GroupVersions
:
externalVersions
,
Codec
:
runtime
.
CodecFor
(
api
.
Scheme
,
preferredExternalVersion
.
String
()),
RESTMapper
:
newRESTMapper
(
externalVersions
),
SelfLinker
:
runtime
.
SelfLinker
(
accessor
),
InterfacesFor
:
interfacesFor
,
}
if
err
:=
latest
.
RegisterGroup
(
groupMeta
);
err
!=
nil
{
glog
.
V
(
4
)
.
Infof
(
"%v"
,
err
)
glog
.
V
(
4
)
.
Infof
(
"%v"
,
err
)
return
return
}
}
registeredGroupVersions
:=
[]
unversioned
.
GroupVersion
{
api
.
RegisterRESTMapper
(
groupMeta
.
RESTMapper
)
{
}
"testgroup"
,
"v1"
,
},
}
groupVersion
:=
registeredGroupVersions
[
0
]
*
groupMeta
=
latest
.
GroupMeta
{
GroupVersion
:
groupVersion
,
Codec
:
runtime
.
CodecFor
(
api
.
Scheme
,
groupVersion
.
String
()),
}
func
newRESTMapper
(
externalVersions
[]
unversioned
.
GroupVersion
)
meta
.
RESTMapper
{
worstToBestGroupVersions
:=
[]
unversioned
.
GroupVersion
{}
worstToBestGroupVersions
:=
[]
unversioned
.
GroupVersion
{}
for
i
:=
len
(
registeredGroup
Versions
)
-
1
;
i
>=
0
;
i
--
{
for
i
:=
len
(
external
Versions
)
-
1
;
i
>=
0
;
i
--
{
worstToBestGroupVersions
=
append
(
worstToBestGroupVersions
,
registeredGroup
Versions
[
i
])
worstToBestGroupVersions
=
append
(
worstToBestGroupVersions
,
external
Versions
[
i
])
}
}
groupMeta
.
GroupVersions
=
registeredGroupVersions
groupMeta
.
SelfLinker
=
runtime
.
SelfLinker
(
accessor
)
// the list of kinds that are scoped at the root of the api hierarchy
// the list of kinds that are scoped at the root of the api hierarchy
// if a kind is not enumerated here, it is assumed to have a namespace scope
// if a kind is not enumerated here, it is assumed to have a namespace scope
...
@@ -71,9 +77,7 @@ func init() {
...
@@ -71,9 +77,7 @@ func init() {
ignoredKinds
:=
sets
.
NewString
()
ignoredKinds
:=
sets
.
NewString
()
groupMeta
.
RESTMapper
=
api
.
NewDefaultRESTMapper
(
worstToBestGroupVersions
,
interfacesFor
,
importPrefix
,
ignoredKinds
,
rootScoped
)
return
api
.
NewDefaultRESTMapper
(
worstToBestGroupVersions
,
interfacesFor
,
importPrefix
,
ignoredKinds
,
rootScoped
)
api
.
RegisterRESTMapper
(
groupMeta
.
RESTMapper
)
groupMeta
.
InterfacesFor
=
interfacesFor
}
}
// InterfacesFor returns the default Codec and ResourceVersioner for a given version
// InterfacesFor returns the default Codec and ResourceVersioner for a given version
...
@@ -87,7 +91,7 @@ func interfacesFor(version unversioned.GroupVersion) (*meta.VersionInterfaces, e
...
@@ -87,7 +91,7 @@ func interfacesFor(version unversioned.GroupVersion) (*meta.VersionInterfaces, e
MetadataAccessor
:
accessor
,
MetadataAccessor
:
accessor
,
},
nil
},
nil
default
:
default
:
g
,
_
:=
latest
.
Group
(
"testgroup"
)
g
,
_
:=
latest
.
Group
(
groupName
)
return
nil
,
fmt
.
Errorf
(
"unsupported storage version: %s (valid: %v)"
,
version
,
g
.
GroupVersions
)
return
nil
,
fmt
.
Errorf
(
"unsupported storage version: %s (valid: %v)"
,
version
,
g
.
GroupVersions
)
}
}
}
}
pkg/api/install/install.go
View file @
7a83ce60
...
@@ -34,35 +34,55 @@ import (
...
@@ -34,35 +34,55 @@ import (
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/runtime"
)
)
// userResources is a group of resources mostly used by a kubectl user
var
userResources
=
[]
string
{
"rc"
,
"svc"
,
"pods"
,
"pvc"
}
const
importPrefix
=
"k8s.io/kubernetes/pkg/api"
const
importPrefix
=
"k8s.io/kubernetes/pkg/api"
var
accessor
=
meta
.
NewAccessor
()
var
accessor
=
meta
.
NewAccessor
()
// availableVersions lists all known external versions for this group from most preferred to least preferred
var
availableVersions
=
[]
unversioned
.
GroupVersion
{
v1
.
SchemeGroupVersion
}
func
init
()
{
func
init
()
{
groupMeta
,
err
:=
latest
.
RegisterGroup
(
api
.
GroupName
)
externalVersions
:=
[]
unversioned
.
GroupVersion
{}
if
err
!=
nil
{
for
_
,
allowedVersion
:=
range
registered
.
GroupVersionsForGroup
(
api
.
GroupName
)
{
glog
.
V
(
4
)
.
Infof
(
"%v"
,
err
)
for
_
,
externalVersion
:=
range
availableVersions
{
if
externalVersion
==
allowedVersion
{
externalVersions
=
append
(
externalVersions
,
externalVersion
)
}
}
}
if
len
(
externalVersions
)
==
0
{
glog
.
V
(
4
)
.
Infof
(
"No version is registered for group %v"
,
api
.
GroupName
)
return
return
}
}
// Use the first API version in the list of registered versions as the latest.
preferredExternalVersion
:=
externalVersions
[
0
]
registeredGroupVersions
:=
registered
.
GroupVersionsForGroup
(
api
.
GroupName
)
groupVersion
:=
registeredGroupVersions
[
0
]
groupMeta
:=
latest
.
GroupMeta
{
*
groupMeta
=
latest
.
GroupMeta
{
GroupVersion
:
preferredExternalVersion
,
GroupVersion
:
groupVersion
,
GroupVersions
:
externalVersions
,
Codec
:
runtime
.
CodecFor
(
api
.
Scheme
,
groupVersion
.
String
()),
Codec
:
runtime
.
CodecFor
(
api
.
Scheme
,
preferredExternalVersion
.
String
()),
RESTMapper
:
newRESTMapper
(
externalVersions
),
SelfLinker
:
runtime
.
SelfLinker
(
accessor
),
InterfacesFor
:
interfacesFor
,
}
}
worstToBestGroupVersions
:=
[]
unversioned
.
GroupVersion
{}
if
err
:=
latest
.
RegisterGroup
(
groupMeta
);
err
!=
nil
{
for
i
:=
len
(
registeredGroupVersions
)
-
1
;
i
>=
0
;
i
--
{
glog
.
V
(
4
)
.
Infof
(
"%v"
,
err
)
worstToBestGroupVersions
=
append
(
worstToBestGroupVersions
,
registeredGroupVersions
[
i
])
return
}
}
groupMeta
.
GroupVersions
=
registeredGroupVersions
groupMeta
.
SelfLinker
=
runtime
.
SelfLinker
(
accessor
)
api
.
RegisterRESTMapper
(
groupMeta
.
RESTMapper
)
}
// userResources is a group of resources mostly used by a kubectl user
var
userResources
=
[]
string
{
"rc"
,
"svc"
,
"pods"
,
"pvc"
}
func
newRESTMapper
(
externalVersions
[]
unversioned
.
GroupVersion
)
meta
.
RESTMapper
{
worstToBestGroupVersions
:=
[]
unversioned
.
GroupVersion
{}
for
i
:=
len
(
externalVersions
)
-
1
;
i
>=
0
;
i
--
{
worstToBestGroupVersions
=
append
(
worstToBestGroupVersions
,
externalVersions
[
i
])
}
// the list of kinds that are scoped at the root of the api hierarchy
// the list of kinds that are scoped at the root of the api hierarchy
// if a kind is not enumerated here, it is assumed to have a namespace scope
// if a kind is not enumerated here, it is assumed to have a namespace scope
...
@@ -89,9 +109,8 @@ func init() {
...
@@ -89,9 +109,8 @@ func init() {
mapper
:=
api
.
NewDefaultRESTMapper
(
worstToBestGroupVersions
,
interfacesFor
,
importPrefix
,
ignoredKinds
,
rootScoped
)
mapper
:=
api
.
NewDefaultRESTMapper
(
worstToBestGroupVersions
,
interfacesFor
,
importPrefix
,
ignoredKinds
,
rootScoped
)
// setup aliases for groups of resources
// setup aliases for groups of resources
mapper
.
AddResourceAlias
(
"all"
,
userResources
...
)
mapper
.
AddResourceAlias
(
"all"
,
userResources
...
)
groupMeta
.
RESTMapper
=
mapper
api
.
RegisterRESTMapper
(
groupMeta
.
RESTMapper
)
return
mapper
groupMeta
.
InterfacesFor
=
interfacesFor
}
}
// InterfacesFor returns the default Codec and ResourceVersioner for a given version
// InterfacesFor returns the default Codec and ResourceVersioner for a given version
...
@@ -105,9 +124,7 @@ func interfacesFor(version unversioned.GroupVersion) (*meta.VersionInterfaces, e
...
@@ -105,9 +124,7 @@ func interfacesFor(version unversioned.GroupVersion) (*meta.VersionInterfaces, e
MetadataAccessor
:
accessor
,
MetadataAccessor
:
accessor
,
},
nil
},
nil
default
:
default
:
{
g
,
_
:=
latest
.
Group
(
api
.
GroupName
)
g
,
_
:=
latest
.
Group
(
api
.
GroupName
)
return
nil
,
fmt
.
Errorf
(
"unsupported storage version: %s (valid: %v)"
,
version
,
g
.
GroupVersions
)
return
nil
,
fmt
.
Errorf
(
"unsupported storage version: %s (valid: %v)"
,
version
,
g
.
GroupVersions
)
}
}
}
}
}
pkg/api/latest/latest.go
View file @
7a83ce60
...
@@ -22,7 +22,6 @@ import (
...
@@ -22,7 +22,6 @@ import (
"strings"
"strings"
"k8s.io/kubernetes/pkg/api/meta"
"k8s.io/kubernetes/pkg/api/meta"
"k8s.io/kubernetes/pkg/api/registered"
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/runtime"
)
)
...
@@ -52,16 +51,14 @@ var ExternalVersions = []unversioned.GroupVersion{
...
@@ -52,16 +51,14 @@ var ExternalVersions = []unversioned.GroupVersion{
type
GroupMetaMap
map
[
string
]
*
GroupMeta
type
GroupMetaMap
map
[
string
]
*
GroupMeta
// RegisterGroup registers a group to GroupMetaMap.
// RegisterGroup registers a group to GroupMetaMap.
func
(
g
GroupMetaMap
)
RegisterGroup
(
group
string
)
(
*
GroupMeta
,
error
)
{
func
(
g
GroupMetaMap
)
RegisterGroup
(
groupMeta
GroupMeta
)
error
{
_
,
found
:=
g
[
group
]
groupName
:=
groupMeta
.
GroupVersion
.
Group
if
found
{
if
_
,
found
:=
g
[
groupName
];
found
{
return
nil
,
fmt
.
Errorf
(
"group %v is already registered"
,
g
)
return
fmt
.
Errorf
(
"group %v is already registered"
,
g
)
}
if
len
(
registered
.
GroupVersionsForGroup
(
group
))
==
0
{
return
nil
,
fmt
.
Errorf
(
"No version is registered for group %v"
,
group
)
}
}
g
[
group
]
=
&
GroupMeta
{}
return
g
[
group
],
nil
g
[
groupName
]
=
&
groupMeta
return
nil
}
}
// Group returns the metadata of a group if the gruop is registered, otherwise
// Group returns the metadata of a group if the gruop is registered, otherwise
...
@@ -71,7 +68,8 @@ func (g GroupMetaMap) Group(group string) (*GroupMeta, error) {
...
@@ -71,7 +68,8 @@ func (g GroupMetaMap) Group(group string) (*GroupMeta, error) {
if
!
found
{
if
!
found
{
return
nil
,
fmt
.
Errorf
(
"no version is registered for group %v"
,
group
)
return
nil
,
fmt
.
Errorf
(
"no version is registered for group %v"
,
group
)
}
}
return
groupMeta
,
nil
groupMetaCopy
:=
*
groupMeta
return
&
groupMetaCopy
,
nil
}
}
// IsRegistered takes a string and determines if it's one of the registered groups
// IsRegistered takes a string and determines if it's one of the registered groups
...
@@ -93,7 +91,8 @@ func (g GroupMetaMap) GroupOrDie(group string) *GroupMeta {
...
@@ -93,7 +91,8 @@ func (g GroupMetaMap) GroupOrDie(group string) *GroupMeta {
panic
(
fmt
.
Sprintf
(
"No version is registered for group %s. "
,
group
)
+
msg
)
panic
(
fmt
.
Sprintf
(
"No version is registered for group %s. "
,
group
)
+
msg
)
}
}
}
}
return
groupMeta
groupMetaCopy
:=
*
groupMeta
return
&
groupMetaCopy
}
}
// AllPreferredGroupVersions returns the preferred versions of all registered
// AllPreferredGroupVersions returns the preferred versions of all registered
...
...
pkg/apis/componentconfig/install/install.go
View file @
7a83ce60
...
@@ -38,27 +38,48 @@ const importPrefix = "k8s.io/kubernetes/pkg/apis/componentconfig"
...
@@ -38,27 +38,48 @@ const importPrefix = "k8s.io/kubernetes/pkg/apis/componentconfig"
var
accessor
=
meta
.
NewAccessor
()
var
accessor
=
meta
.
NewAccessor
()
// availableVersions lists all known external versions for this group from most preferred to least preferred
var
availableVersions
=
[]
unversioned
.
GroupVersion
{
v1alpha1
.
SchemeGroupVersion
}
func
init
()
{
func
init
()
{
groupMeta
,
err
:=
latest
.
RegisterGroup
(
componentconfig
.
GroupName
)
externalVersions
:=
[]
unversioned
.
GroupVersion
{}
if
err
!=
nil
{
for
_
,
allowedVersion
:=
range
registered
.
GroupVersionsForGroup
(
componentconfig
.
GroupName
)
{
glog
.
V
(
4
)
.
Infof
(
"%v"
,
err
)
for
_
,
externalVersion
:=
range
availableVersions
{
if
externalVersion
==
allowedVersion
{
externalVersions
=
append
(
externalVersions
,
externalVersion
)
}
}
}
if
len
(
externalVersions
)
==
0
{
glog
.
V
(
4
)
.
Infof
(
"No version is registered for group %v"
,
componentconfig
.
GroupName
)
return
return
}
}
registeredGroupVersions
:=
registered
.
GroupVersionsForGroup
(
componentconfig
.
GroupName
)
preferredExternalVersion
:=
externalVersions
[
0
]
groupVersion
:=
registeredGroupVersions
[
0
]
*
groupMeta
=
latest
.
GroupMeta
{
groupMeta
:=
latest
.
GroupMeta
{
GroupVersion
:
groupVersion
,
GroupVersion
:
preferredExternalVersion
,
Codec
:
runtime
.
CodecFor
(
api
.
Scheme
,
groupVersion
.
String
()),
GroupVersions
:
externalVersions
,
Codec
:
runtime
.
CodecFor
(
api
.
Scheme
,
preferredExternalVersion
.
String
()),
RESTMapper
:
newRESTMapper
(
externalVersions
),
SelfLinker
:
runtime
.
SelfLinker
(
accessor
),
InterfacesFor
:
interfacesFor
,
}
}
worstToBestGroupVersions
:=
[]
unversioned
.
GroupVersion
{}
if
err
:=
latest
.
RegisterGroup
(
groupMeta
);
err
!=
nil
{
for
i
:=
len
(
registeredGroupVersions
)
-
1
;
i
>=
0
;
i
--
{
glog
.
V
(
4
)
.
Infof
(
"%v"
,
err
)
worstToBestGroupVersions
=
append
(
worstToBestGroupVersions
,
registeredGroupVersions
[
i
])
return
}
}
groupMeta
.
GroupVersions
=
registeredGroupVersions
groupMeta
.
SelfLinker
=
runtime
.
SelfLinker
(
accessor
)
api
.
RegisterRESTMapper
(
groupMeta
.
RESTMapper
)
}
func
newRESTMapper
(
externalVersions
[]
unversioned
.
GroupVersion
)
meta
.
RESTMapper
{
worstToBestGroupVersions
:=
[]
unversioned
.
GroupVersion
{}
for
i
:=
len
(
externalVersions
)
-
1
;
i
>=
0
;
i
--
{
worstToBestGroupVersions
=
append
(
worstToBestGroupVersions
,
externalVersions
[
i
])
}
// the list of kinds that are scoped at the root of the api hierarchy
// the list of kinds that are scoped at the root of the api hierarchy
// if a kind is not enumerated here, it is assumed to have a namespace scope
// if a kind is not enumerated here, it is assumed to have a namespace scope
...
@@ -66,9 +87,7 @@ func init() {
...
@@ -66,9 +87,7 @@ func init() {
ignoredKinds
:=
sets
.
NewString
()
ignoredKinds
:=
sets
.
NewString
()
groupMeta
.
RESTMapper
=
api
.
NewDefaultRESTMapper
(
worstToBestGroupVersions
,
interfacesFor
,
importPrefix
,
ignoredKinds
,
rootScoped
)
return
api
.
NewDefaultRESTMapper
(
worstToBestGroupVersions
,
interfacesFor
,
importPrefix
,
ignoredKinds
,
rootScoped
)
api
.
RegisterRESTMapper
(
groupMeta
.
RESTMapper
)
groupMeta
.
InterfacesFor
=
interfacesFor
}
}
// interfacesFor returns the default Codec and ResourceVersioner for a given version
// interfacesFor returns the default Codec and ResourceVersioner for a given version
...
...
pkg/apis/extensions/install/install.go
View file @
7a83ce60
...
@@ -38,27 +38,48 @@ const importPrefix = "k8s.io/kubernetes/pkg/apis/extensions"
...
@@ -38,27 +38,48 @@ const importPrefix = "k8s.io/kubernetes/pkg/apis/extensions"
var
accessor
=
meta
.
NewAccessor
()
var
accessor
=
meta
.
NewAccessor
()
// availableVersions lists all known external versions for this group from most preferred to least preferred
var
availableVersions
=
[]
unversioned
.
GroupVersion
{
v1beta1
.
SchemeGroupVersion
}
func
init
()
{
func
init
()
{
groupMeta
,
err
:=
latest
.
RegisterGroup
(
extensions
.
GroupName
)
externalVersions
:=
[]
unversioned
.
GroupVersion
{}
if
err
!=
nil
{
for
_
,
allowedVersion
:=
range
registered
.
GroupVersionsForGroup
(
extensions
.
GroupName
)
{
glog
.
V
(
4
)
.
Infof
(
"%v"
,
err
)
for
_
,
externalVersion
:=
range
availableVersions
{
if
externalVersion
==
allowedVersion
{
externalVersions
=
append
(
externalVersions
,
externalVersion
)
}
}
}
if
len
(
externalVersions
)
==
0
{
glog
.
V
(
4
)
.
Infof
(
"No version is registered for group %v"
,
extensions
.
GroupName
)
return
return
}
}
registeredGroupVersions
:=
registered
.
GroupVersionsForGroup
(
extensions
.
GroupName
)
preferredExternalVersion
:=
externalVersions
[
0
]
groupVersion
:=
registeredGroupVersions
[
0
]
*
groupMeta
=
latest
.
GroupMeta
{
groupMeta
:=
latest
.
GroupMeta
{
GroupVersion
:
groupVersion
,
GroupVersion
:
preferredExternalVersion
,
Codec
:
runtime
.
CodecFor
(
api
.
Scheme
,
groupVersion
.
String
()),
GroupVersions
:
externalVersions
,
Codec
:
runtime
.
CodecFor
(
api
.
Scheme
,
preferredExternalVersion
.
String
()),
RESTMapper
:
newRESTMapper
(
externalVersions
),
SelfLinker
:
runtime
.
SelfLinker
(
accessor
),
InterfacesFor
:
interfacesFor
,
}
}
worstToBestGroupVersions
:=
[]
unversioned
.
GroupVersion
{}
if
err
:=
latest
.
RegisterGroup
(
groupMeta
);
err
!=
nil
{
for
i
:=
len
(
registeredGroupVersions
)
-
1
;
i
>=
0
;
i
--
{
glog
.
V
(
4
)
.
Infof
(
"%v"
,
err
)
worstToBestGroupVersions
=
append
(
worstToBestGroupVersions
,
registeredGroupVersions
[
i
])
return
}
}
groupMeta
.
GroupVersions
=
registeredGroupVersions
groupMeta
.
SelfLinker
=
runtime
.
SelfLinker
(
accessor
)
api
.
RegisterRESTMapper
(
groupMeta
.
RESTMapper
)
}
func
newRESTMapper
(
externalVersions
[]
unversioned
.
GroupVersion
)
meta
.
RESTMapper
{
worstToBestGroupVersions
:=
[]
unversioned
.
GroupVersion
{}
for
i
:=
len
(
externalVersions
)
-
1
;
i
>=
0
;
i
--
{
worstToBestGroupVersions
=
append
(
worstToBestGroupVersions
,
externalVersions
[
i
])
}
// the list of kinds that are scoped at the root of the api hierarchy
// the list of kinds that are scoped at the root of the api hierarchy
// if a kind is not enumerated here, it is assumed to have a namespace scope
// if a kind is not enumerated here, it is assumed to have a namespace scope
...
@@ -66,12 +87,10 @@ func init() {
...
@@ -66,12 +87,10 @@ func init() {
ignoredKinds
:=
sets
.
NewString
()
ignoredKinds
:=
sets
.
NewString
()
groupMeta
.
RESTMapper
=
api
.
NewDefaultRESTMapper
(
worstToBestGroupVersions
,
interfacesFor
,
importPrefix
,
ignoredKinds
,
rootScoped
)
return
api
.
NewDefaultRESTMapper
(
worstToBestGroupVersions
,
interfacesFor
,
importPrefix
,
ignoredKinds
,
rootScoped
)
api
.
RegisterRESTMapper
(
groupMeta
.
RESTMapper
)
groupMeta
.
InterfacesFor
=
interfacesFor
}
}
//
I
nterfacesFor returns the default Codec and ResourceVersioner for a given version
//
i
nterfacesFor returns the default Codec and ResourceVersioner for a given version
// string, or an error if the version is not known.
// string, or an error if the version is not known.
func
interfacesFor
(
version
unversioned
.
GroupVersion
)
(
*
meta
.
VersionInterfaces
,
error
)
{
func
interfacesFor
(
version
unversioned
.
GroupVersion
)
(
*
meta
.
VersionInterfaces
,
error
)
{
switch
version
{
switch
version
{
...
...
pkg/apis/metrics/install/install.go
View file @
7a83ce60
...
@@ -38,27 +38,48 @@ const importPrefix = "k8s.io/kubernetes/pkg/apis/metrics"
...
@@ -38,27 +38,48 @@ const importPrefix = "k8s.io/kubernetes/pkg/apis/metrics"
var
accessor
=
meta
.
NewAccessor
()
var
accessor
=
meta
.
NewAccessor
()
// availableVersions lists all known external versions for this group from most preferred to least preferred
var
availableVersions
=
[]
unversioned
.
GroupVersion
{
v1alpha1
.
SchemeGroupVersion
}
func
init
()
{
func
init
()
{
groupMeta
,
err
:=
latest
.
RegisterGroup
(
metrics
.
GroupName
)
externalVersions
:=
[]
unversioned
.
GroupVersion
{}
if
err
!=
nil
{
for
_
,
allowedVersion
:=
range
registered
.
GroupVersionsForGroup
(
metrics
.
GroupName
)
{
glog
.
V
(
4
)
.
Infof
(
"%v"
,
err
)
for
_
,
externalVersion
:=
range
availableVersions
{
if
externalVersion
==
allowedVersion
{
externalVersions
=
append
(
externalVersions
,
externalVersion
)
}
}
}
if
len
(
externalVersions
)
==
0
{
glog
.
V
(
4
)
.
Infof
(
"No version is registered for group %v"
,
metrics
.
GroupName
)
return
return
}
}
registeredGroupVersions
:=
registered
.
GroupVersionsForGroup
(
metrics
.
GroupName
)
preferredExternalVersion
:=
externalVersions
[
0
]
groupVersion
:=
registeredGroupVersions
[
0
]
*
groupMeta
=
latest
.
GroupMeta
{
groupMeta
:=
latest
.
GroupMeta
{
GroupVersion
:
groupVersion
,
GroupVersion
:
preferredExternalVersion
,
Codec
:
runtime
.
CodecFor
(
api
.
Scheme
,
groupVersion
.
String
()),
GroupVersions
:
externalVersions
,
Codec
:
runtime
.
CodecFor
(
api
.
Scheme
,
preferredExternalVersion
.
String
()),
RESTMapper
:
newRESTMapper
(
externalVersions
),
SelfLinker
:
runtime
.
SelfLinker
(
accessor
),
InterfacesFor
:
interfacesFor
,
}
}
worstToBestGroupVersions
:=
[]
unversioned
.
GroupVersion
{}
if
err
:=
latest
.
RegisterGroup
(
groupMeta
);
err
!=
nil
{
for
i
:=
len
(
registeredGroupVersions
)
-
1
;
i
>=
0
;
i
--
{
glog
.
V
(
4
)
.
Infof
(
"%v"
,
err
)
worstToBestGroupVersions
=
append
(
worstToBestGroupVersions
,
registeredGroupVersions
[
i
])
return
}
}
groupMeta
.
GroupVersions
=
registeredGroupVersions
groupMeta
.
SelfLinker
=
runtime
.
SelfLinker
(
accessor
)
api
.
RegisterRESTMapper
(
groupMeta
.
RESTMapper
)
}
func
newRESTMapper
(
externalVersions
[]
unversioned
.
GroupVersion
)
meta
.
RESTMapper
{
worstToBestGroupVersions
:=
[]
unversioned
.
GroupVersion
{}
for
i
:=
len
(
externalVersions
)
-
1
;
i
>=
0
;
i
--
{
worstToBestGroupVersions
=
append
(
worstToBestGroupVersions
,
externalVersions
[
i
])
}
// the list of kinds that are scoped at the root of the api hierarchy
// the list of kinds that are scoped at the root of the api hierarchy
// if a kind is not enumerated here, it is assumed to have a namespace scope
// if a kind is not enumerated here, it is assumed to have a namespace scope
...
@@ -66,12 +87,10 @@ func init() {
...
@@ -66,12 +87,10 @@ func init() {
ignoredKinds
:=
sets
.
NewString
()
ignoredKinds
:=
sets
.
NewString
()
groupMeta
.
RESTMapper
=
api
.
NewDefaultRESTMapper
(
worstToBestGroupVersions
,
interfacesFor
,
importPrefix
,
ignoredKinds
,
rootScoped
)
return
api
.
NewDefaultRESTMapper
(
worstToBestGroupVersions
,
interfacesFor
,
importPrefix
,
ignoredKinds
,
rootScoped
)
api
.
RegisterRESTMapper
(
groupMeta
.
RESTMapper
)
groupMeta
.
InterfacesFor
=
interfacesFor
}
}
//
I
nterfacesFor returns the default Codec and ResourceVersioner for a given version
//
i
nterfacesFor returns the default Codec and ResourceVersioner for a given version
// string, or an error if the version is not known.
// string, or an error if the version is not known.
func
interfacesFor
(
version
unversioned
.
GroupVersion
)
(
*
meta
.
VersionInterfaces
,
error
)
{
func
interfacesFor
(
version
unversioned
.
GroupVersion
)
(
*
meta
.
VersionInterfaces
,
error
)
{
switch
version
{
switch
version
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment