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
354c6f3b
Commit
354c6f3b
authored
Nov 07, 2015
by
k8s-merge-robot
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #16834 from caesarxuchao/GroupVersion-Object
Auto commit by PR queue bot
parents
d71a667a
2f012ae0
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
184 additions
and
17 deletions
+184
-17
group_version.go
pkg/api/unversioned/group_version.go
+89
-0
group_version_test.go
pkg/api/unversioned/group_version_test.go
+78
-0
types.go
pkg/api/unversioned/types.go
+3
-3
types_swagger_doc_generated.go
pkg/api/unversioned/types_swagger_doc_generated.go
+3
-3
client_test.go
pkg/client/unversioned/client_test.go
+1
-1
discovery_client.go
pkg/client/unversioned/discovery_client.go
+2
-2
helper_test.go
pkg/client/unversioned/helper_test.go
+2
-2
master.go
pkg/master/master.go
+4
-4
master_test.go
pkg/master/master_test.go
+2
-2
No files found.
pkg/api/unversioned/group_version.go
0 → 100644
View file @
354c6f3b
/*
Copyright 2015 The Kubernetes Authors All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package
unversioned
import
(
"encoding/json"
"fmt"
"strings"
)
// TODO: We need to remove the GroupVersion in types.go. We use the name GroupVersion here temporarily.
// GroupVersion contains the "group" and the "version", which uniquely identifies the API.
type
GroupVersion
struct
{
Group
string
Version
string
}
// String puts "group" and "version" into a single "group/version" string. For the legacy v1
// it returns "v1".
func
(
gv
*
GroupVersion
)
String
()
string
{
// special case of "v1" for backward compatibility
if
gv
.
Group
==
""
&&
gv
.
Version
==
"v1"
{
return
gv
.
Version
}
else
{
return
gv
.
Group
+
"/"
+
gv
.
Version
}
}
// ParseGroupVersion turns "group/version" string into a GroupVersion struct. It reports error
// if it cannot parse the string.
func
ParseGroupVersion
(
gv
string
)
(
GroupVersion
,
error
)
{
s
:=
strings
.
Split
(
gv
,
"/"
)
// "v1" is the only special case. Otherwise GroupVersion is expected to contain
// one "/" dividing the string into two parts.
switch
{
case
len
(
s
)
==
1
&&
gv
==
"v1"
:
return
GroupVersion
{
""
,
"v1"
},
nil
case
len
(
s
)
==
2
:
return
GroupVersion
{
s
[
0
],
s
[
1
]},
nil
default
:
return
GroupVersion
{},
fmt
.
Errorf
(
"Unexpected GroupVersion string: %v"
,
gv
)
}
}
// MarshalJSON implements the json.Marshaller interface.
func
(
gv
GroupVersion
)
MarshalJSON
()
([]
byte
,
error
)
{
s
:=
gv
.
String
()
if
strings
.
Count
(
s
,
"/"
)
>
1
{
return
[]
byte
{},
fmt
.
Errorf
(
"illegal GroupVersion %v: contains more than one /"
,
s
)
}
return
json
.
Marshal
(
s
)
}
func
(
gv
*
GroupVersion
)
unmarshal
(
value
[]
byte
)
error
{
var
s
string
if
err
:=
json
.
Unmarshal
(
value
,
&
s
);
err
!=
nil
{
return
err
}
parsed
,
err
:=
ParseGroupVersion
(
s
)
if
err
!=
nil
{
return
err
}
*
gv
=
parsed
return
nil
}
// UnmarshalJSON implements the json.Unmarshaller interface.
func
(
gv
*
GroupVersion
)
UnmarshalJSON
(
value
[]
byte
)
error
{
return
gv
.
unmarshal
(
value
)
}
// UnmarshalTEXT implements the Ugorji's encoding.TextUnmarshaler interface.
func
(
gv
*
GroupVersion
)
UnmarshalText
(
value
[]
byte
)
error
{
return
gv
.
unmarshal
(
value
)
}
pkg/api/unversioned/group_version_test.go
0 → 100644
View file @
354c6f3b
/*
Copyright 2015 The Kubernetes Authors All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package
unversioned
import
(
"encoding/json"
"reflect"
"testing"
"github.com/ugorji/go/codec"
)
type
GroupVersionHolder
struct
{
GV
GroupVersion
`json:"val"`
}
func
TestGroupVersionUnmarshalJSON
(
t
*
testing
.
T
)
{
cases
:=
[]
struct
{
input
[]
byte
expect
GroupVersion
}{
{[]
byte
(
`{"val": "v1"}`
),
GroupVersion
{
""
,
"v1"
}},
{[]
byte
(
`{"val": "extensions/v1beta1"}`
),
GroupVersion
{
"extensions"
,
"v1beta1"
}},
}
for
_
,
c
:=
range
cases
{
var
result
GroupVersionHolder
// test golang lib's JSON codec
if
err
:=
json
.
Unmarshal
([]
byte
(
c
.
input
),
&
result
);
err
!=
nil
{
t
.
Errorf
(
"JSON codec failed to unmarshal input '%v': %v"
,
c
.
input
,
err
)
}
if
!
reflect
.
DeepEqual
(
result
.
GV
,
c
.
expect
)
{
t
.
Errorf
(
"JSON codec failed to unmarshal input '%s': expected %+v, got %+v"
,
c
.
input
,
c
.
expect
,
result
.
GV
)
}
// test the Ugorji codec
if
err
:=
codec
.
NewDecoderBytes
(
c
.
input
,
new
(
codec
.
JsonHandle
))
.
Decode
(
&
result
);
err
!=
nil
{
t
.
Errorf
(
"Ugorji codec failed to unmarshal input '%v': %v"
,
c
.
input
,
err
)
}
if
!
reflect
.
DeepEqual
(
result
.
GV
,
c
.
expect
)
{
t
.
Errorf
(
"Ugorji codec failed to unmarshal input '%s': expected %+v, got %+v"
,
c
.
input
,
c
.
expect
,
result
.
GV
)
}
}
}
func
TestGroupVersionMarshalJSON
(
t
*
testing
.
T
)
{
cases
:=
[]
struct
{
input
GroupVersion
expect
[]
byte
}{
{
GroupVersion
{
""
,
"v1"
},
[]
byte
(
`{"val":"v1"}`
)},
{
GroupVersion
{
"extensions"
,
"v1beta1"
},
[]
byte
(
`{"val":"extensions/v1beta1"}`
)},
}
for
_
,
c
:=
range
cases
{
input
:=
GroupVersionHolder
{
c
.
input
}
result
,
err
:=
json
.
Marshal
(
&
input
)
if
err
!=
nil
{
t
.
Errorf
(
"Failed to marshal input '%v': %v"
,
input
,
err
)
}
if
!
reflect
.
DeepEqual
(
result
,
c
.
expect
)
{
t
.
Errorf
(
"Failed to marshal input '%+v': expected: %s, got: %s"
,
input
,
c
.
expect
,
result
)
}
}
}
pkg/api/unversioned/types.go
View file @
354c6f3b
...
@@ -305,15 +305,15 @@ type APIGroup struct {
...
@@ -305,15 +305,15 @@ type APIGroup struct {
// 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.
Versions
[]
GroupVersion
`json:"versions"`
Versions
[]
GroupVersion
ForDiscovery
`json:"versions"`
// preferredVersion is the version preferred by the API server, which
// preferredVersion is the version preferred by the API server, which
// probably is the storage version.
// probably is the storage version.
PreferredVersion
GroupVersion
`json:"preferredVersion,omitempty"`
PreferredVersion
GroupVersion
ForDiscovery
`json:"preferredVersion,omitempty"`
}
}
// GroupVersion contains the "group/version" and "version" string of a version.
// GroupVersion contains the "group/version" and "version" string of a version.
// It is made a struct to keep extensiblity.
// It is made a struct to keep extensiblity.
type
GroupVersion
struct
{
type
GroupVersion
ForDiscovery
struct
{
// groupVersion specifies the API group and version in the form "group/version"
// groupVersion specifies the API group and version in the form "group/version"
GroupVersion
string
`json:"groupVersion"`
GroupVersion
string
`json:"groupVersion"`
// version specifies the version in the form of "version". This is to save
// version specifies the version in the form of "version". This is to save
...
...
pkg/api/unversioned/types_swagger_doc_generated.go
View file @
354c6f3b
...
@@ -76,14 +76,14 @@ func (APIVersions) SwaggerDoc() map[string]string {
...
@@ -76,14 +76,14 @@ func (APIVersions) SwaggerDoc() map[string]string {
return
map_APIVersions
return
map_APIVersions
}
}
var
map_GroupVersion
=
map
[
string
]
string
{
var
map_GroupVersion
ForDiscovery
=
map
[
string
]
string
{
""
:
"GroupVersion contains the
\"
group/version
\"
and
\"
version
\"
string of a version. It is made a struct to keep extensiblity."
,
""
:
"GroupVersion contains the
\"
group/version
\"
and
\"
version
\"
string of a version. It is made a struct to keep extensiblity."
,
"groupVersion"
:
"groupVersion specifies the API group and version in the form
\"
group/version
\"
"
,
"groupVersion"
:
"groupVersion specifies the API group and version in the form
\"
group/version
\"
"
,
"version"
:
"version specifies the version in the form of
\"
version
\"
. This is to save the clients the trouble of splitting the GroupVersion."
,
"version"
:
"version specifies the version in the form of
\"
version
\"
. This is to save the clients the trouble of splitting the GroupVersion."
,
}
}
func
(
GroupVersion
)
SwaggerDoc
()
map
[
string
]
string
{
func
(
GroupVersion
ForDiscovery
)
SwaggerDoc
()
map
[
string
]
string
{
return
map_GroupVersion
return
map_GroupVersion
ForDiscovery
}
}
var
map_ListMeta
=
map
[
string
]
string
{
var
map_ListMeta
=
map
[
string
]
string
{
...
...
pkg/client/unversioned/client_test.go
View file @
354c6f3b
...
@@ -400,7 +400,7 @@ func TestGetServerResources(t *testing.T) {
...
@@ -400,7 +400,7 @@ func TestGetServerResources(t *testing.T) {
list
=
&
unversioned
.
APIGroupList
{
list
=
&
unversioned
.
APIGroupList
{
Groups
:
[]
unversioned
.
APIGroup
{
Groups
:
[]
unversioned
.
APIGroup
{
{
{
Versions
:
[]
unversioned
.
GroupVersion
{
Versions
:
[]
unversioned
.
GroupVersion
ForDiscovery
{
{
GroupVersion
:
"extensions/v1beta1"
},
{
GroupVersion
:
"extensions/v1beta1"
},
},
},
},
},
...
...
pkg/client/unversioned/discovery_client.go
View file @
354c6f3b
...
@@ -55,9 +55,9 @@ type DiscoveryClient struct {
...
@@ -55,9 +55,9 @@ type DiscoveryClient struct {
// Convert unversioned.APIVersions to unversioned.APIGroup. APIVersions is used by legacy v1, so
// Convert unversioned.APIVersions to unversioned.APIGroup. APIVersions is used by legacy v1, so
// group would be "".
// group would be "".
func
apiVersionsToAPIGroup
(
apiVersions
*
unversioned
.
APIVersions
)
(
apiGroup
unversioned
.
APIGroup
)
{
func
apiVersionsToAPIGroup
(
apiVersions
*
unversioned
.
APIVersions
)
(
apiGroup
unversioned
.
APIGroup
)
{
groupVersions
:=
[]
unversioned
.
GroupVersion
{}
groupVersions
:=
[]
unversioned
.
GroupVersion
ForDiscovery
{}
for
_
,
version
:=
range
apiVersions
.
Versions
{
for
_
,
version
:=
range
apiVersions
.
Versions
{
groupVersion
:=
unversioned
.
GroupVersion
{
groupVersion
:=
unversioned
.
GroupVersion
ForDiscovery
{
GroupVersion
:
version
,
GroupVersion
:
version
,
Version
:
version
,
Version
:
version
,
}
}
...
...
pkg/client/unversioned/helper_test.go
View file @
354c6f3b
...
@@ -385,7 +385,7 @@ func TestHelperGetServerAPIVersions(t *testing.T) {
...
@@ -385,7 +385,7 @@ func TestHelperGetServerAPIVersions(t *testing.T) {
APIGroupList
:=
unversioned
.
APIGroupList
{
APIGroupList
:=
unversioned
.
APIGroupList
{
Groups
:
[]
unversioned
.
APIGroup
{
Groups
:
[]
unversioned
.
APIGroup
{
{
{
Versions
:
[]
unversioned
.
GroupVersion
{
Versions
:
[]
unversioned
.
GroupVersion
ForDiscovery
{
{
{
GroupVersion
:
"group1/v1"
,
GroupVersion
:
"group1/v1"
,
},
},
...
@@ -395,7 +395,7 @@ func TestHelperGetServerAPIVersions(t *testing.T) {
...
@@ -395,7 +395,7 @@ func TestHelperGetServerAPIVersions(t *testing.T) {
},
},
},
},
{
{
Versions
:
[]
unversioned
.
GroupVersion
{
Versions
:
[]
unversioned
.
GroupVersion
ForDiscovery
{
{
{
GroupVersion
:
"group2/v1"
,
GroupVersion
:
"group2/v1"
,
},
},
...
...
pkg/master/master.go
View file @
354c6f3b
...
@@ -665,7 +665,7 @@ func (m *Master) init(c *Config) {
...
@@ -665,7 +665,7 @@ func (m *Master) init(c *Config) {
if
err
!=
nil
{
if
err
!=
nil
{
glog
.
Fatalf
(
"Unable to setup experimental api: %v"
,
err
)
glog
.
Fatalf
(
"Unable to setup experimental api: %v"
,
err
)
}
}
expAPIVersions
:=
[]
unversioned
.
GroupVersion
{
expAPIVersions
:=
[]
unversioned
.
GroupVersion
ForDiscovery
{
{
{
GroupVersion
:
expVersion
.
Version
,
GroupVersion
:
expVersion
.
Version
,
Version
:
apiutil
.
GetVersion
(
expVersion
.
Version
),
Version
:
apiutil
.
GetVersion
(
expVersion
.
Version
),
...
@@ -678,7 +678,7 @@ func (m *Master) init(c *Config) {
...
@@ -678,7 +678,7 @@ func (m *Master) init(c *Config) {
group
:=
unversioned
.
APIGroup
{
group
:=
unversioned
.
APIGroup
{
Name
:
g
.
Group
,
Name
:
g
.
Group
,
Versions
:
expAPIVersions
,
Versions
:
expAPIVersions
,
PreferredVersion
:
unversioned
.
GroupVersion
{
GroupVersion
:
storageVersion
,
Version
:
apiutil
.
GetVersion
(
storageVersion
)},
PreferredVersion
:
unversioned
.
GroupVersion
ForDiscovery
{
GroupVersion
:
storageVersion
,
Version
:
apiutil
.
GetVersion
(
storageVersion
)},
}
}
apiserver
.
AddGroupWebService
(
m
.
handlerContainer
,
c
.
APIGroupPrefix
+
"/"
+
latest
.
GroupOrDie
(
"extensions"
)
.
Group
,
group
)
apiserver
.
AddGroupWebService
(
m
.
handlerContainer
,
c
.
APIGroupPrefix
+
"/"
+
latest
.
GroupOrDie
(
"extensions"
)
.
Group
,
group
)
allGroups
=
append
(
allGroups
,
group
)
allGroups
=
append
(
allGroups
,
group
)
...
@@ -992,13 +992,13 @@ func (m *Master) InstallThirdPartyResource(rsrc *expapi.ThirdPartyResource) erro
...
@@ -992,13 +992,13 @@ func (m *Master) InstallThirdPartyResource(rsrc *expapi.ThirdPartyResource) erro
glog
.
Fatalf
(
"Unable to setup thirdparty api: %v"
,
err
)
glog
.
Fatalf
(
"Unable to setup thirdparty api: %v"
,
err
)
}
}
path
:=
makeThirdPartyPath
(
group
)
path
:=
makeThirdPartyPath
(
group
)
groupVersion
:=
unversioned
.
GroupVersion
{
groupVersion
:=
unversioned
.
GroupVersion
ForDiscovery
{
GroupVersion
:
group
+
"/"
+
rsrc
.
Versions
[
0
]
.
Name
,
GroupVersion
:
group
+
"/"
+
rsrc
.
Versions
[
0
]
.
Name
,
Version
:
rsrc
.
Versions
[
0
]
.
Name
,
Version
:
rsrc
.
Versions
[
0
]
.
Name
,
}
}
apiGroup
:=
unversioned
.
APIGroup
{
apiGroup
:=
unversioned
.
APIGroup
{
Name
:
group
,
Name
:
group
,
Versions
:
[]
unversioned
.
GroupVersion
{
groupVersion
},
Versions
:
[]
unversioned
.
GroupVersion
ForDiscovery
{
groupVersion
},
}
}
apiserver
.
AddGroupWebService
(
m
.
handlerContainer
,
path
,
apiGroup
)
apiserver
.
AddGroupWebService
(
m
.
handlerContainer
,
path
,
apiGroup
)
m
.
addThirdPartyResourceStorage
(
path
,
thirdparty
.
Storage
[
strings
.
ToLower
(
kind
)
+
"s"
]
.
(
*
thirdpartyresourcedataetcd
.
REST
))
m
.
addThirdPartyResourceStorage
(
path
,
thirdparty
.
Storage
[
strings
.
ToLower
(
kind
)
+
"s"
]
.
(
*
thirdpartyresourcedataetcd
.
REST
))
...
...
pkg/master/master_test.go
View file @
354c6f3b
...
@@ -399,13 +399,13 @@ func TestDiscoveryAtAPIS(t *testing.T) {
...
@@ -399,13 +399,13 @@ func TestDiscoveryAtAPIS(t *testing.T) {
}
}
expectGroupName
:=
"extensions"
expectGroupName
:=
"extensions"
expectVersions
:=
[]
unversioned
.
GroupVersion
{
expectVersions
:=
[]
unversioned
.
GroupVersion
ForDiscovery
{
{
{
GroupVersion
:
testapi
.
Extensions
.
GroupAndVersion
(),
GroupVersion
:
testapi
.
Extensions
.
GroupAndVersion
(),
Version
:
testapi
.
Extensions
.
Version
(),
Version
:
testapi
.
Extensions
.
Version
(),
},
},
}
}
expectPreferredVersion
:=
unversioned
.
GroupVersion
{
expectPreferredVersion
:=
unversioned
.
GroupVersion
ForDiscovery
{
GroupVersion
:
config
.
StorageVersions
[
"extensions"
],
GroupVersion
:
config
.
StorageVersions
[
"extensions"
],
Version
:
apiutil
.
GetVersion
(
config
.
StorageVersions
[
"extensions"
]),
Version
:
apiutil
.
GetVersion
(
config
.
StorageVersions
[
"extensions"
]),
}
}
...
...
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