From efde94a0bcffdf9a6321dd420d51e925858fdd16 Mon Sep 17 00:00:00 2001 From: Clayton Coleman Date: Sun, 24 Mar 2019 21:21:55 -0400 Subject: [PATCH 1/2] Add ListMeta to PartialObjectMetadataList Unfortunately the proto id is now inconsistent with other "correct" objects, but to change it will require a breaking serialization change. Worth considering. --- .../pkg/apis/meta/v1beta1/generated.pb.go | 93 ++++++++++++++----- .../pkg/apis/meta/v1beta1/generated.proto | 5 + .../pkg/apis/meta/v1beta1/types.go | 6 +- .../meta/v1beta1/zz_generated.deepcopy.go | 1 + 4 files changed, 79 insertions(+), 26 deletions(-) diff --git a/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1beta1/generated.pb.go b/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1beta1/generated.pb.go index 47c03d69b96..2c242fef71a 100644 --- a/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1beta1/generated.pb.go +++ b/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1beta1/generated.pb.go @@ -122,6 +122,14 @@ func (m *PartialObjectMetadataList) MarshalTo(dAtA []byte) (int, error) { i += n } } + dAtA[i] = 0x12 + i++ + i = encodeVarintGenerated(dAtA, i, uint64(m.ListMeta.Size())) + n2, err := m.ListMeta.MarshalTo(dAtA[i:]) + if err != nil { + return 0, err + } + i += n2 return i, nil } @@ -173,6 +181,8 @@ func (m *PartialObjectMetadataList) Size() (n int) { n += 1 + l + sovGenerated(uint64(l)) } } + l = m.ListMeta.Size() + n += 1 + l + sovGenerated(uint64(l)) return n } @@ -213,6 +223,7 @@ func (this *PartialObjectMetadataList) String() string { } s := strings.Join([]string{`&PartialObjectMetadataList{`, `Items:` + strings.Replace(fmt.Sprintf("%v", this.Items), "PartialObjectMetadata", "PartialObjectMetadata", 1) + `,`, + `ListMeta:` + strings.Replace(strings.Replace(this.ListMeta.String(), "ListMeta", "k8s_io_apimachinery_pkg_apis_meta_v1.ListMeta", 1), `&`, ``, 1) + `,`, `}`, }, "") return s @@ -375,6 +386,36 @@ func (m *PartialObjectMetadataList) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ListMeta", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenerated + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenerated + } + postIndex := iNdEx + msglen + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.ListMeta.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipGenerated(dAtA[iNdEx:]) @@ -585,29 +626,31 @@ func init() { } var fileDescriptorGenerated = []byte{ - // 375 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x91, 0xcd, 0x0a, 0xd3, 0x40, - 0x10, 0xc7, 0xb3, 0x48, 0xd1, 0x6e, 0xed, 0x25, 0x22, 0xd4, 0x1e, 0x36, 0xa5, 0xa7, 0x0a, 0x76, - 0xd7, 0x16, 0x11, 0x8f, 0x92, 0x5b, 0x41, 0x69, 0x09, 0x9e, 0x3c, 0xb9, 0x49, 0xc6, 0x74, 0xcd, - 0xc7, 0x86, 0xec, 0xa6, 0xd0, 0x8b, 0xf8, 0x08, 0x3e, 0x56, 0x8f, 0x3d, 0xf6, 0x14, 0x6c, 0x7c, - 0x0b, 0x4f, 0x92, 0x0f, 0xec, 0x87, 0x15, 0x7b, 0x9b, 0xf9, 0x0f, 0xbf, 0x5f, 0x66, 0xb2, 0xd8, - 0x09, 0xdf, 0x28, 0x2a, 0x24, 0x0b, 0x73, 0x17, 0xb2, 0x04, 0x34, 0x28, 0xb6, 0x81, 0xc4, 0x97, - 0x19, 0x6b, 0x07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xa5, 0xd3, 0x98, 0xc7, 0x2e, 0x7e, 0xfc, 0x81, - 0xbb, 0x11, 0x2c, 0x53, 0x2d, 0x64, 0xa2, 0x4c, 0x07, 0xf7, 0x45, 0xe2, 0x45, 0xb9, 0x0f, 0x0d, - 0x5a, 0x9f, 0xdd, 0xb5, 0x5f, 0xb4, 0x47, 0xf4, 0x17, 0xe7, 0xc3, 0x5f, 0x85, 0xf5, 0xe4, 0x22, - 0x58, 0xc9, 0x48, 0x78, 0x5b, 0xe7, 0x52, 0x61, 0x4f, 0x77, 0x47, 0x62, 0xec, 0x8f, 0xc4, 0x38, - 0x1c, 0x89, 0xf1, 0xad, 0x24, 0x68, 0x57, 0x12, 0xb4, 0x2f, 0x09, 0x3a, 0x94, 0x04, 0xfd, 0x28, - 0x09, 0xfa, 0xfe, 0x93, 0x18, 0x1f, 0x1f, 0xb6, 0xab, 0xff, 0x0e, 0x00, 0x00, 0xff, 0xff, 0xf3, - 0xe1, 0xde, 0x86, 0xdb, 0x02, 0x00, 0x00, + // 402 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x91, 0x4f, 0x8b, 0xd3, 0x40, + 0x18, 0xc6, 0x33, 0xca, 0xe2, 0xee, 0xac, 0x0b, 0x12, 0x11, 0xd6, 0x1e, 0x26, 0xcb, 0x9e, 0x2a, + 0xd8, 0x19, 0x5b, 0x44, 0x3c, 0x4a, 0x6e, 0x05, 0xa5, 0x25, 0x78, 0x12, 0x0f, 0x4e, 0x92, 0xd7, + 0x74, 0xcc, 0x9f, 0x09, 0x99, 0x49, 0xa1, 0x37, 0x3f, 0x82, 0x1f, 0xab, 0xc7, 0x1e, 0x7b, 0x90, + 0x60, 0xe3, 0xb7, 0xf0, 0x24, 0xf9, 0xa3, 0x4d, 0x6b, 0x65, 0x73, 0x9b, 0xf7, 0x79, 0x79, 0x7e, + 0x79, 0x9e, 0x37, 0xd8, 0x09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, 0xee, 0x0f, 0x2f, 0x27, + 0x6f, 0x68, 0xef, 0x3f, 0x44, 0x4f, 0x42, 0xed, 0x8b, 0xb2, 0xb0, 0xce, 0xa6, 0x15, 0xd2, 0x69, + 0xc8, 0xe6, 0xc7, 0x4e, 0xc5, 0x7b, 0x75, 0x45, 0xda, 0xaf, 0x62, 0x15, 0xb0, 0x2e, 0xf8, 0xa8, + 0x2d, 0x78, 0xfe, 0x47, 0xe9, 0xd4, 0x73, 0xf1, 0xc3, 0xf7, 0xdc, 0x8d, 0x60, 0x96, 0x6a, 0x21, + 0x13, 0x65, 0x3a, 0xf8, 0x4a, 0x24, 0x5e, 0x94, 0xfb, 0xd0, 0x04, 0xab, 0xaf, 0x7a, 0x61, 0x3f, + 0x6f, 0x11, 0x57, 0xd3, 0xee, 0xf2, 0x57, 0x61, 0x3d, 0x3e, 0x10, 0xe6, 0x32, 0x12, 0xde, 0xca, + 0x39, 0x44, 0xd8, 0xa3, 0xf5, 0x8e, 0x18, 0x9b, 0x1d, 0x31, 0xb6, 0x3b, 0x62, 0x7c, 0x2d, 0x09, + 0x5a, 0x97, 0x04, 0x6d, 0x4a, 0x82, 0xb6, 0x25, 0x41, 0x3f, 0x4a, 0x82, 0xbe, 0xfd, 0x24, 0xc6, + 0x87, 0x07, 0xed, 0x61, 0x7e, 0x07, 0x00, 0x00, 0xff, 0xff, 0xf8, 0x78, 0xd8, 0x63, 0x3a, 0x03, + 0x00, 0x00, } diff --git a/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1beta1/generated.proto b/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1beta1/generated.proto index 83be997904e..5097ad350da 100644 --- a/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1beta1/generated.proto +++ b/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1beta1/generated.proto @@ -41,6 +41,11 @@ message PartialObjectMetadata { // PartialObjectMetadataList contains a list of objects containing only their metadata // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object message PartialObjectMetadataList { + // Standard list metadata. + // More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#types-kinds + // +optional + optional k8s.io.apimachinery.pkg.apis.meta.v1.ListMeta metadata = 2; + // items contains each of the included items. repeated PartialObjectMetadata items = 1; } diff --git a/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1beta1/types.go b/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1beta1/types.go index 0462f087e64..2750f65f829 100644 --- a/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1beta1/types.go +++ b/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1beta1/types.go @@ -18,7 +18,7 @@ limitations under the License. package v1beta1 import ( - "k8s.io/apimachinery/pkg/apis/meta/v1" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" ) @@ -159,6 +159,10 @@ type PartialObjectMetadata struct { // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object type PartialObjectMetadataList struct { v1.TypeMeta `json:",inline"` + // Standard list metadata. + // More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#types-kinds + // +optional + v1.ListMeta `json:"metadata,omitempty" protobuf:"bytes,2,opt,name=metadata"` // items contains each of the included items. Items []*PartialObjectMetadata `json:"items" protobuf:"bytes,1,rep,name=items"` diff --git a/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1beta1/zz_generated.deepcopy.go b/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1beta1/zz_generated.deepcopy.go index b77db1b150d..74c370149f2 100644 --- a/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1beta1/zz_generated.deepcopy.go +++ b/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1beta1/zz_generated.deepcopy.go @@ -54,6 +54,7 @@ func (in *PartialObjectMetadata) DeepCopyObject() runtime.Object { func (in *PartialObjectMetadataList) DeepCopyInto(out *PartialObjectMetadataList) { *out = *in out.TypeMeta = in.TypeMeta + out.ListMeta = in.ListMeta if in.Items != nil { in, out := &in.Items, &out.Items *out = make([]*PartialObjectMetadata, len(*in)) From 6801ce990a48196d871f6b46e1a08938025ce7c5 Mon Sep 17 00:00:00 2001 From: Clayton Coleman Date: Sun, 24 Mar 2019 21:29:20 -0400 Subject: [PATCH 2/2] Set list meta on PartialObjectMetadataList during transform --- .../pkg/apis/meta/v1beta1/types_swagger_doc_generated.go | 5 +++-- staging/src/k8s.io/apiserver/pkg/endpoints/apiserver_test.go | 4 ++++ .../src/k8s.io/apiserver/pkg/endpoints/handlers/response.go | 5 +++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1beta1/types_swagger_doc_generated.go b/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1beta1/types_swagger_doc_generated.go index 7394535d9d9..d5bb86e84d1 100644 --- a/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1beta1/types_swagger_doc_generated.go +++ b/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1beta1/types_swagger_doc_generated.go @@ -37,8 +37,9 @@ func (PartialObjectMetadata) SwaggerDoc() map[string]string { } var map_PartialObjectMetadataList = map[string]string{ - "": "PartialObjectMetadataList contains a list of objects containing only their metadata", - "items": "items contains each of the included items.", + "": "PartialObjectMetadataList contains a list of objects containing only their metadata", + "metadata": "Standard list metadata. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#types-kinds", + "items": "items contains each of the included items.", } func (PartialObjectMetadataList) SwaggerDoc() map[string]string { 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 e65a0566e80..61583fab34b 100644 --- a/staging/src/k8s.io/apiserver/pkg/endpoints/apiserver_test.go +++ b/staging/src/k8s.io/apiserver/pkg/endpoints/apiserver_test.go @@ -2269,6 +2269,10 @@ func TestGetPartialObjectMetadata(t *testing.T) { list: true, accept: runtime.ContentTypeJSON + ";as=PartialObjectMetadataList;v=v1beta1;g=meta.k8s.io", expected: &metav1beta1.PartialObjectMetadataList{ + ListMeta: metav1.ListMeta{ + ResourceVersion: "10", + SelfLink: "/test/link", + }, Items: []*metav1beta1.PartialObjectMetadata{ { TypeMeta: metav1.TypeMeta{APIVersion: "meta.k8s.io/v1beta1", Kind: "PartialObjectMetadata"}, diff --git a/staging/src/k8s.io/apiserver/pkg/endpoints/handlers/response.go b/staging/src/k8s.io/apiserver/pkg/endpoints/handlers/response.go index 0c00fbd39d0..214dbc1e7d2 100644 --- a/staging/src/k8s.io/apiserver/pkg/endpoints/handlers/response.go +++ b/staging/src/k8s.io/apiserver/pkg/endpoints/handlers/response.go @@ -196,6 +196,11 @@ func asV1Beta1PartialObjectMetadataList(result runtime.Object) (runtime.Object, return nil, newNotAcceptableError(fmt.Sprintf("you requested PartialObjectMetadataList, but the requested object is not a list (%T)", result)) } list := &metav1beta1.PartialObjectMetadataList{} + if li, ok := result.(metav1.ListInterface); ok { + list.SelfLink = li.GetSelfLink() + list.ResourceVersion = li.GetResourceVersion() + list.Continue = li.GetContinue() + } err := meta.EachListItem(result, func(obj runtime.Object) error { m, err := meta.Accessor(obj) if err != nil {