mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-28 14:07:14 +00:00
Cleanup metav1 conversions
This commit is contained in:
parent
12ee83ed94
commit
d6969d2c55
@ -87,6 +87,7 @@ func addToGroupVersion(scheme *runtime.Scheme) error {
|
||||
&metav1.DeleteOptions{},
|
||||
&metav1.CreateOptions{},
|
||||
&metav1.UpdateOptions{})
|
||||
|
||||
metav1.AddToGroupVersion(scheme, metav1.SchemeGroupVersion)
|
||||
return nil
|
||||
}
|
||||
@ -95,5 +96,4 @@ func addToGroupVersion(scheme *runtime.Scheme) error {
|
||||
// the logic for conversion private.
|
||||
func init() {
|
||||
localSchemeBuilder.Register(addToGroupVersion)
|
||||
localSchemeBuilder.Register(metav1.RegisterConversions)
|
||||
}
|
||||
|
@ -24,7 +24,6 @@ go_test(
|
||||
deps = [
|
||||
"//staging/src/k8s.io/apimachinery/pkg/api/equality:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/labels:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/runtime/serializer/json:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/types:go_default_library",
|
||||
|
@ -26,69 +26,10 @@ import (
|
||||
"k8s.io/apimachinery/pkg/conversion"
|
||||
"k8s.io/apimachinery/pkg/fields"
|
||||
"k8s.io/apimachinery/pkg/labels"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
"k8s.io/apimachinery/pkg/util/intstr"
|
||||
)
|
||||
|
||||
func AddConversionFuncs(scheme *runtime.Scheme) error {
|
||||
return scheme.AddConversionFuncs(
|
||||
Convert_v1_TypeMeta_To_v1_TypeMeta,
|
||||
|
||||
Convert_v1_ListMeta_To_v1_ListMeta,
|
||||
|
||||
Convert_v1_DeleteOptions_To_v1_DeleteOptions,
|
||||
|
||||
Convert_intstr_IntOrString_To_intstr_IntOrString,
|
||||
Convert_Pointer_intstr_IntOrString_To_intstr_IntOrString,
|
||||
Convert_intstr_IntOrString_To_Pointer_intstr_IntOrString,
|
||||
|
||||
Convert_Pointer_v1_Duration_To_v1_Duration,
|
||||
Convert_v1_Duration_To_Pointer_v1_Duration,
|
||||
|
||||
Convert_Slice_string_To_v1_Time,
|
||||
Convert_Slice_string_To_Pointer_v1_Time,
|
||||
|
||||
Convert_v1_Time_To_v1_Time,
|
||||
Convert_v1_MicroTime_To_v1_MicroTime,
|
||||
|
||||
Convert_resource_Quantity_To_resource_Quantity,
|
||||
|
||||
Convert_string_To_labels_Selector,
|
||||
Convert_labels_Selector_To_string,
|
||||
|
||||
Convert_string_To_fields_Selector,
|
||||
Convert_fields_Selector_To_string,
|
||||
|
||||
Convert_Pointer_bool_To_bool,
|
||||
Convert_bool_To_Pointer_bool,
|
||||
|
||||
Convert_Pointer_string_To_string,
|
||||
Convert_string_To_Pointer_string,
|
||||
|
||||
Convert_Pointer_int64_To_int,
|
||||
Convert_int_To_Pointer_int64,
|
||||
|
||||
Convert_Pointer_int32_To_int32,
|
||||
Convert_int32_To_Pointer_int32,
|
||||
|
||||
Convert_Pointer_int64_To_int64,
|
||||
Convert_int64_To_Pointer_int64,
|
||||
|
||||
Convert_Pointer_float64_To_float64,
|
||||
Convert_float64_To_Pointer_float64,
|
||||
|
||||
Convert_Map_string_To_string_To_v1_LabelSelector,
|
||||
Convert_v1_LabelSelector_To_Map_string_To_string,
|
||||
|
||||
Convert_Slice_string_To_Slice_int32,
|
||||
|
||||
Convert_Slice_string_To_Pointer_v1_DeletionPropagation,
|
||||
|
||||
Convert_Slice_string_To_v1_IncludeObjectPolicy,
|
||||
)
|
||||
}
|
||||
|
||||
func Convert_Pointer_float64_To_float64(in **float64, out *float64, s conversion.Scope) error {
|
||||
if *in == nil {
|
||||
*out = 0
|
||||
|
@ -17,13 +17,11 @@ limitations under the License.
|
||||
package v1_test
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
apiequality "k8s.io/apimachinery/pkg/api/equality"
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
)
|
||||
|
||||
func TestMapToLabelSelectorRoundTrip(t *testing.T) {
|
||||
@ -86,49 +84,42 @@ func TestConvertSliceStringToDeletionPropagation(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestUrlValuesToPointerTime(t *testing.T) {
|
||||
scheme := runtime.NewScheme()
|
||||
v1.AddConversionFuncs(scheme)
|
||||
|
||||
type testType struct {
|
||||
Time *v1.Time `json:"time"`
|
||||
}
|
||||
|
||||
func TestConvertSliceStringToPointerTime(t *testing.T) {
|
||||
t1 := v1.Date(1998, time.May, 5, 5, 5, 5, 0, time.UTC)
|
||||
t1String := t1.Format(time.RFC3339)
|
||||
t2 := v1.Date(2000, time.June, 6, 6, 6, 6, 0, time.UTC)
|
||||
t2String := t2.Format(time.RFC3339)
|
||||
|
||||
tcs := []struct {
|
||||
Input url.Values
|
||||
Input []string
|
||||
Output *v1.Time
|
||||
}{
|
||||
{
|
||||
Input: url.Values{},
|
||||
Output: nil,
|
||||
},
|
||||
{
|
||||
Input: url.Values{"time": []string{}},
|
||||
Input: []string{},
|
||||
Output: &v1.Time{},
|
||||
},
|
||||
{
|
||||
Input: url.Values{"time": []string{""}},
|
||||
Input: []string{""},
|
||||
Output: &v1.Time{},
|
||||
},
|
||||
{
|
||||
Input: url.Values{"time": []string{t1String, t2String}},
|
||||
Input: []string{t1String},
|
||||
Output: &t1,
|
||||
},
|
||||
{
|
||||
Input: []string{t1String, t2String},
|
||||
Output: &t1,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range tcs {
|
||||
result := &testType{}
|
||||
if err := scheme.Convert(&tc.Input, &result, nil); err != nil {
|
||||
t.Errorf("Failed to convert []string to *metav1.Time %#v: %v", tc.Input, err)
|
||||
var timePtr *v1.Time
|
||||
if err := v1.Convert_Slice_string_To_Pointer_v1_Time(&tc.Input, &timePtr, nil); err != nil {
|
||||
t.Errorf("Convert_Slice_string_To_Pointer_v1_Time(%#v): %v", tc.Input, err)
|
||||
continue
|
||||
}
|
||||
if !apiequality.Semantic.DeepEqual(result.Time, tc.Output) {
|
||||
t.Errorf("Unexpected output: %v, expected: %v", result.Time, tc.Output)
|
||||
if !apiequality.Semantic.DeepEqual(timePtr, tc.Output) {
|
||||
t.Errorf("slice string to *v1.Time conversion failed: got %#v; want %#v", timePtr, tc.Output)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -53,15 +53,6 @@ var scheme = runtime.NewScheme()
|
||||
// ParameterCodec knows about query parameters used with the meta v1 API spec.
|
||||
var ParameterCodec = runtime.NewParameterCodec(scheme)
|
||||
|
||||
func addEventConversionFuncs(scheme *runtime.Scheme) error {
|
||||
return scheme.AddConversionFuncs(
|
||||
Convert_v1_WatchEvent_To_watch_Event,
|
||||
Convert_v1_InternalEvent_To_v1_WatchEvent,
|
||||
Convert_watch_Event_To_v1_WatchEvent,
|
||||
Convert_v1_WatchEvent_To_v1_InternalEvent,
|
||||
)
|
||||
}
|
||||
|
||||
var optionsTypes = []runtime.Object{
|
||||
&ListOptions{},
|
||||
&ExportOptions{},
|
||||
@ -90,10 +81,8 @@ func AddToGroupVersion(scheme *runtime.Scheme, groupVersion schema.GroupVersion)
|
||||
&APIResourceList{},
|
||||
)
|
||||
|
||||
utilruntime.Must(addEventConversionFuncs(scheme))
|
||||
|
||||
// register manually. This usually goes through the SchemeBuilder, which we cannot use here.
|
||||
utilruntime.Must(AddConversionFuncs(scheme))
|
||||
utilruntime.Must(RegisterConversions(scheme))
|
||||
utilruntime.Must(RegisterDefaults(scheme))
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user