Skip to content

Commit a9fb448

Browse files
authored
Merge pull request kubernetes#84670 from wojtek-t/remove_conversion_funcs_3
Autogenerate missing conversions for corev1 options types
2 parents 0685cf2 + 0b4b7d9 commit a9fb448

File tree

6 files changed

+286
-0
lines changed

6 files changed

+286
-0
lines changed

pkg/apis/core/v1/zz_generated.conversion.go

Lines changed: 209 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

staging/src/k8s.io/api/core/v1/types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4774,6 +4774,7 @@ type Preconditions struct {
47744774
UID *types.UID `json:"uid,omitempty" protobuf:"bytes,1,opt,name=uid,casttype=k8s.io/apimachinery/pkg/types.UID"`
47754775
}
47764776

4777+
// +k8s:conversion-gen:explicit-from=net/url.Values
47774778
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
47784779

47794780
// PodLogOptions is the query options for a Pod's logs REST call.
@@ -4825,6 +4826,7 @@ type PodLogOptions struct {
48254826
InsecureSkipTLSVerifyBackend bool `json:"insecureSkipTLSVerifyBackend,omitempty" protobuf:"varint,9,opt,name=insecureSkipTLSVerifyBackend"`
48264827
}
48274828

4829+
// +k8s:conversion-gen:explicit-from=net/url.Values
48284830
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
48294831

48304832
// PodAttachOptions is the query options to a Pod's remote attach call.
@@ -4862,6 +4864,7 @@ type PodAttachOptions struct {
48624864
Container string `json:"container,omitempty" protobuf:"bytes,5,opt,name=container"`
48634865
}
48644866

4867+
// +k8s:conversion-gen:explicit-from=net/url.Values
48654868
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
48664869

48674870
// PodExecOptions is the query options to a Pod's remote exec call.
@@ -4900,6 +4903,7 @@ type PodExecOptions struct {
49004903
Command []string `json:"command" protobuf:"bytes,6,rep,name=command"`
49014904
}
49024905

4906+
// +k8s:conversion-gen:explicit-from=net/url.Values
49034907
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
49044908

49054909
// PodPortForwardOptions is the query options to a Pod's port forward call

staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ go_test(
2424
deps = [
2525
"//staging/src/k8s.io/apimachinery/pkg/api/equality:go_default_library",
2626
"//staging/src/k8s.io/apimachinery/pkg/labels:go_default_library",
27+
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",
2728
"//staging/src/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
2829
"//staging/src/k8s.io/apimachinery/pkg/runtime/serializer/json:go_default_library",
2930
"//staging/src/k8s.io/apimachinery/pkg/types:go_default_library",

staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/conversion.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ func AddConversionFuncs(scheme *runtime.Scheme) error {
4545
Convert_v1_Duration_To_Pointer_v1_Duration,
4646

4747
Convert_Slice_string_To_v1_Time,
48+
Convert_Slice_string_To_Pointer_v1_Time,
4849

4950
Convert_v1_Time_To_v1_Time,
5051
Convert_v1_MicroTime_To_v1_MicroTime,
@@ -263,6 +264,22 @@ func Convert_Slice_string_To_v1_Time(in *[]string, out *Time, s conversion.Scope
263264
return out.UnmarshalQueryParameter(str)
264265
}
265266

267+
func Convert_Slice_string_To_Pointer_v1_Time(in *[]string, out **Time, s conversion.Scope) error {
268+
if in == nil {
269+
return nil
270+
}
271+
str := ""
272+
if len(*in) > 0 {
273+
str = (*in)[0]
274+
}
275+
temp := Time{}
276+
if err := temp.UnmarshalQueryParameter(str); err != nil {
277+
return err
278+
}
279+
*out = &temp
280+
return nil
281+
}
282+
266283
func Convert_string_To_labels_Selector(in *string, out *labels.Selector, s conversion.Scope) error {
267284
selector, err := labels.Parse(*in)
268285
if err != nil {

staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/conversion_test.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,13 @@ limitations under the License.
1717
package v1_test
1818

1919
import (
20+
"net/url"
2021
"testing"
22+
"time"
2123

2224
apiequality "k8s.io/apimachinery/pkg/api/equality"
2325
"k8s.io/apimachinery/pkg/apis/meta/v1"
26+
"k8s.io/apimachinery/pkg/runtime"
2427
)
2528

2629
func TestMapToLabelSelectorRoundTrip(t *testing.T) {
@@ -82,3 +85,50 @@ func TestConvertSliceStringToDeletionPropagation(t *testing.T) {
8285
}
8386
}
8487
}
88+
89+
func TestUrlValuesToPointerTime(t *testing.T) {
90+
scheme := runtime.NewScheme()
91+
v1.AddConversionFuncs(scheme)
92+
93+
type testType struct {
94+
Time *v1.Time `json:"time"`
95+
}
96+
97+
t1 := v1.Date(1998, time.May, 5, 5, 5, 5, 0, time.UTC)
98+
t1String := t1.Format(time.RFC3339)
99+
t2 := v1.Date(2000, time.June, 6, 6, 6, 6, 0, time.UTC)
100+
t2String := t2.Format(time.RFC3339)
101+
102+
tcs := []struct {
103+
Input url.Values
104+
Output *v1.Time
105+
}{
106+
{
107+
Input: url.Values{},
108+
Output: nil,
109+
},
110+
{
111+
Input: url.Values{"time": []string{}},
112+
Output: &v1.Time{},
113+
},
114+
{
115+
Input: url.Values{"time": []string{""}},
116+
Output: &v1.Time{},
117+
},
118+
{
119+
Input: url.Values{"time": []string{t1String, t2String}},
120+
Output: &t1,
121+
},
122+
}
123+
124+
for _, tc := range tcs {
125+
result := &testType{}
126+
if err := scheme.Convert(&tc.Input, &result, nil); err != nil {
127+
t.Errorf("Failed to convert []string to *metav1.Time %#v: %v", tc.Input, err)
128+
continue
129+
}
130+
if !apiequality.Semantic.DeepEqual(result.Time, tc.Output) {
131+
t.Errorf("Unexpected output: %v, expected: %v", result.Time, tc.Output)
132+
}
133+
}
134+
}

staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/zz_generated.conversion.go

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)