Skip to content

Commit 145e8c4

Browse files
committed
Make GetRemainingItemCount/SetRemainingItemCount use pointers
1 parent 3693149 commit 145e8c4

File tree

17 files changed

+84
-68
lines changed

17 files changed

+84
-68
lines changed

pkg/printers/tablegenerator.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ func (h *HumanReadablePrinter) GenerateTable(obj runtime.Object, options PrintOp
112112
table.ResourceVersion = m.GetResourceVersion()
113113
table.SelfLink = m.GetSelfLink()
114114
table.Continue = m.GetContinue()
115-
table.SetRemainingItemCount(m.GetRemainingItemCount())
115+
table.RemainingItemCount = m.GetRemainingItemCount()
116116
} else {
117117
if m, err := meta.CommonAccessor(obj); err == nil {
118118
table.ResourceVersion = m.GetResourceVersion()

staging/src/k8s.io/apiextensions-apiserver/pkg/registry/customresource/tableconvertor/tableconvertor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func (c *convertor) ConvertToTable(ctx context.Context, obj runtime.Object, tabl
8787
table.ResourceVersion = m.GetResourceVersion()
8888
table.SelfLink = m.GetSelfLink()
8989
table.Continue = m.GetContinue()
90-
table.SetRemainingItemCount(m.GetRemainingItemCount())
90+
table.RemainingItemCount = m.GetRemainingItemCount()
9191
} else {
9292
if m, err := meta.CommonAccessor(obj); err == nil {
9393
table.ResourceVersion = m.GetResourceVersion()

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

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ type ListInterface interface {
9494
SetSelfLink(selfLink string)
9595
GetContinue() string
9696
SetContinue(c string)
97-
GetRemainingItemCount() int64
98-
SetRemainingItemCount(c int64)
97+
GetRemainingItemCount() *int64
98+
SetRemainingItemCount(c *int64)
9999
}
100100

101101
// Type exposes the type and APIVersion of versioned or internal API objects.
@@ -115,20 +115,8 @@ func (meta *ListMeta) GetSelfLink() string { return meta.SelfLink
115115
func (meta *ListMeta) SetSelfLink(selfLink string) { meta.SelfLink = selfLink }
116116
func (meta *ListMeta) GetContinue() string { return meta.Continue }
117117
func (meta *ListMeta) SetContinue(c string) { meta.Continue = c }
118-
119-
func (meta *ListMeta) GetRemainingItemCount() int64 {
120-
if meta.RemainingItemCount != nil {
121-
return *meta.RemainingItemCount
122-
}
123-
return 0
124-
}
125-
126-
func (meta *ListMeta) SetRemainingItemCount(c int64) {
127-
if meta.RemainingItemCount == nil {
128-
meta.RemainingItemCount = new(int64)
129-
}
130-
*meta.RemainingItemCount = c
131-
}
118+
func (meta *ListMeta) GetRemainingItemCount() *int64 { return meta.RemainingItemCount }
119+
func (meta *ListMeta) SetRemainingItemCount(c *int64) { meta.RemainingItemCount = c }
132120

133121
func (obj *TypeMeta) GetObjectKind() schema.ObjectKind { return obj }
134122

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,14 @@ func getNestedInt64(obj map[string]interface{}, fields ...string) int64 {
283283
return val
284284
}
285285

286+
func getNestedInt64Pointer(obj map[string]interface{}, fields ...string) *int64 {
287+
val, found, err := NestedInt64(obj, fields...)
288+
if !found || err != nil {
289+
return nil
290+
}
291+
return &val
292+
}
293+
286294
func jsonPath(fields []string) string {
287295
return "." + strings.Join(fields, ".")
288296
}

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -320,12 +320,16 @@ func (u *Unstructured) SetContinue(c string) {
320320
u.setNestedField(c, "metadata", "continue")
321321
}
322322

323-
func (u *Unstructured) GetRemainingItemCount() int64 {
324-
return getNestedInt64(u.Object, "metadata", "remainingItemCount")
323+
func (u *Unstructured) GetRemainingItemCount() *int64 {
324+
return getNestedInt64Pointer(u.Object, "metadata", "remainingItemCount")
325325
}
326326

327-
func (u *Unstructured) SetRemainingItemCount(c int64) {
328-
u.setNestedField(c, "metadata", "remainingItemCount")
327+
func (u *Unstructured) SetRemainingItemCount(c *int64) {
328+
if c == nil {
329+
RemoveNestedField(u.Object, "metadata", "remainingItemCount")
330+
} else {
331+
u.setNestedField(*c, "metadata", "remainingItemCount")
332+
}
329333
}
330334

331335
func (u *Unstructured) GetCreationTimestamp() metav1.Time {

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,12 +166,16 @@ func (u *UnstructuredList) SetContinue(c string) {
166166
u.setNestedField(c, "metadata", "continue")
167167
}
168168

169-
func (u *UnstructuredList) GetRemainingItemCount() int64 {
170-
return getNestedInt64(u.Object, "metadata", "remainingItemCount")
169+
func (u *UnstructuredList) GetRemainingItemCount() *int64 {
170+
return getNestedInt64Pointer(u.Object, "metadata", "remainingItemCount")
171171
}
172172

173-
func (u *UnstructuredList) SetRemainingItemCount(c int64) {
174-
u.setNestedField(c, "metadata", "remainingItemCount")
173+
func (u *UnstructuredList) SetRemainingItemCount(c *int64) {
174+
if c == nil {
175+
RemoveNestedField(u.Object, "metadata", "remainingItemCount")
176+
} else {
177+
u.setNestedField(*c, "metadata", "remainingItemCount")
178+
}
175179
}
176180

177181
func (u *UnstructuredList) SetGroupVersionKind(gvk schema.GroupVersionKind) {

staging/src/k8s.io/apimachinery/pkg/test/api_meta_meta_test.go

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -209,26 +209,14 @@ type InternalTypeMeta struct {
209209
OwnerReferences []metav1.OwnerReference `json:"ownerReferences,omitempty"`
210210
}
211211

212-
func (m *InternalTypeMeta) GetResourceVersion() string { return m.ResourceVersion }
213-
func (m *InternalTypeMeta) SetResourceVersion(rv string) { m.ResourceVersion = rv }
214-
func (m *InternalTypeMeta) GetSelfLink() string { return m.SelfLink }
215-
func (m *InternalTypeMeta) SetSelfLink(link string) { m.SelfLink = link }
216-
func (m *InternalTypeMeta) GetContinue() string { return m.Continue }
217-
func (m *InternalTypeMeta) SetContinue(c string) { m.Continue = c }
218-
219-
func (m *InternalTypeMeta) GetRemainingItemCount() int64 {
220-
if m.RemainingItemCount != nil {
221-
return *m.RemainingItemCount
222-
}
223-
return 0
224-
}
225-
226-
func (m *InternalTypeMeta) SetRemainingItemCount(c int64) {
227-
if m.RemainingItemCount == nil {
228-
m.RemainingItemCount = new(int64)
229-
}
230-
*m.RemainingItemCount = c
231-
}
212+
func (m *InternalTypeMeta) GetResourceVersion() string { return m.ResourceVersion }
213+
func (m *InternalTypeMeta) SetResourceVersion(rv string) { m.ResourceVersion = rv }
214+
func (m *InternalTypeMeta) GetSelfLink() string { return m.SelfLink }
215+
func (m *InternalTypeMeta) SetSelfLink(link string) { m.SelfLink = link }
216+
func (m *InternalTypeMeta) GetContinue() string { return m.Continue }
217+
func (m *InternalTypeMeta) SetContinue(c string) { m.Continue = c }
218+
func (m *InternalTypeMeta) GetRemainingItemCount() *int64 { return m.RemainingItemCount }
219+
func (m *InternalTypeMeta) SetRemainingItemCount(c *int64) { m.RemainingItemCount = c }
232220

233221
type MyAPIObject struct {
234222
TypeMeta InternalTypeMeta `json:",inline"`

staging/src/k8s.io/apiserver/pkg/registry/rest/table.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func (c defaultTableConvertor) ConvertToTable(ctx context.Context, object runtim
6767
table.ResourceVersion = m.GetResourceVersion()
6868
table.SelfLink = m.GetSelfLink()
6969
table.Continue = m.GetContinue()
70-
table.SetRemainingItemCount(m.GetRemainingItemCount())
70+
table.RemainingItemCount = m.GetRemainingItemCount()
7171
} else {
7272
if m, err := meta.CommonAccessor(object); err == nil {
7373
table.ResourceVersion = m.GetResourceVersion()

staging/src/k8s.io/apiserver/pkg/storage/cacher/cacher.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,7 @@ func (c *Cacher) GetToList(ctx context.Context, key string, resourceVersion stri
605605
}
606606
}
607607
if c.versioner != nil {
608-
if err := c.versioner.UpdateList(listObj, readResourceVersion, "", 0); err != nil {
608+
if err := c.versioner.UpdateList(listObj, readResourceVersion, "", nil); err != nil {
609609
return err
610610
}
611611
}
@@ -680,7 +680,7 @@ func (c *Cacher) List(ctx context.Context, key string, resourceVersion string, p
680680
}
681681
trace.Step(fmt.Sprintf("Filtered %d items", listVal.Len()))
682682
if c.versioner != nil {
683-
if err := c.versioner.UpdateList(listObj, readResourceVersion, "", 0); err != nil {
683+
if err := c.versioner.UpdateList(listObj, readResourceVersion, "", nil); err != nil {
684684
return err
685685
}
686686
}

staging/src/k8s.io/apiserver/pkg/storage/cacher/cacher_whitebox_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ type testVersioner struct{}
217217
func (testVersioner) UpdateObject(obj runtime.Object, resourceVersion uint64) error {
218218
return meta.NewAccessor().SetResourceVersion(obj, strconv.FormatUint(resourceVersion, 10))
219219
}
220-
func (testVersioner) UpdateList(obj runtime.Object, resourceVersion uint64, continueValue string, count int64) error {
220+
func (testVersioner) UpdateList(obj runtime.Object, resourceVersion uint64, continueValue string, count *int64) error {
221221
listAccessor, err := meta.ListAccessor(obj)
222222
if err != nil || listAccessor == nil {
223223
return err

0 commit comments

Comments
 (0)