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
303bcad3
Commit
303bcad3
authored
Nov 13, 2015
by
deads2k
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use groupversion in RESTMapping
parent
b675a772
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
19 changed files
with
175 additions
and
93 deletions
+175
-93
install_test.go
pkg/api/install/install_test.go
+8
-4
mapper.go
pkg/api/mapper.go
+16
-5
interfaces.go
pkg/api/meta/interfaces.go
+3
-4
restmapper.go
pkg/api/meta/restmapper.go
+59
-30
restmapper_test.go
pkg/api/meta/restmapper_test.go
+0
-0
group_version.go
pkg/api/unversioned/group_version.go
+21
-2
install_test.go
pkg/apis/componentconfig/install/install_test.go
+16
-7
install_test.go
pkg/apis/extensions/install/install_test.go
+10
-6
apiserver_test.go
pkg/apiserver/apiserver_test.go
+0
-0
watch_test.go
pkg/apiserver/watch_test.go
+4
-4
autoscale.go
pkg/kubectl/cmd/autoscale.go
+3
-3
cmd_test.go
pkg/kubectl/cmd/cmd_test.go
+12
-8
expose.go
pkg/kubectl/cmd/expose.go
+2
-2
get_test.go
pkg/kubectl/cmd/get_test.go
+4
-3
rollingupdate.go
pkg/kubectl/cmd/rollingupdate.go
+4
-2
factory.go
pkg/kubectl/cmd/util/factory.go
+9
-9
builder_test.go
pkg/kubectl/resource/builder_test.go
+1
-1
result.go
pkg/kubectl/resource/result.go
+1
-1
selector.go
pkg/kubectl/resource/selector.go
+2
-2
No files found.
pkg/api/install/install_test.go
View file @
303bcad3
...
@@ -78,12 +78,16 @@ func TestRESTMapper(t *testing.T) {
...
@@ -78,12 +78,16 @@ func TestRESTMapper(t *testing.T) {
t
.
Errorf
(
"unexpected version mapping: %s %s %v"
,
v
,
k
,
err
)
t
.
Errorf
(
"unexpected version mapping: %s %s %v"
,
v
,
k
,
err
)
}
}
if
m
,
err
:=
latest
.
GroupOrDie
(
""
)
.
RESTMapper
.
RESTMapping
(
"PodTemplate"
,
""
);
err
!=
nil
||
m
.
APIVersion
!=
"v1"
||
m
.
Resource
!=
"podtemplates"
{
expectedGroupVersion
:=
unversioned
.
GroupVersion
{
Version
:
"v1"
}
if
m
,
err
:=
latest
.
GroupOrDie
(
""
)
.
RESTMapper
.
RESTMapping
(
"PodTemplate"
,
""
);
err
!=
nil
||
m
.
GroupVersionKind
.
GroupVersion
()
!=
expectedGroupVersion
||
m
.
Resource
!=
"podtemplates"
{
t
.
Errorf
(
"unexpected version mapping: %#v %v"
,
m
,
err
)
t
.
Errorf
(
"unexpected version mapping: %#v %v"
,
m
,
err
)
}
}
for
_
,
version
:=
range
latest
.
GroupOrDie
(
""
)
.
Versions
{
for
_
,
version
:=
range
latest
.
GroupOrDie
(
""
)
.
Versions
{
mapping
,
err
:=
latest
.
GroupOrDie
(
""
)
.
RESTMapper
.
RESTMapping
(
"ReplicationController"
,
version
)
currGroupVersion
:=
unversioned
.
GroupVersion
{
Version
:
version
}
mapping
,
err
:=
latest
.
GroupOrDie
(
""
)
.
RESTMapper
.
RESTMapping
(
"ReplicationController"
,
currGroupVersion
.
String
())
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"unexpected error: %v"
,
err
)
t
.
Errorf
(
"unexpected error: %v"
,
err
)
}
}
...
@@ -91,11 +95,11 @@ func TestRESTMapper(t *testing.T) {
...
@@ -91,11 +95,11 @@ func TestRESTMapper(t *testing.T) {
if
mapping
.
Resource
!=
"replicationControllers"
&&
mapping
.
Resource
!=
"replicationcontrollers"
{
if
mapping
.
Resource
!=
"replicationControllers"
&&
mapping
.
Resource
!=
"replicationcontrollers"
{
t
.
Errorf
(
"incorrect resource name: %#v"
,
mapping
)
t
.
Errorf
(
"incorrect resource name: %#v"
,
mapping
)
}
}
if
mapping
.
APIVersion
!=
v
ersion
{
if
mapping
.
GroupVersionKind
.
GroupVersion
()
!=
currGroupV
ersion
{
t
.
Errorf
(
"incorrect version: %v"
,
mapping
)
t
.
Errorf
(
"incorrect version: %v"
,
mapping
)
}
}
interfaces
,
_
:=
latest
.
GroupOrDie
(
""
)
.
InterfacesFor
(
version
)
interfaces
,
_
:=
latest
.
GroupOrDie
(
""
)
.
InterfacesFor
(
currGroupVersion
.
String
()
)
if
mapping
.
Codec
!=
interfaces
.
Codec
{
if
mapping
.
Codec
!=
interfaces
.
Codec
{
t
.
Errorf
(
"unexpected codec: %#v, expected: %#v"
,
mapping
,
interfaces
)
t
.
Errorf
(
"unexpected codec: %#v, expected: %#v"
,
mapping
,
interfaces
)
}
}
...
...
pkg/api/mapper.go
View file @
303bcad3
...
@@ -17,9 +17,11 @@ limitations under the License.
...
@@ -17,9 +17,11 @@ limitations under the License.
package
api
package
api
import
(
import
(
"fmt"
"strings"
"strings"
"k8s.io/kubernetes/pkg/api/meta"
"k8s.io/kubernetes/pkg/api/meta"
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/util/sets"
"k8s.io/kubernetes/pkg/util/sets"
)
)
...
@@ -33,14 +35,23 @@ func RegisterRESTMapper(m meta.RESTMapper) {
...
@@ -33,14 +35,23 @@ func RegisterRESTMapper(m meta.RESTMapper) {
RESTMapper
=
append
(
RESTMapper
.
(
meta
.
MultiRESTMapper
),
m
)
RESTMapper
=
append
(
RESTMapper
.
(
meta
.
MultiRESTMapper
),
m
)
}
}
func
NewDefaultRESTMapper
(
group
string
,
version
s
[]
string
,
interfacesFunc
meta
.
VersionInterfacesFunc
,
func
NewDefaultRESTMapper
(
group
string
,
groupVersionString
s
[]
string
,
interfacesFunc
meta
.
VersionInterfacesFunc
,
importPathPrefix
string
,
ignoredKinds
,
rootScoped
sets
.
String
)
*
meta
.
DefaultRESTMapper
{
importPathPrefix
string
,
ignoredKinds
,
rootScoped
sets
.
String
)
*
meta
.
DefaultRESTMapper
{
mapper
:=
meta
.
NewDefaultRESTMapper
(
group
,
version
s
,
interfacesFunc
)
mapper
:=
meta
.
NewDefaultRESTMapper
(
group
,
groupVersionString
s
,
interfacesFunc
)
// enumerate all supported versions, get the kinds, and register with the mapper how to address
// enumerate all supported versions, get the kinds, and register with the mapper how to address
// our resources.
// our resources.
for
_
,
version
:=
range
versions
{
for
_
,
gvString
:=
range
groupVersionStrings
{
for
kind
,
oType
:=
range
Scheme
.
KnownTypes
(
version
)
{
gv
,
err
:=
unversioned
.
ParseGroupVersion
(
gvString
)
// TODO stop panicing when the types are fixed
if
err
!=
nil
{
panic
(
err
)
}
if
gv
.
Group
!=
group
{
panic
(
fmt
.
Sprintf
(
"%q does not match the expect %q"
,
gv
.
Group
,
group
))
}
for
kind
,
oType
:=
range
Scheme
.
KnownTypes
(
gv
.
String
())
{
// TODO: Remove import path prefix check.
// TODO: Remove import path prefix check.
// We check the import path prefix because we currently stuff both "api" and "extensions" objects
// We check the import path prefix because we currently stuff both "api" and "extensions" objects
// into the same group within Scheme since Scheme has no notion of groups yet.
// into the same group within Scheme since Scheme has no notion of groups yet.
...
@@ -51,7 +62,7 @@ func NewDefaultRESTMapper(group string, versions []string, interfacesFunc meta.V
...
@@ -51,7 +62,7 @@ func NewDefaultRESTMapper(group string, versions []string, interfacesFunc meta.V
if
rootScoped
.
Has
(
kind
)
{
if
rootScoped
.
Has
(
kind
)
{
scope
=
meta
.
RESTScopeRoot
scope
=
meta
.
RESTScopeRoot
}
}
mapper
.
Add
(
scope
,
kind
,
version
,
false
)
mapper
.
Add
(
scope
,
kind
,
gv
.
String
()
,
false
)
}
}
}
}
return
mapper
return
mapper
...
...
pkg/api/meta/interfaces.go
View file @
303bcad3
...
@@ -17,6 +17,7 @@ limitations under the License.
...
@@ -17,6 +17,7 @@ limitations under the License.
package
meta
package
meta
import
(
import
(
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/types"
"k8s.io/kubernetes/pkg/types"
)
)
...
@@ -124,10 +125,8 @@ type RESTScope interface {
...
@@ -124,10 +125,8 @@ type RESTScope interface {
type
RESTMapping
struct
{
type
RESTMapping
struct
{
// Resource is a string representing the name of this resource as a REST client would see it
// Resource is a string representing the name of this resource as a REST client would see it
Resource
string
Resource
string
// APIVersion represents the APIVersion that represents the resource as presented. It is provided
// for convenience for passing around a consistent mapping.
GroupVersionKind
unversioned
.
GroupVersionKind
APIVersion
string
Kind
string
// Scope contains the information needed to deal with REST Resources that are in a resource hierarchy
// Scope contains the information needed to deal with REST Resources that are in a resource hierarchy
Scope
RESTScope
Scope
RESTScope
...
...
pkg/api/meta/restmapper.go
View file @
303bcad3
...
@@ -20,6 +20,8 @@ package meta
...
@@ -20,6 +20,8 @@ package meta
import
(
import
(
"fmt"
"fmt"
"strings"
"strings"
"k8s.io/kubernetes/pkg/api/unversioned"
)
)
// Implements RESTScope interface
// Implements RESTScope interface
...
@@ -72,12 +74,12 @@ type typeMeta struct {
...
@@ -72,12 +74,12 @@ type typeMeta struct {
//
//
// TODO: Only accept plural for some operations for increased control?
// TODO: Only accept plural for some operations for increased control?
// (`get pod bar` vs `get pods bar`)
// (`get pod bar` vs `get pods bar`)
// TODO these maps should be keyed based on GroupVersionKinds
type
DefaultRESTMapper
struct
{
type
DefaultRESTMapper
struct
{
mapping
map
[
string
]
typeMeta
mapping
map
[
string
]
typeMeta
reverse
map
[
typeMeta
]
string
reverse
map
[
typeMeta
]
string
scopes
map
[
typeMeta
]
RESTScope
scopes
map
[
typeMeta
]
RESTScope
group
string
groupVersions
[]
unversioned
.
GroupVersion
versions
[]
string
plurals
map
[
string
]
string
plurals
map
[
string
]
string
singulars
map
[
string
]
string
singulars
map
[
string
]
string
interfacesFunc
VersionInterfacesFunc
interfacesFunc
VersionInterfacesFunc
...
@@ -92,7 +94,12 @@ type VersionInterfacesFunc func(apiVersion string) (*VersionInterfaces, error)
...
@@ -92,7 +94,12 @@ type VersionInterfacesFunc func(apiVersion string) (*VersionInterfaces, error)
// and the Kubernetes API conventions. Takes a group name, a priority list of the versions
// and the Kubernetes API conventions. Takes a group name, a priority list of the versions
// to search when an object has no default version (set empty to return an error),
// to search when an object has no default version (set empty to return an error),
// and a function that retrieves the correct codec and metadata for a given version.
// and a function that retrieves the correct codec and metadata for a given version.
func
NewDefaultRESTMapper
(
group
string
,
versions
[]
string
,
f
VersionInterfacesFunc
)
*
DefaultRESTMapper
{
// TODO remove group when this API is fixed. It is no longer used.
// The external API for a RESTMapper is cross-version and this is currently called using
// group/version tuples. In the end, the structure may be easier to understand with
// a GroupRESTMapper and CrossGroupRESTMapper, but for now, this one is constructed and
// used a CrossGroupRESTMapper.
func
NewDefaultRESTMapper
(
group
string
,
gvStrings
[]
string
,
f
VersionInterfacesFunc
)
*
DefaultRESTMapper
{
mapping
:=
make
(
map
[
string
]
typeMeta
)
mapping
:=
make
(
map
[
string
]
typeMeta
)
reverse
:=
make
(
map
[
typeMeta
]
string
)
reverse
:=
make
(
map
[
typeMeta
]
string
)
scopes
:=
make
(
map
[
typeMeta
]
RESTScope
)
scopes
:=
make
(
map
[
typeMeta
]
RESTScope
)
...
@@ -100,23 +107,29 @@ func NewDefaultRESTMapper(group string, versions []string, f VersionInterfacesFu
...
@@ -100,23 +107,29 @@ func NewDefaultRESTMapper(group string, versions []string, f VersionInterfacesFu
singulars
:=
make
(
map
[
string
]
string
)
singulars
:=
make
(
map
[
string
]
string
)
// TODO: verify name mappings work correctly when versions differ
// TODO: verify name mappings work correctly when versions differ
gvs
:=
[]
unversioned
.
GroupVersion
{}
for
_
,
gvString
:=
range
gvStrings
{
gvs
=
append
(
gvs
,
unversioned
.
ParseGroupVersionOrDie
(
gvString
))
}
return
&
DefaultRESTMapper
{
return
&
DefaultRESTMapper
{
mapping
:
mapping
,
mapping
:
mapping
,
reverse
:
reverse
,
reverse
:
reverse
,
scopes
:
scopes
,
scopes
:
scopes
,
group
:
group
,
groupVersions
:
gvs
,
versions
:
versions
,
plurals
:
plurals
,
plurals
:
plurals
,
singulars
:
singulars
,
singulars
:
singulars
,
interfacesFunc
:
f
,
interfacesFunc
:
f
,
}
}
}
}
func
(
m
*
DefaultRESTMapper
)
Add
(
scope
RESTScope
,
kind
string
,
version
string
,
mixedCase
bool
)
{
func
(
m
*
DefaultRESTMapper
)
Add
(
scope
RESTScope
,
kind
string
,
gvString
string
,
mixedCase
bool
)
{
gv
:=
unversioned
.
ParseGroupVersionOrDie
(
gvString
)
plural
,
singular
:=
KindToResource
(
kind
,
mixedCase
)
plural
,
singular
:=
KindToResource
(
kind
,
mixedCase
)
m
.
plurals
[
singular
]
=
plural
m
.
plurals
[
singular
]
=
plural
m
.
singulars
[
plural
]
=
singular
m
.
singulars
[
plural
]
=
singular
meta
:=
typeMeta
{
APIVersion
:
version
,
Kind
:
kind
}
meta
:=
typeMeta
{
APIVersion
:
gv
.
String
()
,
Kind
:
kind
}
_
,
ok1
:=
m
.
mapping
[
plural
]
_
,
ok1
:=
m
.
mapping
[
plural
]
_
,
ok2
:=
m
.
mapping
[
strings
.
ToLower
(
plural
)]
_
,
ok2
:=
m
.
mapping
[
strings
.
ToLower
(
plural
)]
if
!
ok1
&&
!
ok2
{
if
!
ok1
&&
!
ok2
{
...
@@ -177,73 +190,89 @@ func (m *DefaultRESTMapper) VersionAndKindForResource(resource string) (defaultV
...
@@ -177,73 +190,89 @@ func (m *DefaultRESTMapper) VersionAndKindForResource(resource string) (defaultV
}
}
func
(
m
*
DefaultRESTMapper
)
GroupForResource
(
resource
string
)
(
string
,
error
)
{
func
(
m
*
DefaultRESTMapper
)
GroupForResource
(
resource
string
)
(
string
,
error
)
{
if
_
,
ok
:=
m
.
mapping
[
strings
.
ToLower
(
resource
)];
!
ok
{
typemeta
,
exists
:=
m
.
mapping
[
strings
.
ToLower
(
resource
)]
if
!
exists
{
return
""
,
fmt
.
Errorf
(
"in group for resource, no resource %q has been defined"
,
resource
)
return
""
,
fmt
.
Errorf
(
"in group for resource, no resource %q has been defined"
,
resource
)
}
}
return
m
.
group
,
nil
gv
,
err
:=
unversioned
.
ParseGroupVersion
(
typemeta
.
APIVersion
)
if
err
!=
nil
{
return
""
,
err
}
return
gv
.
Group
,
nil
}
}
// RESTMapping returns a struct representing the resource path and conversion interfaces a
// RESTMapping returns a struct representing the resource path and conversion interfaces a
// RESTClient should use to operate on the provided kind in order of versions. If a version search
// RESTClient should use to operate on the provided kind in order of versions. If a version search
// order is not provided, the search order provided to DefaultRESTMapper will be used to resolve which
// order is not provided, the search order provided to DefaultRESTMapper will be used to resolve which
// APIVersion should be used to access the named kind.
// APIVersion should be used to access the named kind.
// TODO version here in this RESTMapper means just APIVersion, but the RESTMapper API is intended to handle multiple groups
// So this API is broken. The RESTMapper test made it clear that versions here were API versions, but the code tries to use
// them with group/version tuples.
// TODO this should probably become RESTMapping(GroupKind, versions ...string)
func
(
m
*
DefaultRESTMapper
)
RESTMapping
(
kind
string
,
versions
...
string
)
(
*
RESTMapping
,
error
)
{
func
(
m
*
DefaultRESTMapper
)
RESTMapping
(
kind
string
,
versions
...
string
)
(
*
RESTMapping
,
error
)
{
// Pick an appropriate version
// Pick an appropriate version
var
version
string
var
groupVersion
*
unversioned
.
GroupVersion
hadVersion
:=
false
hadVersion
:=
false
for
_
,
v
:=
range
versions
{
for
_
,
v
:=
range
versions
{
if
len
(
v
)
==
0
{
if
len
(
v
)
==
0
{
continue
continue
}
}
currGroupVersion
,
err
:=
unversioned
.
ParseGroupVersion
(
v
)
if
err
!=
nil
{
return
nil
,
err
}
hadVersion
=
true
hadVersion
=
true
if
_
,
ok
:=
m
.
reverse
[
typeMeta
{
APIVersion
:
v
,
Kind
:
kind
}];
ok
{
if
_
,
ok
:=
m
.
reverse
[
typeMeta
{
APIVersion
:
currGroupVersion
.
String
()
,
Kind
:
kind
}];
ok
{
version
=
v
groupVersion
=
&
currGroupVersion
break
break
}
}
}
}
// Use the default preferred versions
// Use the default preferred versions
if
!
hadVersion
&&
len
(
version
)
==
0
{
if
!
hadVersion
&&
(
groupVersion
==
nil
)
{
for
_
,
v
:=
range
m
.
v
ersions
{
for
_
,
currGroupVersion
:=
range
m
.
groupV
ersions
{
if
_
,
ok
:=
m
.
reverse
[
typeMeta
{
APIVersion
:
v
,
Kind
:
kind
}];
ok
{
if
_
,
ok
:=
m
.
reverse
[
typeMeta
{
APIVersion
:
currGroupVersion
.
String
()
,
Kind
:
kind
}];
ok
{
version
=
v
groupVersion
=
&
currGroupVersion
break
break
}
}
}
}
}
}
if
len
(
version
)
==
0
{
if
groupVersion
==
nil
{
return
nil
,
fmt
.
Errorf
(
"no kind named %q is registered in versions %q"
,
kind
,
versions
)
return
nil
,
fmt
.
Errorf
(
"no kind named %q is registered in versions %q"
,
kind
,
versions
)
}
}
gvk
:=
unversioned
.
NewGroupVersionKind
(
*
groupVersion
,
kind
)
// Ensure we have a REST mapping
// Ensure we have a REST mapping
resource
,
ok
:=
m
.
reverse
[
typeMeta
{
APIVersion
:
version
,
Kind
:
k
ind
}]
resource
,
ok
:=
m
.
reverse
[
typeMeta
{
APIVersion
:
gvk
.
GroupVersion
()
.
String
(),
Kind
:
gvk
.
K
ind
}]
if
!
ok
{
if
!
ok
{
found
:=
[]
string
{}
found
:=
[]
unversioned
.
GroupVersion
{}
for
_
,
v
:=
range
m
.
v
ersions
{
for
_
,
gv
:=
range
m
.
groupV
ersions
{
if
_
,
ok
:=
m
.
reverse
[
typeMeta
{
APIVersion
:
v
,
Kind
:
kind
}];
ok
{
if
_
,
ok
:=
m
.
reverse
[
typeMeta
{
APIVersion
:
gv
.
String
()
,
Kind
:
kind
}];
ok
{
found
=
append
(
found
,
v
)
found
=
append
(
found
,
g
v
)
}
}
}
}
if
len
(
found
)
>
0
{
if
len
(
found
)
>
0
{
return
nil
,
fmt
.
Errorf
(
"object with kind %q exists in versions %
q, not %q"
,
kind
,
strings
.
Join
(
found
,
", "
),
v
ersion
)
return
nil
,
fmt
.
Errorf
(
"object with kind %q exists in versions %
v, not %v"
,
kind
,
found
,
*
groupV
ersion
)
}
}
return
nil
,
fmt
.
Errorf
(
"the provided version %q and kind %q cannot be mapped to a supported object"
,
v
ersion
,
kind
)
return
nil
,
fmt
.
Errorf
(
"the provided version %q and kind %q cannot be mapped to a supported object"
,
groupV
ersion
,
kind
)
}
}
// Ensure we have a REST scope
// Ensure we have a REST scope
scope
,
ok
:=
m
.
scopes
[
typeMeta
{
APIVersion
:
version
,
Kind
:
k
ind
}]
scope
,
ok
:=
m
.
scopes
[
typeMeta
{
APIVersion
:
gvk
.
GroupVersion
()
.
String
(),
Kind
:
gvk
.
K
ind
}]
if
!
ok
{
if
!
ok
{
return
nil
,
fmt
.
Errorf
(
"the provided version %q and kind %q cannot be mapped to a supported scope"
,
version
,
k
ind
)
return
nil
,
fmt
.
Errorf
(
"the provided version %q and kind %q cannot be mapped to a supported scope"
,
gvk
.
GroupVersion
()
.
String
(),
gvk
.
K
ind
)
}
}
interfaces
,
err
:=
m
.
interfacesFunc
(
version
)
interfaces
,
err
:=
m
.
interfacesFunc
(
gvk
.
GroupVersion
()
.
String
()
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"the provided version %q has no relevant versions"
,
version
)
return
nil
,
fmt
.
Errorf
(
"the provided version %q has no relevant versions"
,
gvk
.
GroupVersion
()
.
String
()
)
}
}
retVal
:=
&
RESTMapping
{
retVal
:=
&
RESTMapping
{
Resource
:
resource
,
Resource
:
resource
,
APIVersion
:
version
,
GroupVersionKind
:
gvk
,
Kind
:
kind
,
Scope
:
scope
,
Scope
:
scope
,
Codec
:
interfaces
.
Codec
,
Codec
:
interfaces
.
Codec
,
...
...
pkg/api/meta/restmapper_test.go
View file @
303bcad3
This diff is collapsed.
Click to expand it.
pkg/api/unversioned/group_version.go
View file @
303bcad3
...
@@ -22,7 +22,26 @@ import (
...
@@ -22,7 +22,26 @@ import (
"strings"
"strings"
)
)
// TODO: We need to remove the GroupVersion in types.go. We use the name GroupVersion here temporarily.
// GroupVersionKind unambiguously identifies a kind. It doesn't anonymously include GroupVersion
// to avoid automatic coersion. It doesn't use a GroupVersion to avoid custom marshalling
type
GroupVersionKind
struct
{
Group
string
Version
string
Kind
string
}
func
NewGroupVersionKind
(
gv
GroupVersion
,
kind
string
)
GroupVersionKind
{
return
GroupVersionKind
{
Group
:
gv
.
Group
,
Version
:
gv
.
Version
,
Kind
:
kind
}
}
func
(
gvk
GroupVersionKind
)
GroupVersion
()
GroupVersion
{
return
GroupVersion
{
Group
:
gvk
.
Group
,
Version
:
gvk
.
Version
}
}
func
(
gvk
*
GroupVersionKind
)
String
()
string
{
return
gvk
.
Group
+
"/"
+
gvk
.
Version
+
", Kind="
+
gvk
.
Kind
}
// GroupVersion contains the "group" and the "version", which uniquely identifies the API.
// GroupVersion contains the "group" and the "version", which uniquely identifies the API.
type
GroupVersion
struct
{
type
GroupVersion
struct
{
Group
string
Group
string
...
@@ -31,7 +50,7 @@ type GroupVersion struct {
...
@@ -31,7 +50,7 @@ type GroupVersion struct {
// String puts "group" and "version" into a single "group/version" string. For the legacy v1
// String puts "group" and "version" into a single "group/version" string. For the legacy v1
// it returns "v1".
// it returns "v1".
func
(
gv
*
GroupVersion
)
String
()
string
{
func
(
gv
GroupVersion
)
String
()
string
{
// special case of "v1" for backward compatibility
// special case of "v1" for backward compatibility
if
gv
.
Group
==
""
&&
gv
.
Version
==
"v1"
{
if
gv
.
Group
==
""
&&
gv
.
Version
==
"v1"
{
return
gv
.
Version
return
gv
.
Version
...
...
pkg/apis/componentconfig/install/install_test.go
View file @
303bcad3
...
@@ -21,6 +21,7 @@ import (
...
@@ -21,6 +21,7 @@ import (
"testing"
"testing"
"k8s.io/kubernetes/pkg/api/latest"
"k8s.io/kubernetes/pkg/api/latest"
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/apis/componentconfig"
"k8s.io/kubernetes/pkg/apis/componentconfig"
)
)
...
@@ -53,28 +54,36 @@ func TestInterfacesFor(t *testing.T) {
...
@@ -53,28 +54,36 @@ func TestInterfacesFor(t *testing.T) {
}
}
func
TestRESTMapper
(
t
*
testing
.
T
)
{
func
TestRESTMapper
(
t
*
testing
.
T
)
{
if
v
,
k
,
err
:=
latest
.
GroupOrDie
(
"componentconfig"
)
.
RESTMapper
.
VersionAndKindForResource
(
"kubeproxyconfiguration"
);
err
!=
nil
||
v
!=
"componentconfig/v1alpha1"
||
k
!=
"KubeProxyConfiguration"
{
expectedGroupVersion
:=
unversioned
.
GroupVersion
{
Group
:
"componentconfig"
,
Version
:
"v1alpha1"
}
t
.
Errorf
(
"unexpected version mapping: %s %s %v"
,
v
,
k
,
err
)
if
v
,
k
,
err
:=
latest
.
GroupOrDie
(
"componentconfig"
)
.
RESTMapper
.
VersionAndKindForResource
(
"kubeproxyconfiguration"
);
err
!=
nil
||
v
!=
expectedGroupVersion
.
String
()
||
k
!=
"KubeProxyConfiguration"
{
t
.
Errorf
(
"unexpected version mapping: %q %q %v"
,
v
,
k
,
err
)
}
}
if
m
,
err
:=
latest
.
GroupOrDie
(
"componentconfig"
)
.
RESTMapper
.
RESTMapping
(
"KubeProxyConfiguration"
,
""
);
err
!=
nil
||
m
.
APIVersion
!=
"componentconfig/v1alpha1"
||
m
.
Resource
!=
"kubeproxyconfigurations"
{
if
m
,
err
:=
latest
.
GroupOrDie
(
"componentconfig"
)
.
RESTMapper
.
RESTMapping
(
"KubeProxyConfiguration"
,
""
);
err
!=
nil
||
m
.
GroupVersionKind
.
GroupVersion
()
!=
expectedGroupVersion
||
m
.
Resource
!=
"kubeproxyconfigurations"
{
t
.
Errorf
(
"unexpected version mapping: %#v %v"
,
m
,
err
)
t
.
Errorf
(
"unexpected version mapping: %#v %v"
,
m
,
err
)
}
}
for
_
,
groupVersion
:=
range
latest
.
GroupOrDie
(
"componentconfig"
)
.
GroupVersions
{
for
_
,
groupVersionString
:=
range
latest
.
GroupOrDie
(
"componentconfig"
)
.
GroupVersions
{
mapping
,
err
:=
latest
.
GroupOrDie
(
"componentconfig"
)
.
RESTMapper
.
RESTMapping
(
"KubeProxyConfiguration"
,
groupVersion
)
gv
,
err
:=
unversioned
.
ParseGroupVersion
(
groupVersionString
)
if
err
!=
nil
{
t
.
Errorf
(
"unexpected error: %v"
,
err
)
continue
}
mapping
,
err
:=
latest
.
GroupOrDie
(
"componentconfig"
)
.
RESTMapper
.
RESTMapping
(
"KubeProxyConfiguration"
,
gv
.
String
())
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"unexpected error: %v"
,
err
)
t
.
Errorf
(
"unexpected error: %v"
,
err
)
continue
}
}
if
mapping
.
Resource
!=
"kubeproxyconfigurations"
{
if
mapping
.
Resource
!=
"kubeproxyconfigurations"
{
t
.
Errorf
(
"incorrect resource name: %#v"
,
mapping
)
t
.
Errorf
(
"incorrect resource name: %#v"
,
mapping
)
}
}
if
mapping
.
APIVersion
!=
groupVersion
{
if
mapping
.
GroupVersionKind
.
GroupVersion
()
!=
gv
{
t
.
Errorf
(
"incorrect groupVersion: %v"
,
mapping
)
t
.
Errorf
(
"incorrect groupVersion: %v"
,
mapping
)
}
}
interfaces
,
_
:=
latest
.
GroupOrDie
(
"componentconfig"
)
.
InterfacesFor
(
g
roupVersion
)
interfaces
,
_
:=
latest
.
GroupOrDie
(
"componentconfig"
)
.
InterfacesFor
(
g
v
.
String
()
)
if
mapping
.
Codec
!=
interfaces
.
Codec
{
if
mapping
.
Codec
!=
interfaces
.
Codec
{
t
.
Errorf
(
"unexpected codec: %#v, expected: %#v"
,
mapping
,
interfaces
)
t
.
Errorf
(
"unexpected codec: %#v, expected: %#v"
,
mapping
,
interfaces
)
}
}
...
...
pkg/apis/extensions/install/install_test.go
View file @
303bcad3
...
@@ -75,16 +75,20 @@ func TestInterfacesFor(t *testing.T) {
...
@@ -75,16 +75,20 @@ func TestInterfacesFor(t *testing.T) {
}
}
func
TestRESTMapper
(
t
*
testing
.
T
)
{
func
TestRESTMapper
(
t
*
testing
.
T
)
{
if
v
,
k
,
err
:=
latest
.
GroupOrDie
(
"extensions"
)
.
RESTMapper
.
VersionAndKindForResource
(
"horizontalpodautoscalers"
);
err
!=
nil
||
v
!=
"extensions/v1beta1"
||
k
!=
"HorizontalPodAutoscaler"
{
expectedGroupVersion
:=
unversioned
.
GroupVersion
{
Group
:
"extensions"
,
Version
:
"v1beta1"
}
if
v
,
k
,
err
:=
latest
.
GroupOrDie
(
"extensions"
)
.
RESTMapper
.
VersionAndKindForResource
(
"horizontalpodautoscalers"
);
err
!=
nil
||
v
!=
expectedGroupVersion
.
String
()
||
k
!=
"HorizontalPodAutoscaler"
{
t
.
Errorf
(
"unexpected version mapping: %s %s %v"
,
v
,
k
,
err
)
t
.
Errorf
(
"unexpected version mapping: %s %s %v"
,
v
,
k
,
err
)
}
}
if
m
,
err
:=
latest
.
GroupOrDie
(
"extensions"
)
.
RESTMapper
.
RESTMapping
(
"DaemonSet"
,
""
);
err
!=
nil
||
m
.
APIVersion
!=
"extensions/v1beta1"
||
m
.
Resource
!=
"daemonsets"
{
if
m
,
err
:=
latest
.
GroupOrDie
(
"extensions"
)
.
RESTMapper
.
RESTMapping
(
"DaemonSet"
,
""
);
err
!=
nil
||
m
.
GroupVersionKind
.
GroupVersion
()
!=
expectedGroupVersion
||
m
.
Resource
!=
"daemonsets"
{
t
.
Errorf
(
"unexpected version mapping: %#v %v"
,
m
,
err
)
t
.
Errorf
(
"unexpected version mapping: %#v %v"
,
m
,
err
)
}
}
for
_
,
groupVersion
:=
range
latest
.
GroupOrDie
(
"extensions"
)
.
GroupVersions
{
for
_
,
groupVersionString
:=
range
latest
.
GroupOrDie
(
"extensions"
)
.
GroupVersions
{
mapping
,
err
:=
latest
.
GroupOrDie
(
"extensions"
)
.
RESTMapper
.
RESTMapping
(
"HorizontalPodAutoscaler"
,
groupVersion
)
gv
,
err
:=
unversioned
.
ParseGroupVersion
(
groupVersionString
)
mapping
,
err
:=
latest
.
GroupOrDie
(
"extensions"
)
.
RESTMapper
.
RESTMapping
(
"HorizontalPodAutoscaler"
,
gv
.
String
())
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"unexpected error: %v"
,
err
)
t
.
Errorf
(
"unexpected error: %v"
,
err
)
}
}
...
@@ -92,11 +96,11 @@ func TestRESTMapper(t *testing.T) {
...
@@ -92,11 +96,11 @@ func TestRESTMapper(t *testing.T) {
if
mapping
.
Resource
!=
"horizontalpodautoscalers"
{
if
mapping
.
Resource
!=
"horizontalpodautoscalers"
{
t
.
Errorf
(
"incorrect resource name: %#v"
,
mapping
)
t
.
Errorf
(
"incorrect resource name: %#v"
,
mapping
)
}
}
if
mapping
.
APIVersion
!=
groupVersion
{
if
mapping
.
GroupVersionKind
.
GroupVersion
()
!=
gv
{
t
.
Errorf
(
"incorrect groupVersion: %v"
,
mapping
)
t
.
Errorf
(
"incorrect groupVersion: %v"
,
mapping
)
}
}
interfaces
,
_
:=
latest
.
GroupOrDie
(
"extensions"
)
.
InterfacesFor
(
g
roupVersion
)
interfaces
,
_
:=
latest
.
GroupOrDie
(
"extensions"
)
.
InterfacesFor
(
g
v
.
String
()
)
if
mapping
.
Codec
!=
interfaces
.
Codec
{
if
mapping
.
Codec
!=
interfaces
.
Codec
{
t
.
Errorf
(
"unexpected codec: %#v, expected: %#v"
,
mapping
,
interfaces
)
t
.
Errorf
(
"unexpected codec: %#v, expected: %#v"
,
mapping
,
interfaces
)
}
}
...
...
pkg/apiserver/apiserver_test.go
View file @
303bcad3
This diff is collapsed.
Click to expand it.
pkg/apiserver/watch_test.go
View file @
303bcad3
...
@@ -178,8 +178,8 @@ func TestWatchParamParsing(t *testing.T) {
...
@@ -178,8 +178,8 @@ func TestWatchParamParsing(t *testing.T) {
dest
,
_
:=
url
.
Parse
(
server
.
URL
)
dest
,
_
:=
url
.
Parse
(
server
.
URL
)
rootPath
:=
"/"
+
prefix
+
"/"
+
testVersion
+
"/watch/simples"
rootPath
:=
"/"
+
prefix
+
"/"
+
test
GroupVersion
.
Group
+
"/"
+
testGroupVersion
.
Version
+
"/watch/simples"
namespacedPath
:=
"/"
+
prefix
+
"/"
+
testVersion
+
"/watch/namespaces/other/simpleroots"
namespacedPath
:=
"/"
+
prefix
+
"/"
+
test
GroupVersion
.
Group
+
"/"
+
testGroupVersion
.
Version
+
"/watch/namespaces/other/simpleroots"
table
:=
[]
struct
{
table
:=
[]
struct
{
path
string
path
string
...
@@ -358,13 +358,13 @@ func TestWatchHTTPTimeout(t *testing.T) {
...
@@ -358,13 +358,13 @@ func TestWatchHTTPTimeout(t *testing.T) {
// Setup a client
// Setup a client
dest
,
_
:=
url
.
Parse
(
s
.
URL
)
dest
,
_
:=
url
.
Parse
(
s
.
URL
)
dest
.
Path
=
"/"
+
prefix
+
"/"
+
newVersion
+
"/simple"
dest
.
Path
=
"/"
+
prefix
+
"/"
+
new
GroupVersion
.
Group
+
"/"
+
newGroupVersion
.
Version
+
"/simple"
dest
.
RawQuery
=
"watch=true"
dest
.
RawQuery
=
"watch=true"
req
,
_
:=
http
.
NewRequest
(
"GET"
,
dest
.
String
(),
nil
)
req
,
_
:=
http
.
NewRequest
(
"GET"
,
dest
.
String
(),
nil
)
client
:=
http
.
Client
{}
client
:=
http
.
Client
{}
resp
,
err
:=
client
.
Do
(
req
)
resp
,
err
:=
client
.
Do
(
req
)
watcher
.
Add
(
&
apiservertesting
.
Simple
{
TypeMeta
:
unversioned
.
TypeMeta
{
APIVersion
:
new
Version
}})
watcher
.
Add
(
&
apiservertesting
.
Simple
{
TypeMeta
:
unversioned
.
TypeMeta
{
APIVersion
:
new
GroupVersion
.
String
()
}})
// Make sure we can actually watch an endpoint
// Make sure we can actually watch an endpoint
decoder
:=
json
.
NewDecoder
(
resp
.
Body
)
decoder
:=
json
.
NewDecoder
(
resp
.
Body
)
...
...
pkg/kubectl/cmd/autoscale.go
View file @
303bcad3
...
@@ -96,7 +96,7 @@ func RunAutoscale(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []
...
@@ -96,7 +96,7 @@ func RunAutoscale(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []
}
}
info
:=
infos
[
0
]
info
:=
infos
[
0
]
mapping
:=
info
.
ResourceMapping
()
mapping
:=
info
.
ResourceMapping
()
if
err
:=
f
.
CanBeAutoscaled
(
mapping
.
Kind
);
err
!=
nil
{
if
err
:=
f
.
CanBeAutoscaled
(
mapping
.
GroupVersionKind
.
Kind
);
err
!=
nil
{
return
err
return
err
}
}
...
@@ -111,9 +111,9 @@ func RunAutoscale(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []
...
@@ -111,9 +111,9 @@ func RunAutoscale(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []
name
:=
info
.
Name
name
:=
info
.
Name
params
[
"default-name"
]
=
name
params
[
"default-name"
]
=
name
params
[
"scaleRef-kind"
]
=
mapping
.
Kind
params
[
"scaleRef-kind"
]
=
mapping
.
GroupVersionKind
.
Kind
params
[
"scaleRef-name"
]
=
name
params
[
"scaleRef-name"
]
=
name
params
[
"scaleRef-apiVersion"
]
=
mapping
.
APIVersion
params
[
"scaleRef-apiVersion"
]
=
mapping
.
GroupVersionKind
.
GroupVersion
()
.
String
()
if
err
=
kubectl
.
ValidateParams
(
names
,
params
);
err
!=
nil
{
if
err
=
kubectl
.
ValidateParams
(
names
,
params
);
err
!=
nil
{
return
err
return
err
...
...
pkg/kubectl/cmd/cmd_test.go
View file @
303bcad3
...
@@ -76,23 +76,27 @@ func versionErrIfFalse(b bool) error {
...
@@ -76,23 +76,27 @@ func versionErrIfFalse(b bool) error {
return
versionErr
return
versionErr
}
}
var
validVersion
=
testapi
.
Default
.
Version
()
var
internalGV
=
unversioned
.
GroupVersion
{
Group
:
"apitest"
,
Version
:
""
}
var
unlikelyGV
=
unversioned
.
GroupVersion
{
Group
:
"apitest"
,
Version
:
"unlikelyversion"
}
var
validVersionGV
=
unversioned
.
GroupVersion
{
Group
:
"apitest"
,
Version
:
validVersion
}
func
newExternalScheme
()
(
*
runtime
.
Scheme
,
meta
.
RESTMapper
,
runtime
.
Codec
)
{
func
newExternalScheme
()
(
*
runtime
.
Scheme
,
meta
.
RESTMapper
,
runtime
.
Codec
)
{
scheme
:=
runtime
.
NewScheme
()
scheme
:=
runtime
.
NewScheme
()
scheme
.
AddKnownTypeWithName
(
""
,
"Type"
,
&
internalType
{})
scheme
.
AddKnownTypeWithName
(
internalGV
.
Version
,
"Type"
,
&
internalType
{})
scheme
.
AddKnownTypeWithName
(
"unlikelyversion"
,
"Type"
,
&
externalType
{})
scheme
.
AddKnownTypeWithName
(
unlikelyGV
.
String
()
,
"Type"
,
&
externalType
{})
//This tests that kubectl will not confuse the external scheme with the internal scheme, even when they accidentally have versions of the same name.
//This tests that kubectl will not confuse the external scheme with the internal scheme, even when they accidentally have versions of the same name.
scheme
.
AddKnownTypeWithName
(
testapi
.
Default
.
Version
(),
"Type"
,
&
ExternalType2
{})
scheme
.
AddKnownTypeWithName
(
validVersionGV
.
String
(),
"Type"
,
&
ExternalType2
{})
codec
:=
runtime
.
CodecFor
(
scheme
,
"unlikelyversion"
)
codec
:=
runtime
.
CodecFor
(
scheme
,
unlikelyGV
.
String
())
validVersion
:=
testapi
.
Default
.
Version
()
mapper
:=
meta
.
NewDefaultRESTMapper
(
"apitest"
,
[]
string
{
unlikelyGV
.
String
(),
validVersionGV
.
String
()},
func
(
version
string
)
(
*
meta
.
VersionInterfaces
,
error
)
{
mapper
:=
meta
.
NewDefaultRESTMapper
(
"apitest"
,
[]
string
{
"unlikelyversion"
,
validVersion
},
func
(
version
string
)
(
*
meta
.
VersionInterfaces
,
error
)
{
return
&
meta
.
VersionInterfaces
{
return
&
meta
.
VersionInterfaces
{
Codec
:
runtime
.
CodecFor
(
scheme
,
version
),
Codec
:
runtime
.
CodecFor
(
scheme
,
version
),
ObjectConvertor
:
scheme
,
ObjectConvertor
:
scheme
,
MetadataAccessor
:
meta
.
NewAccessor
(),
MetadataAccessor
:
meta
.
NewAccessor
(),
},
versionErrIfFalse
(
version
==
validVersion
||
version
==
"unlikelyversion"
)
},
versionErrIfFalse
(
version
==
validVersion
GV
.
String
()
||
version
==
unlikelyGV
.
String
()
)
})
})
for
_
,
version
:=
range
[]
string
{
"unlikelyversion"
,
validVersion
}
{
for
_
,
version
:=
range
[]
string
{
unlikelyGV
.
String
(),
validVersionGV
.
String
()
}
{
for
kind
:=
range
scheme
.
KnownTypes
(
version
)
{
for
kind
:=
range
scheme
.
KnownTypes
(
version
)
{
mixedCase
:=
false
mixedCase
:=
false
scope
:=
meta
.
RESTScopeNamespace
scope
:=
meta
.
RESTScopeNamespace
...
...
pkg/kubectl/cmd/expose.go
View file @
303bcad3
...
@@ -120,7 +120,7 @@ func RunExpose(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []str
...
@@ -120,7 +120,7 @@ func RunExpose(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []str
}
}
info
:=
infos
[
0
]
info
:=
infos
[
0
]
mapping
:=
info
.
ResourceMapping
()
mapping
:=
info
.
ResourceMapping
()
if
err
:=
f
.
CanBeExposed
(
mapping
.
Kind
);
err
!=
nil
{
if
err
:=
f
.
CanBeExposed
(
mapping
.
GroupVersionKind
.
Kind
);
err
!=
nil
{
return
err
return
err
}
}
// Get the input object
// Get the input object
...
@@ -187,7 +187,7 @@ func RunExpose(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []str
...
@@ -187,7 +187,7 @@ func RunExpose(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []str
}
}
if
inline
:=
cmdutil
.
GetFlagString
(
cmd
,
"overrides"
);
len
(
inline
)
>
0
{
if
inline
:=
cmdutil
.
GetFlagString
(
cmd
,
"overrides"
);
len
(
inline
)
>
0
{
object
,
err
=
cmdutil
.
Merge
(
object
,
inline
,
mapping
.
Kind
)
object
,
err
=
cmdutil
.
Merge
(
object
,
inline
,
mapping
.
GroupVersionKind
.
Kind
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
...
pkg/kubectl/cmd/get_test.go
View file @
303bcad3
...
@@ -159,19 +159,19 @@ func TestGetUnknownSchemaObjectListGeneric(t *testing.T) {
...
@@ -159,19 +159,19 @@ func TestGetUnknownSchemaObjectListGeneric(t *testing.T) {
"handles specific version"
:
{
"handles specific version"
:
{
outputVersion
:
testapi
.
Default
.
Version
(),
outputVersion
:
testapi
.
Default
.
Version
(),
listVersion
:
testapi
.
Default
.
Version
(),
listVersion
:
testapi
.
Default
.
Version
(),
testtypeVersion
:
"unlikelyversion"
,
testtypeVersion
:
unlikelyGV
.
String
()
,
rcVersion
:
testapi
.
Default
.
Version
(),
rcVersion
:
testapi
.
Default
.
Version
(),
},
},
"handles second specific version"
:
{
"handles second specific version"
:
{
outputVersion
:
"unlikelyversion"
,
outputVersion
:
"unlikelyversion"
,
listVersion
:
testapi
.
Default
.
Version
(),
listVersion
:
testapi
.
Default
.
Version
(),
testtypeVersion
:
"unlikelyversion"
,
testtypeVersion
:
unlikelyGV
.
String
()
,
rcVersion
:
testapi
.
Default
.
Version
(),
// see expected behavior 3b
rcVersion
:
testapi
.
Default
.
Version
(),
// see expected behavior 3b
},
},
"handles common version"
:
{
"handles common version"
:
{
outputVersion
:
testapi
.
Default
.
Version
(),
outputVersion
:
testapi
.
Default
.
Version
(),
listVersion
:
testapi
.
Default
.
Version
(),
listVersion
:
testapi
.
Default
.
Version
(),
testtypeVersion
:
"unlikelyversion"
,
testtypeVersion
:
unlikelyGV
.
String
()
,
rcVersion
:
testapi
.
Default
.
Version
(),
rcVersion
:
testapi
.
Default
.
Version
(),
},
},
}
}
...
@@ -198,6 +198,7 @@ func TestGetUnknownSchemaObjectListGeneric(t *testing.T) {
...
@@ -198,6 +198,7 @@ func TestGetUnknownSchemaObjectListGeneric(t *testing.T) {
cmd
:=
NewCmdGet
(
f
,
buf
)
cmd
:=
NewCmdGet
(
f
,
buf
)
cmd
.
SetOutput
(
buf
)
cmd
.
SetOutput
(
buf
)
cmd
.
Flags
()
.
Set
(
"output"
,
"json"
)
cmd
.
Flags
()
.
Set
(
"output"
,
"json"
)
cmd
.
Flags
()
.
Set
(
"output-version"
,
test
.
outputVersion
)
cmd
.
Flags
()
.
Set
(
"output-version"
,
test
.
outputVersion
)
err
:=
RunGet
(
f
,
buf
,
cmd
,
[]
string
{
"type/foo"
,
"replicationcontrollers/foo"
},
&
GetOptions
{})
err
:=
RunGet
(
f
,
buf
,
cmd
,
[]
string
{
"type/foo"
,
"replicationcontrollers/foo"
},
&
GetOptions
{})
if
err
!=
nil
{
if
err
!=
nil
{
...
...
pkg/kubectl/cmd/rollingupdate.go
View file @
303bcad3
...
@@ -29,6 +29,7 @@ import (
...
@@ -29,6 +29,7 @@ import (
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/errors"
"k8s.io/kubernetes/pkg/api/errors"
"k8s.io/kubernetes/pkg/api/meta"
"k8s.io/kubernetes/pkg/api/meta"
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/api/v1"
"k8s.io/kubernetes/pkg/api/v1"
"k8s.io/kubernetes/pkg/kubectl"
"k8s.io/kubernetes/pkg/kubectl"
cmdutil
"k8s.io/kubernetes/pkg/kubectl/cmd/util"
cmdutil
"k8s.io/kubernetes/pkg/kubectl/cmd/util"
...
@@ -382,8 +383,9 @@ func isReplicasDefaulted(info *resource.Info) bool {
...
@@ -382,8 +383,9 @@ func isReplicasDefaulted(info *resource.Info) bool {
// was unable to recover versioned info
// was unable to recover versioned info
return
false
return
false
}
}
switch
info
.
Mapping
.
APIVersion
{
case
"v1"
:
switch
info
.
Mapping
.
GroupVersionKind
.
GroupVersion
()
{
case
unversioned
.
GroupVersion
{
Version
:
"v1"
}
:
if
rc
,
ok
:=
info
.
VersionedObject
.
(
*
v1
.
ReplicationController
);
ok
{
if
rc
,
ok
:=
info
.
VersionedObject
.
(
*
v1
.
ReplicationController
);
ok
{
return
rc
.
Spec
.
Replicas
==
nil
return
rc
.
Spec
.
Replicas
==
nil
}
}
...
...
pkg/kubectl/cmd/util/factory.go
View file @
303bcad3
...
@@ -148,7 +148,7 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
...
@@ -148,7 +148,7 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
client
,
err
:=
clients
.
ClientForVersion
(
mapping
.
APIVersion
)
client
,
err
:=
clients
.
ClientForVersion
(
mapping
.
GroupVersionKind
.
GroupVersion
()
.
String
()
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
@@ -165,11 +165,11 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
...
@@ -165,11 +165,11 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
client
,
err
:=
clients
.
ClientForVersion
(
mapping
.
APIVersion
)
client
,
err
:=
clients
.
ClientForVersion
(
mapping
.
GroupVersionKind
.
GroupVersion
()
.
String
()
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
if
describer
,
ok
:=
kubectl
.
DescriberFor
(
group
,
mapping
.
Kind
,
client
);
ok
{
if
describer
,
ok
:=
kubectl
.
DescriberFor
(
group
,
mapping
.
GroupVersionKind
.
Kind
,
client
);
ok
{
return
describer
,
nil
return
describer
,
nil
}
}
return
nil
,
fmt
.
Errorf
(
"no description has been implemented for %q"
,
mapping
.
Kind
)
return
nil
,
fmt
.
Errorf
(
"no description has been implemented for %q"
,
mapping
.
Kind
)
...
@@ -242,18 +242,18 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
...
@@ -242,18 +242,18 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
}
}
},
},
Scaler
:
func
(
mapping
*
meta
.
RESTMapping
)
(
kubectl
.
Scaler
,
error
)
{
Scaler
:
func
(
mapping
*
meta
.
RESTMapping
)
(
kubectl
.
Scaler
,
error
)
{
client
,
err
:=
clients
.
ClientForVersion
(
mapping
.
APIVersion
)
client
,
err
:=
clients
.
ClientForVersion
(
mapping
.
GroupVersionKind
.
GroupVersion
()
.
String
()
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
return
kubectl
.
ScalerFor
(
mapping
.
Kind
,
client
)
return
kubectl
.
ScalerFor
(
mapping
.
GroupVersionKind
.
Kind
,
client
)
},
},
Reaper
:
func
(
mapping
*
meta
.
RESTMapping
)
(
kubectl
.
Reaper
,
error
)
{
Reaper
:
func
(
mapping
*
meta
.
RESTMapping
)
(
kubectl
.
Reaper
,
error
)
{
client
,
err
:=
clients
.
ClientForVersion
(
mapping
.
APIVersion
)
client
,
err
:=
clients
.
ClientForVersion
(
mapping
.
GroupVersionKind
.
GroupVersion
()
.
String
()
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
return
kubectl
.
ReaperFor
(
mapping
.
Kind
,
client
)
return
kubectl
.
ReaperFor
(
mapping
.
GroupVersionKind
.
Kind
,
client
)
},
},
Validator
:
func
(
validate
bool
,
cacheDir
string
)
(
validation
.
Schema
,
error
)
{
Validator
:
func
(
validate
bool
,
cacheDir
string
)
(
validation
.
Schema
,
error
)
{
if
validate
{
if
validate
{
...
@@ -581,12 +581,12 @@ func (f *Factory) PrinterForMapping(cmd *cobra.Command, mapping *meta.RESTMappin
...
@@ -581,12 +581,12 @@ func (f *Factory) PrinterForMapping(cmd *cobra.Command, mapping *meta.RESTMappin
version
:=
OutputVersion
(
cmd
,
defaultVersion
)
version
:=
OutputVersion
(
cmd
,
defaultVersion
)
if
len
(
version
)
==
0
{
if
len
(
version
)
==
0
{
version
=
mapping
.
APIVersion
version
=
mapping
.
GroupVersionKind
.
GroupVersion
()
.
String
()
}
}
if
len
(
version
)
==
0
{
if
len
(
version
)
==
0
{
return
nil
,
fmt
.
Errorf
(
"you must specify an output-version when using this output format"
)
return
nil
,
fmt
.
Errorf
(
"you must specify an output-version when using this output format"
)
}
}
printer
=
kubectl
.
NewVersionedPrinter
(
printer
,
mapping
.
ObjectConvertor
,
version
,
mapping
.
APIVersion
)
printer
=
kubectl
.
NewVersionedPrinter
(
printer
,
mapping
.
ObjectConvertor
,
version
,
mapping
.
GroupVersionKind
.
GroupVersion
()
.
String
()
)
}
else
{
}
else
{
// Some callers do not have "label-columns" so we can't use the GetFlagStringSlice() helper
// Some callers do not have "label-columns" so we can't use the GetFlagStringSlice() helper
columnLabel
,
err
:=
cmd
.
Flags
()
.
GetStringSlice
(
"label-columns"
)
columnLabel
,
err
:=
cmd
.
Flags
()
.
GetStringSlice
(
"label-columns"
)
...
...
pkg/kubectl/resource/builder_test.go
View file @
303bcad3
...
@@ -470,7 +470,7 @@ func TestResourceByNameWithoutRequireObject(t *testing.T) {
...
@@ -470,7 +470,7 @@ func TestResourceByNameWithoutRequireObject(t *testing.T) {
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
}
}
if
mapping
.
Kind
!=
"Pod"
||
mapping
.
Resource
!=
"pods"
{
if
mapping
.
GroupVersionKind
.
Kind
!=
"Pod"
||
mapping
.
Resource
!=
"pods"
{
t
.
Errorf
(
"unexpected resource mapping: %#v"
,
mapping
)
t
.
Errorf
(
"unexpected resource mapping: %#v"
,
mapping
)
}
}
}
}
...
...
pkg/kubectl/resource/result.go
View file @
303bcad3
...
@@ -254,7 +254,7 @@ func AsVersionedObjects(infos []*Info, version string) ([]runtime.Object, error)
...
@@ -254,7 +254,7 @@ func AsVersionedObjects(infos []*Info, version string) ([]runtime.Object, error)
}
}
}
}
converted
,
err
:=
tryConvert
(
info
.
Mapping
.
ObjectConvertor
,
info
.
Object
,
version
,
info
.
Mapping
.
APIVersion
)
converted
,
err
:=
tryConvert
(
info
.
Mapping
.
ObjectConvertor
,
info
.
Object
,
version
,
info
.
Mapping
.
GroupVersionKind
.
GroupVersion
()
.
String
()
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
...
pkg/kubectl/resource/selector.go
View file @
303bcad3
...
@@ -45,7 +45,7 @@ func NewSelector(client RESTClient, mapping *meta.RESTMapping, namespace string,
...
@@ -45,7 +45,7 @@ func NewSelector(client RESTClient, mapping *meta.RESTMapping, namespace string,
// Visit implements Visitor
// Visit implements Visitor
func
(
r
*
Selector
)
Visit
(
fn
VisitorFunc
)
error
{
func
(
r
*
Selector
)
Visit
(
fn
VisitorFunc
)
error
{
list
,
err
:=
NewHelper
(
r
.
Client
,
r
.
Mapping
)
.
List
(
r
.
Namespace
,
r
.
ResourceMapping
()
.
APIVersion
,
r
.
Selector
)
list
,
err
:=
NewHelper
(
r
.
Client
,
r
.
Mapping
)
.
List
(
r
.
Namespace
,
r
.
ResourceMapping
()
.
GroupVersionKind
.
GroupVersion
()
.
String
()
,
r
.
Selector
)
if
err
!=
nil
{
if
err
!=
nil
{
if
errors
.
IsBadRequest
(
err
)
||
errors
.
IsNotFound
(
err
)
{
if
errors
.
IsBadRequest
(
err
)
||
errors
.
IsNotFound
(
err
)
{
if
r
.
Selector
.
Empty
()
{
if
r
.
Selector
.
Empty
()
{
...
@@ -70,7 +70,7 @@ func (r *Selector) Visit(fn VisitorFunc) error {
...
@@ -70,7 +70,7 @@ func (r *Selector) Visit(fn VisitorFunc) error {
}
}
func
(
r
*
Selector
)
Watch
(
resourceVersion
string
)
(
watch
.
Interface
,
error
)
{
func
(
r
*
Selector
)
Watch
(
resourceVersion
string
)
(
watch
.
Interface
,
error
)
{
return
NewHelper
(
r
.
Client
,
r
.
Mapping
)
.
Watch
(
r
.
Namespace
,
resourceVersion
,
r
.
ResourceMapping
()
.
APIVersion
,
r
.
Selector
)
return
NewHelper
(
r
.
Client
,
r
.
Mapping
)
.
Watch
(
r
.
Namespace
,
resourceVersion
,
r
.
ResourceMapping
()
.
GroupVersionKind
.
GroupVersion
()
.
String
()
,
r
.
Selector
)
}
}
// ResourceMapping returns the mapping for this resource and implements ResourceMapping
// ResourceMapping returns the mapping for this resource and implements ResourceMapping
...
...
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