Skip to content

Commit e5778f0

Browse files
committed
Fix unstructured list interface compatibility, fix kubectl paging
1 parent 8765fa2 commit e5778f0

File tree

7 files changed

+22
-0
lines changed

7 files changed

+22
-0
lines changed

pkg/printers/tablegenerator.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +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.RemainingItemCount = m.GetRemainingItemCount()
115116
} else {
116117
if m, err := meta.CommonAccessor(obj); err == nil {
117118
table.ResourceVersion = m.GetResourceVersion()

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +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.RemainingItemCount = m.GetRemainingItemCount()
9091
} else {
9192
if m, err := meta.CommonAccessor(obj); err == nil {
9293
table.ResourceVersion = m.GetResourceVersion()

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ type Type interface {
107107
SetKind(kind string)
108108
}
109109

110+
var _ ListInterface = &ListMeta{}
111+
110112
func (meta *ListMeta) GetResourceVersion() string { return meta.ResourceVersion }
111113
func (meta *ListMeta) SetResourceVersion(version string) { meta.ResourceVersion = version }
112114
func (meta *ListMeta) GetSelfLink() string { return meta.SelfLink }

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ type Unstructured struct {
4747

4848
var _ metav1.Object = &Unstructured{}
4949
var _ runtime.Unstructured = &Unstructured{}
50+
var _ metav1.ListInterface = &Unstructured{}
5051

5152
func (obj *Unstructured) GetObjectKind() schema.ObjectKind { return obj }
5253

@@ -319,6 +320,14 @@ func (u *Unstructured) SetContinue(c string) {
319320
u.setNestedField(c, "metadata", "continue")
320321
}
321322

323+
func (u *Unstructured) GetRemainingItemCount() int64 {
324+
return getNestedInt64(u.Object, "metadata", "remainingItemCount")
325+
}
326+
327+
func (u *Unstructured) SetRemainingItemCount(c int64) {
328+
u.setNestedField(c, "metadata", "remainingItemCount")
329+
}
330+
322331
func (u *Unstructured) GetCreationTimestamp() metav1.Time {
323332
var timestamp metav1.Time
324333
timestamp.UnmarshalQueryParameter(getNestedString(u.Object, "metadata", "creationTimestamp"))

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +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.RemainingItemCount = m.GetRemainingItemCount()
7071
} else {
7172
if m, err := meta.CommonAccessor(object); err == nil {
7273
table.ResourceVersion = m.GetResourceVersion()

staging/src/k8s.io/kube-aggregator/pkg/registry/apiservice/etcd/etcd.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ func (c *REST) ConvertToTable(ctx context.Context, obj runtime.Object, tableOpti
7373
table.ResourceVersion = m.GetResourceVersion()
7474
table.SelfLink = m.GetSelfLink()
7575
table.Continue = m.GetContinue()
76+
table.RemainingItemCount = m.GetRemainingItemCount()
7677
} else {
7778
if m, err := meta.CommonAccessor(obj); err == nil {
7879
table.ResourceVersion = m.GetResourceVersion()

test/cmd/get.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,13 @@ run_kubectl_get_tests() {
129129
# Post-condition: Check if we get a limit and continue
130130
kube::test::if_has_string "${output_message}" "/clusterroles?limit=500 200 OK"
131131

132+
### Test kubectl get accumulates pages
133+
output_message=$(kubectl get namespaces --chunk-size=1 --no-headers "${kube_flags[@]}")
134+
# Post-condition: Check we got multiple pages worth of namespaces
135+
kube::test::if_has_string "${output_message}" "default"
136+
kube::test::if_has_string "${output_message}" "kube-public"
137+
kube::test::if_has_string "${output_message}" "kube-system"
138+
132139
### Test kubectl get chunk size does not result in a --watch error when resource list is served in multiple chunks
133140
# Pre-condition: ConfigMap one two tree does not exist
134141
kube::test::get_object_assert 'configmaps' '{{range.items}}{{ if eq $id_field \"one\" }}found{{end}}{{end}}:' ':'

0 commit comments

Comments
 (0)