From a7a551148071bb4d87f73c7b6c0f4bd7cc829b22 Mon Sep 17 00:00:00 2001 From: Jordan Liggitt Date: Fri, 4 Aug 2017 13:25:23 -0400 Subject: [PATCH] Fix includeObject parameter parsing --- .../apimachinery/pkg/apis/meta/v1alpha1/BUILD | 1 + .../pkg/apis/meta/v1alpha1/conversion.go | 27 +++++++++++++++++++ .../pkg/apis/meta/v1alpha1/register.go | 6 +++++ .../apiserver/pkg/endpoints/apiserver_test.go | 22 ++++++++++++--- 4 files changed, 53 insertions(+), 3 deletions(-) create mode 100644 staging/src/k8s.io/apimachinery/pkg/apis/meta/v1alpha1/conversion.go diff --git a/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1alpha1/BUILD b/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1alpha1/BUILD index 0988e6cbda..87a10d4e5a 100644 --- a/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1alpha1/BUILD +++ b/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1alpha1/BUILD @@ -10,6 +10,7 @@ load( go_library( name = "go_default_library", srcs = [ + "conversion.go", "deepcopy.go", "doc.go", "generated.pb.go", diff --git a/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1alpha1/conversion.go b/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1alpha1/conversion.go new file mode 100644 index 0000000000..f8ecc7c26c --- /dev/null +++ b/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1alpha1/conversion.go @@ -0,0 +1,27 @@ +/* +Copyright 2017 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 v1alpha1 + +import "k8s.io/apimachinery/pkg/conversion" + +// Convert_Slice_string_To_v1alpha1_IncludeObjectPolicy allows converting a URL query parameter value +func Convert_Slice_string_To_v1alpha1_IncludeObjectPolicy(input *[]string, out *IncludeObjectPolicy, s conversion.Scope) error { + if len(*input) > 0 { + *out = IncludeObjectPolicy((*input)[0]) + } + return nil +} diff --git a/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1alpha1/register.go b/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1alpha1/register.go index 89f08f3837..dab66bf088 100644 --- a/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1alpha1/register.go +++ b/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1alpha1/register.go @@ -46,6 +46,12 @@ func init() { &PartialObjectMetadataList{}, ) + if err := scheme.AddConversionFuncs( + Convert_Slice_string_To_v1alpha1_IncludeObjectPolicy, + ); err != nil { + panic(err) + } + // register manually. This usually goes through the SchemeBuilder, which we cannot use here. //scheme.AddGeneratedDeepCopyFuncs(GetGeneratedDeepCopyFuncs()...) } diff --git a/staging/src/k8s.io/apiserver/pkg/endpoints/apiserver_test.go b/staging/src/k8s.io/apiserver/pkg/endpoints/apiserver_test.go index 19980d543d..9da48d7f7e 100644 --- a/staging/src/k8s.io/apiserver/pkg/endpoints/apiserver_test.go +++ b/staging/src/k8s.io/apiserver/pkg/endpoints/apiserver_test.go @@ -1885,6 +1885,20 @@ func TestGetTable(t *testing.T) { }, }, }, + { + accept: runtime.ContentTypeJSON + ";as=Table;v=v1alpha1;g=meta.k8s.io", + params: url.Values{"includeObject": []string{"Metadata"}}, + expected: &metav1alpha1.Table{ + TypeMeta: metav1.TypeMeta{Kind: "Table", APIVersion: "meta.k8s.io/v1alpha1"}, + ColumnDefinitions: []metav1alpha1.TableColumnDefinition{ + {Name: "Name", Type: "string", Description: metaDoc["name"]}, + {Name: "Created At", Type: "date", Description: metaDoc["creationTimestamp"]}, + }, + Rows: []metav1alpha1.TableRow{ + {Cells: []interface{}{"foo1", now.Time.UTC().Format(time.RFC3339)}, Object: runtime.RawExtension{Raw: encodedBody}}, + }, + }, + }, } for i, test := range tests { u, err := url.Parse(server.URL + "/" + prefix + "/" + testGroupVersion.Group + "/" + testGroupVersion.Version + "/namespaces/default/simple/id") @@ -1901,18 +1915,20 @@ func TestGetTable(t *testing.T) { } if test.statusCode != 0 { if resp.StatusCode != test.statusCode { - t.Errorf("%d: unexpected response: %#v", resp) + t.Errorf("%d: unexpected response: %#v", i, resp) } continue } if resp.StatusCode != http.StatusOK { - t.Errorf("%d: unexpected response: %#v", resp) + t.Errorf("%d: unexpected response: %#v", i, resp) } var itemOut metav1alpha1.Table - if _, err = extractBody(resp, &itemOut); err != nil { + body, err := extractBody(resp, &itemOut) + if err != nil { t.Fatal(err) } if !reflect.DeepEqual(test.expected, &itemOut) { + t.Log(body) t.Errorf("%d: did not match: %s", i, diff.ObjectReflectDiff(test.expected, &itemOut)) } }