mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 13:37:30 +00:00
Merge pull request #42275 from deads2k/cli-05-restmapper
Automatic merge from submit-queue (batch tested with PRs 41306, 42187, 41666, 42275, 42266) discovery restmapping should always prefer /v1 The core kube API, empty group, version==v1 should always be the most preferred group and resource from a rest mapper. This special cases that. All the others should be based on discovery order as we previously agreed. @kubernetes/sig-cli-pr-reviews @kubernetes/sig-api-machinery-pr-reviews @enj
This commit is contained in:
commit
6db099fcee
@ -43,8 +43,9 @@ func NewRESTMapper(groupResources []*APIGroupResources, versionInterfaces meta.V
|
|||||||
unionMapper := meta.MultiRESTMapper{}
|
unionMapper := meta.MultiRESTMapper{}
|
||||||
|
|
||||||
var groupPriority []string
|
var groupPriority []string
|
||||||
var resourcePriority []schema.GroupVersionResource
|
// /v1 is special. It should always come first
|
||||||
var kindPriority []schema.GroupVersionKind
|
resourcePriority := []schema.GroupVersionResource{{Group: "", Version: "v1", Resource: meta.AnyResource}}
|
||||||
|
kindPriority := []schema.GroupVersionKind{{Group: "", Version: "v1", Kind: meta.AnyKind}}
|
||||||
|
|
||||||
for _, group := range groupResources {
|
for _, group := range groupResources {
|
||||||
groupPriority = append(groupPriority, group.Group.Name)
|
groupPriority = append(groupPriority, group.Group.Name)
|
||||||
|
@ -35,6 +35,21 @@ import (
|
|||||||
|
|
||||||
func TestRESTMapper(t *testing.T) {
|
func TestRESTMapper(t *testing.T) {
|
||||||
resources := []*APIGroupResources{
|
resources := []*APIGroupResources{
|
||||||
|
{
|
||||||
|
Group: metav1.APIGroup{
|
||||||
|
Name: "extensions",
|
||||||
|
Versions: []metav1.GroupVersionForDiscovery{
|
||||||
|
{Version: "v1beta"},
|
||||||
|
},
|
||||||
|
PreferredVersion: metav1.GroupVersionForDiscovery{Version: "v1beta"},
|
||||||
|
},
|
||||||
|
VersionedResources: map[string][]metav1.APIResource{
|
||||||
|
"v1beta": {
|
||||||
|
{Name: "jobs", Namespaced: true, Kind: "Job"},
|
||||||
|
{Name: "pods", Namespaced: true, Kind: "Pod"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
Group: metav1.APIGroup{
|
Group: metav1.APIGroup{
|
||||||
Versions: []metav1.GroupVersionForDiscovery{
|
Versions: []metav1.GroupVersionForDiscovery{
|
||||||
@ -52,20 +67,6 @@ func TestRESTMapper(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
|
||||||
Group: metav1.APIGroup{
|
|
||||||
Name: "extensions",
|
|
||||||
Versions: []metav1.GroupVersionForDiscovery{
|
|
||||||
{Version: "v1beta"},
|
|
||||||
},
|
|
||||||
PreferredVersion: metav1.GroupVersionForDiscovery{Version: "v1beta"},
|
|
||||||
},
|
|
||||||
VersionedResources: map[string][]metav1.APIResource{
|
|
||||||
"v1beta": {
|
|
||||||
{Name: "jobs", Namespaced: true, Kind: "Job"},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
restMapper := NewRESTMapper(resources, nil)
|
restMapper := NewRESTMapper(resources, nil)
|
||||||
@ -74,6 +75,15 @@ func TestRESTMapper(t *testing.T) {
|
|||||||
input schema.GroupVersionResource
|
input schema.GroupVersionResource
|
||||||
want schema.GroupVersionKind
|
want schema.GroupVersionKind
|
||||||
}{
|
}{
|
||||||
|
{
|
||||||
|
input: schema.GroupVersionResource{
|
||||||
|
Resource: "pods",
|
||||||
|
},
|
||||||
|
want: schema.GroupVersionKind{
|
||||||
|
Version: "v1",
|
||||||
|
Kind: "Pod",
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
input: schema.GroupVersionResource{
|
input: schema.GroupVersionResource{
|
||||||
Version: "v1",
|
Version: "v1",
|
||||||
@ -131,6 +141,15 @@ func TestRESTMapper(t *testing.T) {
|
|||||||
input schema.GroupVersionResource
|
input schema.GroupVersionResource
|
||||||
want schema.GroupVersionResource
|
want schema.GroupVersionResource
|
||||||
}{
|
}{
|
||||||
|
{
|
||||||
|
input: schema.GroupVersionResource{
|
||||||
|
Resource: "pods",
|
||||||
|
},
|
||||||
|
want: schema.GroupVersionResource{
|
||||||
|
Version: "v1",
|
||||||
|
Resource: "pods",
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
input: schema.GroupVersionResource{
|
input: schema.GroupVersionResource{
|
||||||
Version: "v1",
|
Version: "v1",
|
||||||
|
Loading…
Reference in New Issue
Block a user