зеркало из https://github.com/Azure/ARO-RP.git
fix: respect apiVersion of submitted document
This commit is contained in:
Родитель
00fcab0567
Коммит
3434c40396
|
@ -48,12 +48,13 @@ func New(log *logrus.Entry, env env.Interface) Interface {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ka *kubeactions) findGVR(grs []*restmapper.APIGroupResources, groupKind string) []*schema.GroupVersionResource {
|
func (ka *kubeactions) findGVR(grs []*restmapper.APIGroupResources, groupKind, optionalVersion string) []*schema.GroupVersionResource {
|
||||||
var matches []*schema.GroupVersionResource
|
var matches []*schema.GroupVersionResource
|
||||||
|
|
||||||
for _, gr := range grs {
|
for _, gr := range grs {
|
||||||
for version, resources := range gr.VersionedResources {
|
for version, resources := range gr.VersionedResources {
|
||||||
if version != gr.Group.PreferredVersion.Version {
|
if optionalVersion == "" && version != gr.Group.PreferredVersion.Version ||
|
||||||
|
optionalVersion != "" && version != optionalVersion {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,7 +122,7 @@ func (ka *kubeactions) Get(ctx context.Context, oc *api.OpenShiftCluster, groupK
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
gvrs := ka.findGVR(grs, groupKind)
|
gvrs := ka.findGVR(grs, groupKind, "")
|
||||||
|
|
||||||
if len(gvrs) == 0 {
|
if len(gvrs) == 0 {
|
||||||
return nil, api.NewCloudError(http.StatusBadRequest, api.CloudErrorCodeInvalidParameter, "", "The groupKind '%s' was not found.", groupKind)
|
return nil, api.NewCloudError(http.StatusBadRequest, api.CloudErrorCodeInvalidParameter, "", "The groupKind '%s' was not found.", groupKind)
|
||||||
|
@ -147,7 +148,7 @@ func (ka *kubeactions) List(ctx context.Context, oc *api.OpenShiftCluster, group
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
gvrs := ka.findGVR(grs, groupKind)
|
gvrs := ka.findGVR(grs, groupKind, "")
|
||||||
|
|
||||||
if len(gvrs) == 0 {
|
if len(gvrs) == 0 {
|
||||||
return nil, api.NewCloudError(http.StatusBadRequest, api.CloudErrorCodeInvalidParameter, "", "The groupKind '%s' was not found.", groupKind)
|
return nil, api.NewCloudError(http.StatusBadRequest, api.CloudErrorCodeInvalidParameter, "", "The groupKind '%s' was not found.", groupKind)
|
||||||
|
@ -178,7 +179,7 @@ func (ka *kubeactions) CreateOrUpdate(ctx context.Context, oc *api.OpenShiftClus
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
gvrs := ka.findGVR(grs, groupKind)
|
gvrs := ka.findGVR(grs, groupKind, obj.GroupVersionKind().Version)
|
||||||
|
|
||||||
if len(gvrs) == 0 {
|
if len(gvrs) == 0 {
|
||||||
return api.NewCloudError(http.StatusBadRequest, api.CloudErrorCodeInvalidParameter, "", "The groupKind '%s' was not found.", groupKind)
|
return api.NewCloudError(http.StatusBadRequest, api.CloudErrorCodeInvalidParameter, "", "The groupKind '%s' was not found.", groupKind)
|
||||||
|
@ -207,7 +208,7 @@ func (ka *kubeactions) Delete(ctx context.Context, oc *api.OpenShiftCluster, gro
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
gvrs := ka.findGVR(grs, groupKind)
|
gvrs := ka.findGVR(grs, groupKind, "")
|
||||||
|
|
||||||
if len(gvrs) == 0 {
|
if len(gvrs) == 0 {
|
||||||
return api.NewCloudError(http.StatusBadRequest, api.CloudErrorCodeInvalidParameter, "", "The groupKind '%s' was not found.", groupKind)
|
return api.NewCloudError(http.StatusBadRequest, api.CloudErrorCodeInvalidParameter, "", "The groupKind '%s' was not found.", groupKind)
|
||||||
|
|
|
@ -161,7 +161,7 @@ func TestKubeactionsFindGVR(t *testing.T) {
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
ka := &kubeactions{}
|
ka := &kubeactions{}
|
||||||
if got := ka.findGVR(tt.grs, tt.kind); !reflect.DeepEqual(got, tt.want) {
|
if got := ka.findGVR(tt.grs, tt.kind, ""); !reflect.DeepEqual(got, tt.want) {
|
||||||
t.Errorf("kubeactions.findGVR() = %v, want %v", got, tt.want)
|
t.Errorf("kubeactions.findGVR() = %v, want %v", got, tt.want)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
Загрузка…
Ссылка в новой задаче