Not rely on default conversions in apiserver test
This commit is contained in:
		| @@ -147,6 +147,8 @@ func addGrouplessTypes() { | |||||||
| 	scheme.AddKnownTypes(grouplessInternalGroupVersion, | 	scheme.AddKnownTypes(grouplessInternalGroupVersion, | ||||||
| 		&genericapitesting.Simple{}, &genericapitesting.SimpleList{}, &metav1.ExportOptions{}, | 		&genericapitesting.Simple{}, &genericapitesting.SimpleList{}, &metav1.ExportOptions{}, | ||||||
| 		&genericapitesting.SimpleGetOptions{}, &genericapitesting.SimpleRoot{}) | 		&genericapitesting.SimpleGetOptions{}, &genericapitesting.SimpleRoot{}) | ||||||
|  |  | ||||||
|  | 	utilruntime.Must(genericapitesting.RegisterConversions(scheme)) | ||||||
| } | } | ||||||
|  |  | ||||||
| func addTestTypes() { | func addTestTypes() { | ||||||
| @@ -166,6 +168,8 @@ func addTestTypes() { | |||||||
| 	scheme.AddKnownTypes(testGroup2Version, &genericapitesting.SimpleXGSubresource{}, &metav1.ExportOptions{}) | 	scheme.AddKnownTypes(testGroup2Version, &genericapitesting.SimpleXGSubresource{}, &metav1.ExportOptions{}) | ||||||
| 	scheme.AddKnownTypes(testInternalGroup2Version, &genericapitesting.SimpleXGSubresource{}, &metav1.ExportOptions{}) | 	scheme.AddKnownTypes(testInternalGroup2Version, &genericapitesting.SimpleXGSubresource{}, &metav1.ExportOptions{}) | ||||||
| 	metav1.AddToGroupVersion(scheme, testGroupVersion) | 	metav1.AddToGroupVersion(scheme, testGroupVersion) | ||||||
|  |  | ||||||
|  | 	utilruntime.Must(genericapitesting.RegisterConversions(scheme)) | ||||||
| } | } | ||||||
|  |  | ||||||
| func addNewTestTypes() { | func addNewTestTypes() { | ||||||
| @@ -175,6 +179,8 @@ func addNewTestTypes() { | |||||||
| 		&examplev1.Pod{}, | 		&examplev1.Pod{}, | ||||||
| 	) | 	) | ||||||
| 	metav1.AddToGroupVersion(scheme, newGroupVersion) | 	metav1.AddToGroupVersion(scheme, newGroupVersion) | ||||||
|  |  | ||||||
|  | 	utilruntime.Must(genericapitesting.RegisterConversions(scheme)) | ||||||
| } | } | ||||||
|  |  | ||||||
| func init() { | func init() { | ||||||
|   | |||||||
| @@ -8,6 +8,7 @@ load( | |||||||
| go_library( | go_library( | ||||||
|     name = "go_default_library", |     name = "go_default_library", | ||||||
|     srcs = [ |     srcs = [ | ||||||
|  |         "conversion.go", | ||||||
|         "doc.go", |         "doc.go", | ||||||
|         "types.go", |         "types.go", | ||||||
|         "zz_generated.deepcopy.go", |         "zz_generated.deepcopy.go", | ||||||
| @@ -16,6 +17,7 @@ go_library( | |||||||
|     importpath = "k8s.io/apiserver/pkg/endpoints/testing", |     importpath = "k8s.io/apiserver/pkg/endpoints/testing", | ||||||
|     deps = [ |     deps = [ | ||||||
|         "//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library", |         "//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library", | ||||||
|  |         "//staging/src/k8s.io/apimachinery/pkg/conversion:go_default_library", | ||||||
|         "//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library", |         "//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library", | ||||||
|     ], |     ], | ||||||
| ) | ) | ||||||
|   | |||||||
| @@ -0,0 +1,60 @@ | |||||||
|  | /* | ||||||
|  | Copyright 2020 The Kubernetes Authors. | ||||||
|  |  | ||||||
|  | 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 testing | ||||||
|  |  | ||||||
|  | import ( | ||||||
|  | 	"net/url" | ||||||
|  |  | ||||||
|  | 	"k8s.io/apimachinery/pkg/conversion" | ||||||
|  | 	"k8s.io/apimachinery/pkg/runtime" | ||||||
|  | ) | ||||||
|  |  | ||||||
|  | func convertUrlValuesToSimpleGetOptions(in *url.Values, out *SimpleGetOptions, s conversion.Scope) error { | ||||||
|  | 	// Skip TypeMeta field. | ||||||
|  |  | ||||||
|  | 	if values, ok := map[string][]string(*in)["param1"]; ok && len(values) > 0 { | ||||||
|  | 		if err := runtime.Convert_Slice_string_To_string(&values, &out.Param1, s); err != nil { | ||||||
|  | 			return err | ||||||
|  | 		} | ||||||
|  | 	} else { | ||||||
|  | 		out.Param1 = "" | ||||||
|  | 	} | ||||||
|  | 	if values, ok := map[string][]string(*in)["param2"]; ok && len(values) > 0 { | ||||||
|  | 		if err := runtime.Convert_Slice_string_To_string(&values, &out.Param2, s); err != nil { | ||||||
|  | 			return err | ||||||
|  | 		} | ||||||
|  | 	} else { | ||||||
|  | 		out.Param2 = "" | ||||||
|  | 	} | ||||||
|  | 	if values, ok := map[string][]string(*in)["atAPath"]; ok && len(values) > 0 { | ||||||
|  | 		if err := runtime.Convert_Slice_string_To_string(&values, &out.Path, s); err != nil { | ||||||
|  | 			return err | ||||||
|  | 		} | ||||||
|  | 	} else { | ||||||
|  | 		out.Path = "" | ||||||
|  | 	} | ||||||
|  | 	return nil | ||||||
|  | } | ||||||
|  |  | ||||||
|  | func RegisterConversions(s *runtime.Scheme) error { | ||||||
|  | 	if err := s.AddConversionFunc((*url.Values)(nil), (*SimpleGetOptions)(nil), func(a, b interface{}, scope conversion.Scope) error { | ||||||
|  | 		return convertUrlValuesToSimpleGetOptions(a.(*url.Values), b.(*SimpleGetOptions), scope) | ||||||
|  | 	}); err != nil { | ||||||
|  | 		return err | ||||||
|  | 	} | ||||||
|  | 	return nil | ||||||
|  | } | ||||||
		Reference in New Issue
	
	Block a user
	 wojtekt
					wojtekt