mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-13 22:05:59 +00:00
rename to GroupVersion and rename the one in type.go to GroupVersionForDiscovery
This commit is contained in:
parent
fb360bca98
commit
15e6ca5ac5
@ -22,16 +22,16 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TODO: We need to remove the GroupVersion in types.go. We use the name GroupAndVersion here temporarily.
|
// 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.
|
// GroupVersion contains the "group" and the "version", which uniquely identifies the API.
|
||||||
type GroupAndVersion struct {
|
type GroupVersion struct {
|
||||||
Group string
|
Group string
|
||||||
Version string
|
Version string
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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 *GroupAndVersion) 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
|
||||||
@ -42,22 +42,22 @@ func (gv *GroupAndVersion) String() string {
|
|||||||
|
|
||||||
// ParseGroupVersion turns "group/version" string into a GroupVersion struct. It reports error
|
// ParseGroupVersion turns "group/version" string into a GroupVersion struct. It reports error
|
||||||
// if it cannot parse the string.
|
// if it cannot parse the string.
|
||||||
func ParseGroupVersion(gv string) (GroupAndVersion, error) {
|
func ParseGroupVersion(gv string) (GroupVersion, error) {
|
||||||
s := strings.Split(gv, "/")
|
s := strings.Split(gv, "/")
|
||||||
// "v1" is the only special case. Otherwise GroupVersion is expected to contain
|
// "v1" is the only special case. Otherwise GroupVersion is expected to contain
|
||||||
// one "/" dividing the string into two parts.
|
// one "/" dividing the string into two parts.
|
||||||
switch {
|
switch {
|
||||||
case len(s) == 1 && gv == "v1":
|
case len(s) == 1 && gv == "v1":
|
||||||
return GroupAndVersion{"", "v1"}, nil
|
return GroupVersion{"", "v1"}, nil
|
||||||
case len(s) == 2:
|
case len(s) == 2:
|
||||||
return GroupAndVersion{s[0], s[1]}, nil
|
return GroupVersion{s[0], s[1]}, nil
|
||||||
default:
|
default:
|
||||||
return GroupAndVersion{}, fmt.Errorf("Unexpected GroupVersion string: %v", gv)
|
return GroupVersion{}, fmt.Errorf("Unexpected GroupVersion string: %v", gv)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MarshalJSON implements the json.Marshaller interface.
|
// MarshalJSON implements the json.Marshaller interface.
|
||||||
func (gv GroupAndVersion) MarshalJSON() ([]byte, error) {
|
func (gv GroupVersion) MarshalJSON() ([]byte, error) {
|
||||||
s := gv.String()
|
s := gv.String()
|
||||||
if strings.Count(s, "/") > 1 {
|
if strings.Count(s, "/") > 1 {
|
||||||
return []byte{}, fmt.Errorf("illegal GroupVersion %v: contains more than one /", s)
|
return []byte{}, fmt.Errorf("illegal GroupVersion %v: contains more than one /", s)
|
||||||
@ -65,7 +65,7 @@ func (gv GroupAndVersion) MarshalJSON() ([]byte, error) {
|
|||||||
return json.Marshal(s)
|
return json.Marshal(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gv *GroupAndVersion) unmarshal(value []byte) error {
|
func (gv *GroupVersion) unmarshal(value []byte) error {
|
||||||
var s string
|
var s string
|
||||||
if err := json.Unmarshal(value, &s); err != nil {
|
if err := json.Unmarshal(value, &s); err != nil {
|
||||||
return err
|
return err
|
||||||
@ -79,11 +79,11 @@ func (gv *GroupAndVersion) unmarshal(value []byte) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// UnmarshalJSON implements the json.Unmarshaller interface.
|
// UnmarshalJSON implements the json.Unmarshaller interface.
|
||||||
func (gv *GroupAndVersion) UnmarshalJSON(value []byte) error {
|
func (gv *GroupVersion) UnmarshalJSON(value []byte) error {
|
||||||
return gv.unmarshal(value)
|
return gv.unmarshal(value)
|
||||||
}
|
}
|
||||||
|
|
||||||
// UnmarshalTEXT implements the Ugorji's encoding.TextUnmarshaler interface.
|
// UnmarshalTEXT implements the Ugorji's encoding.TextUnmarshaler interface.
|
||||||
func (gv *GroupAndVersion) UnmarshalText(value []byte) error {
|
func (gv *GroupVersion) UnmarshalText(value []byte) error {
|
||||||
return gv.unmarshal(value)
|
return gv.unmarshal(value)
|
||||||
}
|
}
|
||||||
|
@ -25,16 +25,16 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type GroupVersionHolder struct {
|
type GroupVersionHolder struct {
|
||||||
GV GroupAndVersion `json:"val"`
|
GV GroupVersion `json:"val"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGroupVersionUnmarshalJSON(t *testing.T) {
|
func TestGroupVersionUnmarshalJSON(t *testing.T) {
|
||||||
cases := []struct {
|
cases := []struct {
|
||||||
input []byte
|
input []byte
|
||||||
expect GroupAndVersion
|
expect GroupVersion
|
||||||
}{
|
}{
|
||||||
{[]byte(`{"val": "v1"}`), GroupAndVersion{"", "v1"}},
|
{[]byte(`{"val": "v1"}`), GroupVersion{"", "v1"}},
|
||||||
{[]byte(`{"val": "extensions/v1beta1"}`), GroupAndVersion{"extensions", "v1beta1"}},
|
{[]byte(`{"val": "extensions/v1beta1"}`), GroupVersion{"extensions", "v1beta1"}},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, c := range cases {
|
for _, c := range cases {
|
||||||
@ -58,11 +58,11 @@ func TestGroupVersionUnmarshalJSON(t *testing.T) {
|
|||||||
|
|
||||||
func TestGroupVersionMarshalJSON(t *testing.T) {
|
func TestGroupVersionMarshalJSON(t *testing.T) {
|
||||||
cases := []struct {
|
cases := []struct {
|
||||||
input GroupAndVersion
|
input GroupVersion
|
||||||
expect []byte
|
expect []byte
|
||||||
}{
|
}{
|
||||||
{GroupAndVersion{"", "v1"}, []byte(`{"val":"v1"}`)},
|
{GroupVersion{"", "v1"}, []byte(`{"val":"v1"}`)},
|
||||||
{GroupAndVersion{"extensions", "v1beta1"}, []byte(`{"val":"extensions/v1beta1"}`)},
|
{GroupVersion{"extensions", "v1beta1"}, []byte(`{"val":"extensions/v1beta1"}`)},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, c := range cases {
|
for _, c := range cases {
|
||||||
|
@ -299,15 +299,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 []GroupVersionForDiscovery `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 GroupVersionForDiscovery `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 GroupVersionForDiscovery 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
|
||||||
|
@ -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.GroupVersionForDiscovery{
|
||||||
{GroupVersion: "extensions/v1beta1"},
|
{GroupVersion: "extensions/v1beta1"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -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.GroupVersionForDiscovery{}
|
||||||
for _, version := range apiVersions.Versions {
|
for _, version := range apiVersions.Versions {
|
||||||
groupVersion := unversioned.GroupVersion{
|
groupVersion := unversioned.GroupVersionForDiscovery{
|
||||||
GroupVersion: version,
|
GroupVersion: version,
|
||||||
Version: version,
|
Version: version,
|
||||||
}
|
}
|
||||||
|
@ -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.GroupVersionForDiscovery{
|
||||||
{
|
{
|
||||||
GroupVersion: "group1/v1",
|
GroupVersion: "group1/v1",
|
||||||
},
|
},
|
||||||
@ -395,7 +395,7 @@ func TestHelperGetServerAPIVersions(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Versions: []unversioned.GroupVersion{
|
Versions: []unversioned.GroupVersionForDiscovery{
|
||||||
{
|
{
|
||||||
GroupVersion: "group2/v1",
|
GroupVersion: "group2/v1",
|
||||||
},
|
},
|
||||||
|
@ -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.GroupVersionForDiscovery{
|
||||||
{
|
{
|
||||||
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) {
|
|||||||
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.GroupVersionForDiscovery{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
|
|||||||
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.GroupVersionForDiscovery{
|
||||||
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.GroupVersionForDiscovery{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))
|
||||||
|
@ -399,13 +399,13 @@ func TestDiscoveryAtAPIS(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
expectGroupName := "extensions"
|
expectGroupName := "extensions"
|
||||||
expectVersions := []unversioned.GroupVersion{
|
expectVersions := []unversioned.GroupVersionForDiscovery{
|
||||||
{
|
{
|
||||||
GroupVersion: testapi.Extensions.GroupAndVersion(),
|
GroupVersion: testapi.Extensions.GroupAndVersion(),
|
||||||
Version: testapi.Extensions.Version(),
|
Version: testapi.Extensions.Version(),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
expectPreferredVersion := unversioned.GroupVersion{
|
expectPreferredVersion := unversioned.GroupVersionForDiscovery{
|
||||||
GroupVersion: config.StorageVersions["extensions"],
|
GroupVersion: config.StorageVersions["extensions"],
|
||||||
Version: apiutil.GetVersion(config.StorageVersions["extensions"]),
|
Version: apiutil.GetVersion(config.StorageVersions["extensions"]),
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user