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
cd7e4bd6
Commit
cd7e4bd6
authored
Oct 29, 2015
by
k8s-merge-robot
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #16364 from liggitt/unversioned_types
Auto commit by PR queue bot
parents
e47c8db9
3bc4abb9
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
54 additions
and
5 deletions
+54
-5
register.go
pkg/api/register.go
+4
-0
serialization_test.go
pkg/api/serialization_test.go
+33
-0
testapi.go
pkg/api/testapi/testapi.go
+4
-0
types.go
pkg/api/unversioned/types.go
+9
-1
apiserver.go
pkg/apiserver/apiserver.go
+4
-4
No files found.
pkg/api/register.go
View file @
cd7e4bd6
...
@@ -71,6 +71,10 @@ func init() {
...
@@ -71,6 +71,10 @@ func init() {
// Register Unversioned types
// Register Unversioned types
Scheme
.
AddKnownTypes
(
""
,
&
unversioned
.
Status
{})
Scheme
.
AddKnownTypes
(
""
,
&
unversioned
.
Status
{})
Scheme
.
AddKnownTypes
(
""
,
&
unversioned
.
APIVersions
{})
Scheme
.
AddKnownTypes
(
""
,
&
unversioned
.
APIGroupList
{})
Scheme
.
AddKnownTypes
(
""
,
&
unversioned
.
APIGroup
{})
Scheme
.
AddKnownTypes
(
""
,
&
unversioned
.
APIResourceList
{})
}
}
func
(
*
Pod
)
IsAnAPIObject
()
{}
func
(
*
Pod
)
IsAnAPIObject
()
{}
...
...
pkg/api/serialization_test.go
View file @
cd7e4bd6
...
@@ -28,6 +28,7 @@ import (
...
@@ -28,6 +28,7 @@ import (
"k8s.io/kubernetes/pkg/api/meta"
"k8s.io/kubernetes/pkg/api/meta"
"k8s.io/kubernetes/pkg/api/testapi"
"k8s.io/kubernetes/pkg/api/testapi"
apitesting
"k8s.io/kubernetes/pkg/api/testing"
apitesting
"k8s.io/kubernetes/pkg/api/testing"
"k8s.io/kubernetes/pkg/api/unversioned"
"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"
...
@@ -94,6 +95,7 @@ func roundTripSame(t *testing.T, item runtime.Object, except ...string) {
...
@@ -94,6 +95,7 @@ func roundTripSame(t *testing.T, item runtime.Object, except ...string) {
codec
,
err
:=
testapi
.
GetCodecForObject
(
item
)
codec
,
err
:=
testapi
.
GetCodecForObject
(
item
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"unexpected error: %v"
,
err
)
t
.
Errorf
(
"unexpected error: %v"
,
err
)
return
}
}
version
:=
testapi
.
Default
.
Version
()
version
:=
testapi
.
Default
.
Version
()
...
@@ -203,6 +205,37 @@ func TestBadJSONRejection(t *testing.T) {
...
@@ -203,6 +205,37 @@ func TestBadJSONRejection(t *testing.T) {
}*/
}*/
}
}
func
TestUnversionedTypes
(
t
*
testing
.
T
)
{
testcases
:=
[]
runtime
.
Object
{
&
unversioned
.
Status
{
Status
:
"Failure"
,
Message
:
"something went wrong"
},
&
unversioned
.
APIVersions
{
Versions
:
[]
string
{
"A"
,
"B"
,
"C"
}},
&
unversioned
.
APIGroupList
{
Groups
:
[]
unversioned
.
APIGroup
{{
Name
:
"mygroup"
}}},
&
unversioned
.
APIGroup
{
Name
:
"mygroup"
},
&
unversioned
.
APIResourceList
{
GroupVersion
:
"mygroup/myversion"
},
}
for
_
,
obj
:=
range
testcases
{
// Make sure the unversioned codec can encode
unversionedJSON
,
err
:=
api
.
Codec
.
Encode
(
obj
)
if
err
!=
nil
{
t
.
Errorf
(
"%v: unexpected error: %v"
,
obj
,
err
)
continue
}
// Make sure the versioned codec under test can decode
versionDecodedObject
,
err
:=
testapi
.
Default
.
Codec
()
.
Decode
(
unversionedJSON
)
if
err
!=
nil
{
t
.
Errorf
(
"%v: unexpected error: %v"
,
obj
,
err
)
continue
}
// Make sure it decodes correctly
if
!
reflect
.
DeepEqual
(
obj
,
versionDecodedObject
)
{
t
.
Errorf
(
"%v: expected %#v, got %#v"
,
obj
,
obj
,
versionDecodedObject
)
continue
}
}
}
const
benchmarkSeed
=
100
const
benchmarkSeed
=
100
func
BenchmarkEncode
(
b
*
testing
.
B
)
{
func
BenchmarkEncode
(
b
*
testing
.
B
)
{
...
...
pkg/api/testapi/testapi.go
View file @
cd7e4bd6
...
@@ -225,5 +225,9 @@ func GetCodecForObject(obj runtime.Object) (runtime.Codec, error) {
...
@@ -225,5 +225,9 @@ func GetCodecForObject(obj runtime.Object) (runtime.Codec, error) {
return
group
.
Codec
(),
nil
return
group
.
Codec
(),
nil
}
}
}
}
// Codec used for unversioned types
if
api
.
Scheme
.
Recognizes
(
""
,
kind
)
{
return
api
.
Codec
,
nil
}
return
nil
,
fmt
.
Errorf
(
"unexpected kind: %v"
,
kind
)
return
nil
,
fmt
.
Errorf
(
"unexpected kind: %v"
,
kind
)
}
}
pkg/api/unversioned/types.go
View file @
cd7e4bd6
...
@@ -270,11 +270,16 @@ const (
...
@@ -270,11 +270,16 @@ const (
CauseTypeUnexpectedServerResponse
CauseType
=
"UnexpectedServerResponse"
CauseTypeUnexpectedServerResponse
CauseType
=
"UnexpectedServerResponse"
)
)
func
(
*
Status
)
IsAnAPIObject
()
{}
func
(
*
Status
)
IsAnAPIObject
()
{}
func
(
*
APIVersions
)
IsAnAPIObject
()
{}
func
(
*
APIGroupList
)
IsAnAPIObject
()
{}
func
(
*
APIGroup
)
IsAnAPIObject
()
{}
func
(
*
APIResourceList
)
IsAnAPIObject
()
{}
// APIVersions lists the versions that are available, to allow clients to
// APIVersions lists the versions that are available, to allow clients to
// discover the API at /api, which is the root path of the legacy v1 API.
// discover the API at /api, which is the root path of the legacy v1 API.
type
APIVersions
struct
{
type
APIVersions
struct
{
TypeMeta
`json:",inline"`
// versions are the api versions that are available.
// versions are the api versions that are available.
Versions
[]
string
`json:"versions"`
Versions
[]
string
`json:"versions"`
}
}
...
@@ -282,6 +287,7 @@ type APIVersions struct {
...
@@ -282,6 +287,7 @@ type APIVersions struct {
// APIGroupList is a list of APIGroup, to allow clients to discover the API at
// APIGroupList is a list of APIGroup, to allow clients to discover the API at
// /apis.
// /apis.
type
APIGroupList
struct
{
type
APIGroupList
struct
{
TypeMeta
`json:",inline"`
// groups is a list of APIGroup.
// groups is a list of APIGroup.
Groups
[]
APIGroup
`json:"groups"`
Groups
[]
APIGroup
`json:"groups"`
}
}
...
@@ -289,6 +295,7 @@ type APIGroupList struct {
...
@@ -289,6 +295,7 @@ type APIGroupList struct {
// APIGroup contains the name, the supported versions, and the preferred version
// APIGroup contains the name, the supported versions, and the preferred version
// of a group.
// of a group.
type
APIGroup
struct
{
type
APIGroup
struct
{
TypeMeta
`json:",inline"`
// name is the name of the group.
// name is the name of the group.
Name
string
`json:"name"`
Name
string
`json:"name"`
// versions are the versions supported in this group.
// versions are the versions supported in this group.
...
@@ -320,6 +327,7 @@ type APIResource struct {
...
@@ -320,6 +327,7 @@ type APIResource struct {
// resources supported in a specific group and version, and if the resource
// resources supported in a specific group and version, and if the resource
// is namespaced.
// is namespaced.
type
APIResourceList
struct
{
type
APIResourceList
struct
{
TypeMeta
`json:",inline"`
// groupVersion is the group and version this APIResourceList is for.
// groupVersion is the group and version this APIResourceList is for.
GroupVersion
string
`json:"groupVersion"`
GroupVersion
string
`json:"groupVersion"`
// resources contains the name of the resources and if they are namespaced.
// resources contains the name of the resources and if they are namespaced.
...
...
pkg/apiserver/apiserver.go
View file @
cd7e4bd6
...
@@ -306,7 +306,7 @@ func handleVersion(req *restful.Request, resp *restful.Response) {
...
@@ -306,7 +306,7 @@ func handleVersion(req *restful.Request, resp *restful.Response) {
func
APIVersionHandler
(
versions
...
string
)
restful
.
RouteFunction
{
func
APIVersionHandler
(
versions
...
string
)
restful
.
RouteFunction
{
return
func
(
req
*
restful
.
Request
,
resp
*
restful
.
Response
)
{
return
func
(
req
*
restful
.
Request
,
resp
*
restful
.
Response
)
{
// TODO: use restful's Response methods
// TODO: use restful's Response methods
write
RawJSON
(
http
.
StatusOK
,
unversioned
.
APIVersions
{
Versions
:
versions
},
resp
.
ResponseWriter
)
write
JSON
(
http
.
StatusOK
,
api
.
Codec
,
&
unversioned
.
APIVersions
{
Versions
:
versions
},
resp
.
ResponseWriter
,
true
)
}
}
}
}
...
@@ -314,7 +314,7 @@ func APIVersionHandler(versions ...string) restful.RouteFunction {
...
@@ -314,7 +314,7 @@ func APIVersionHandler(versions ...string) restful.RouteFunction {
func
RootAPIHandler
(
groups
[]
unversioned
.
APIGroup
)
restful
.
RouteFunction
{
func
RootAPIHandler
(
groups
[]
unversioned
.
APIGroup
)
restful
.
RouteFunction
{
return
func
(
req
*
restful
.
Request
,
resp
*
restful
.
Response
)
{
return
func
(
req
*
restful
.
Request
,
resp
*
restful
.
Response
)
{
// TODO: use restful's Response methods
// TODO: use restful's Response methods
write
RawJSON
(
http
.
StatusOK
,
unversioned
.
APIGroupList
{
Groups
:
groups
},
resp
.
ResponseWriter
)
write
JSON
(
http
.
StatusOK
,
api
.
Codec
,
&
unversioned
.
APIGroupList
{
Groups
:
groups
},
resp
.
ResponseWriter
,
true
)
}
}
}
}
...
@@ -323,7 +323,7 @@ func RootAPIHandler(groups []unversioned.APIGroup) restful.RouteFunction {
...
@@ -323,7 +323,7 @@ func RootAPIHandler(groups []unversioned.APIGroup) restful.RouteFunction {
func
GroupHandler
(
group
unversioned
.
APIGroup
)
restful
.
RouteFunction
{
func
GroupHandler
(
group
unversioned
.
APIGroup
)
restful
.
RouteFunction
{
return
func
(
req
*
restful
.
Request
,
resp
*
restful
.
Response
)
{
return
func
(
req
*
restful
.
Request
,
resp
*
restful
.
Response
)
{
// TODO: use restful's Response methods
// TODO: use restful's Response methods
write
RawJSON
(
http
.
StatusOK
,
group
,
resp
.
ResponseWriter
)
write
JSON
(
http
.
StatusOK
,
api
.
Codec
,
&
group
,
resp
.
ResponseWriter
,
true
)
}
}
}
}
...
@@ -331,7 +331,7 @@ func GroupHandler(group unversioned.APIGroup) restful.RouteFunction {
...
@@ -331,7 +331,7 @@ func GroupHandler(group unversioned.APIGroup) restful.RouteFunction {
func
SupportedResourcesHandler
(
groupVersion
string
,
apiResources
[]
unversioned
.
APIResource
)
restful
.
RouteFunction
{
func
SupportedResourcesHandler
(
groupVersion
string
,
apiResources
[]
unversioned
.
APIResource
)
restful
.
RouteFunction
{
return
func
(
req
*
restful
.
Request
,
resp
*
restful
.
Response
)
{
return
func
(
req
*
restful
.
Request
,
resp
*
restful
.
Response
)
{
// TODO: use restful's Response methods
// TODO: use restful's Response methods
write
RawJSON
(
http
.
StatusOK
,
unversioned
.
APIResourceList
{
GroupVersion
:
groupVersion
,
APIResources
:
apiResources
},
resp
.
ResponseWriter
)
write
JSON
(
http
.
StatusOK
,
api
.
Codec
,
&
unversioned
.
APIResourceList
{
GroupVersion
:
groupVersion
,
APIResources
:
apiResources
},
resp
.
ResponseWriter
,
true
)
}
}
}
}
...
...
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