mirror of https://github.com/k3s-io/k3s
Make ListMeta.RemainingItemCount a pointer (*int64) to make sure it's omitted
when serialized to proto. The SetRemainingItemCount() and GetRemainingItemCount() still takes and returns an int64 to make developers life easier.k3s-v1.15.3
parent
01a5ec3d3d
commit
e28a1072d9
|
@ -112,7 +112,7 @@ func (h *HumanReadablePrinter) GenerateTable(obj runtime.Object, options PrintOp
|
|||
table.ResourceVersion = m.GetResourceVersion()
|
||||
table.SelfLink = m.GetSelfLink()
|
||||
table.Continue = m.GetContinue()
|
||||
table.RemainingItemCount = m.GetRemainingItemCount()
|
||||
table.SetRemainingItemCount(m.GetRemainingItemCount())
|
||||
} else {
|
||||
if m, err := meta.CommonAccessor(obj); err == nil {
|
||||
table.ResourceVersion = m.GetResourceVersion()
|
||||
|
|
|
@ -87,7 +87,7 @@ func (c *convertor) ConvertToTable(ctx context.Context, obj runtime.Object, tabl
|
|||
table.ResourceVersion = m.GetResourceVersion()
|
||||
table.SelfLink = m.GetSelfLink()
|
||||
table.Continue = m.GetContinue()
|
||||
table.RemainingItemCount = m.GetRemainingItemCount()
|
||||
table.SetRemainingItemCount(m.GetRemainingItemCount())
|
||||
} else {
|
||||
if m, err := meta.CommonAccessor(obj); err == nil {
|
||||
table.ResourceVersion = m.GetResourceVersion()
|
||||
|
|
|
@ -115,8 +115,20 @@ func (meta *ListMeta) GetSelfLink() string { return meta.SelfLink
|
|||
func (meta *ListMeta) SetSelfLink(selfLink string) { meta.SelfLink = selfLink }
|
||||
func (meta *ListMeta) GetContinue() string { return meta.Continue }
|
||||
func (meta *ListMeta) SetContinue(c string) { meta.Continue = c }
|
||||
func (meta *ListMeta) GetRemainingItemCount() int64 { return meta.RemainingItemCount }
|
||||
func (meta *ListMeta) SetRemainingItemCount(c int64) { meta.RemainingItemCount = c }
|
||||
|
||||
func (meta *ListMeta) GetRemainingItemCount() int64 {
|
||||
if meta.RemainingItemCount != nil {
|
||||
return *meta.RemainingItemCount
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (meta *ListMeta) SetRemainingItemCount(c int64) {
|
||||
if meta.RemainingItemCount == nil {
|
||||
meta.RemainingItemCount = new(int64)
|
||||
}
|
||||
*meta.RemainingItemCount = c
|
||||
}
|
||||
|
||||
func (obj *TypeMeta) GetObjectKind() schema.ObjectKind { return obj }
|
||||
|
||||
|
|
|
@ -88,7 +88,7 @@ type ListMeta struct {
|
|||
// because it is unpaginated or because this is the last page), then there are no more remaining
|
||||
// items and this field will also be unset. Servers older than v1.15 do not set this field.
|
||||
// +optional
|
||||
RemainingItemCount int64 `json:"remainingItemCount,omitempty" protobuf:"bytes,4,opt,name=remainingItemCount"`
|
||||
RemainingItemCount *int64 `json:"remainingItemCount,omitempty" protobuf:"bytes,4,opt,name=remainingItemCount"`
|
||||
}
|
||||
|
||||
// These are internal finalizer values for Kubernetes-like APIs, must be qualified name unless defined here
|
||||
|
|
|
@ -20,8 +20,7 @@ import (
|
|||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/google/gofuzz"
|
||||
|
||||
fuzz "github.com/google/gofuzz"
|
||||
"k8s.io/apimachinery/pkg/api/meta"
|
||||
metafuzzer "k8s.io/apimachinery/pkg/apis/meta/fuzzer"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
@ -202,7 +201,7 @@ type InternalTypeMeta struct {
|
|||
SelfLink string `json:"selfLink,omitempty"`
|
||||
ResourceVersion string `json:"resourceVersion,omitempty"`
|
||||
Continue string `json:"next,omitempty"`
|
||||
RemainingItemCount int64 `json:"remainingItemCount,omitempty"`
|
||||
RemainingItemCount *int64 `json:"remainingItemCount,omitempty"`
|
||||
APIVersion string `json:"apiVersion,omitempty"`
|
||||
Labels map[string]string `json:"labels,omitempty"`
|
||||
Annotations map[string]string `json:"annotations,omitempty"`
|
||||
|
@ -210,14 +209,26 @@ type InternalTypeMeta struct {
|
|||
OwnerReferences []metav1.OwnerReference `json:"ownerReferences,omitempty"`
|
||||
}
|
||||
|
||||
func (m *InternalTypeMeta) GetResourceVersion() string { return m.ResourceVersion }
|
||||
func (m *InternalTypeMeta) SetResourceVersion(rv string) { m.ResourceVersion = rv }
|
||||
func (m *InternalTypeMeta) GetSelfLink() string { return m.SelfLink }
|
||||
func (m *InternalTypeMeta) SetSelfLink(link string) { m.SelfLink = link }
|
||||
func (m *InternalTypeMeta) GetContinue() string { return m.Continue }
|
||||
func (m *InternalTypeMeta) SetContinue(c string) { m.Continue = c }
|
||||
func (m *InternalTypeMeta) GetRemainingItemCount() int64 { return m.RemainingItemCount }
|
||||
func (m *InternalTypeMeta) SetRemainingItemCount(c int64) { m.RemainingItemCount = c }
|
||||
func (m *InternalTypeMeta) GetResourceVersion() string { return m.ResourceVersion }
|
||||
func (m *InternalTypeMeta) SetResourceVersion(rv string) { m.ResourceVersion = rv }
|
||||
func (m *InternalTypeMeta) GetSelfLink() string { return m.SelfLink }
|
||||
func (m *InternalTypeMeta) SetSelfLink(link string) { m.SelfLink = link }
|
||||
func (m *InternalTypeMeta) GetContinue() string { return m.Continue }
|
||||
func (m *InternalTypeMeta) SetContinue(c string) { m.Continue = c }
|
||||
|
||||
func (m *InternalTypeMeta) GetRemainingItemCount() int64 {
|
||||
if m.RemainingItemCount != nil {
|
||||
return *m.RemainingItemCount
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (m *InternalTypeMeta) SetRemainingItemCount(c int64) {
|
||||
if m.RemainingItemCount == nil {
|
||||
m.RemainingItemCount = new(int64)
|
||||
}
|
||||
*m.RemainingItemCount = c
|
||||
}
|
||||
|
||||
type MyAPIObject struct {
|
||||
TypeMeta InternalTypeMeta `json:",inline"`
|
||||
|
|
|
@ -67,7 +67,7 @@ func (c defaultTableConvertor) ConvertToTable(ctx context.Context, object runtim
|
|||
table.ResourceVersion = m.GetResourceVersion()
|
||||
table.SelfLink = m.GetSelfLink()
|
||||
table.Continue = m.GetContinue()
|
||||
table.RemainingItemCount = m.GetRemainingItemCount()
|
||||
table.SetRemainingItemCount(m.GetRemainingItemCount())
|
||||
} else {
|
||||
if m, err := meta.CommonAccessor(object); err == nil {
|
||||
table.ResourceVersion = m.GetResourceVersion()
|
||||
|
|
|
@ -1062,7 +1062,7 @@ func TestList(t *testing.T) {
|
|||
t.Errorf("(%s): length of list want=%d, got=%d", tt.name, len(tt.expectedOut), len(out.Items))
|
||||
continue
|
||||
}
|
||||
if e, a := tt.expectedRemainingItemCount, out.ListMeta.RemainingItemCount; e != a {
|
||||
if e, a := tt.expectedRemainingItemCount, out.ListMeta.GetRemainingItemCount(); e != a {
|
||||
t.Errorf("(%s): remainingItemCount want=%d, got=%d", tt.name, e, a)
|
||||
}
|
||||
for j, wantPod := range tt.expectedOut {
|
||||
|
|
|
@ -73,7 +73,7 @@ func (c *REST) ConvertToTable(ctx context.Context, obj runtime.Object, tableOpti
|
|||
table.ResourceVersion = m.GetResourceVersion()
|
||||
table.SelfLink = m.GetSelfLink()
|
||||
table.Continue = m.GetContinue()
|
||||
table.RemainingItemCount = m.GetRemainingItemCount()
|
||||
table.SetRemainingItemCount(m.GetRemainingItemCount())
|
||||
} else {
|
||||
if m, err := meta.CommonAccessor(obj); err == nil {
|
||||
table.ResourceVersion = m.GetResourceVersion()
|
||||
|
|
|
@ -89,7 +89,7 @@ var _ = SIGDescribe("Servers with support for API chunking", func() {
|
|||
lastRV = list.ResourceVersion
|
||||
}
|
||||
gomega.Expect(list.ResourceVersion).To(gomega.Equal(lastRV))
|
||||
gomega.Expect(int(list.RemainingItemCount) + len(list.Items) + found).To(gomega.BeNumerically("==", numberOfTotalResources))
|
||||
gomega.Expect(int(list.GetRemainingItemCount()) + len(list.Items) + found).To(gomega.BeNumerically("==", numberOfTotalResources))
|
||||
for _, item := range list.Items {
|
||||
gomega.Expect(item.Name).To(gomega.Equal(fmt.Sprintf("template-%04d", found)))
|
||||
found++
|
||||
|
@ -122,7 +122,7 @@ var _ = SIGDescribe("Servers with support for API chunking", func() {
|
|||
gomega.Expect(err).ToNot(gomega.HaveOccurred(), "failed to list pod templates in namespace: %s, given limit: %d", ns, opts.Limit)
|
||||
firstToken := list.Continue
|
||||
firstRV := list.ResourceVersion
|
||||
gomega.Expect(int(list.RemainingItemCount) + len(list.Items)).To(gomega.BeNumerically("==", numberOfTotalResources))
|
||||
gomega.Expect(int(list.GetRemainingItemCount()) + len(list.Items)).To(gomega.BeNumerically("==", numberOfTotalResources))
|
||||
e2elog.Logf("Retrieved %d/%d results with rv %s and continue %s", len(list.Items), opts.Limit, list.ResourceVersion, firstToken)
|
||||
|
||||
ginkgo.By("retrieving the second page until the token expires")
|
||||
|
@ -157,7 +157,7 @@ var _ = SIGDescribe("Servers with support for API chunking", func() {
|
|||
gomega.Expect(list.ResourceVersion).ToNot(gomega.Equal(firstRV))
|
||||
gomega.Expect(len(list.Items)).To(gomega.BeNumerically("==", opts.Limit))
|
||||
found := int(oneTenth)
|
||||
gomega.Expect(int(list.RemainingItemCount) + len(list.Items) + found).To(gomega.BeNumerically("==", numberOfTotalResources))
|
||||
gomega.Expect(int(list.GetRemainingItemCount()) + len(list.Items) + found).To(gomega.BeNumerically("==", numberOfTotalResources))
|
||||
for _, item := range list.Items {
|
||||
gomega.Expect(item.Name).To(gomega.Equal(fmt.Sprintf("template-%04d", found)))
|
||||
found++
|
||||
|
@ -169,7 +169,7 @@ var _ = SIGDescribe("Servers with support for API chunking", func() {
|
|||
for {
|
||||
list, err := client.List(opts)
|
||||
gomega.Expect(err).ToNot(gomega.HaveOccurred(), "failed to list pod templates in namespace: %s, given limit: %d", ns, opts.Limit)
|
||||
gomega.Expect(int(list.RemainingItemCount) + len(list.Items) + found).To(gomega.BeNumerically("==", numberOfTotalResources))
|
||||
gomega.Expect(int(list.GetRemainingItemCount()) + len(list.Items) + found).To(gomega.BeNumerically("==", numberOfTotalResources))
|
||||
e2elog.Logf("Retrieved %d/%d results with rv %s and continue %s", len(list.Items), opts.Limit, list.ResourceVersion, list.Continue)
|
||||
gomega.Expect(len(list.Items)).To(gomega.BeNumerically("<=", opts.Limit))
|
||||
gomega.Expect(list.ResourceVersion).To(gomega.Equal(lastRV))
|
||||
|
|
Loading…
Reference in New Issue