reflector: reject Table format resources in List and Watch paths

Kubernetes-commit: a46b1903a5426ede16d021b49c96d3f4ba7aea4d
This commit is contained in:
Lukasz Szaszkiewicz
2026-02-10 21:42:42 +01:00
committed by Kubernetes Publisher
parent 00e45797cb
commit 7b594c4c71

View File

@@ -729,6 +729,11 @@ func (r *Reflector) list(ctx context.Context) error {
// the reflector makes forward progress.
list, paginatedResult, err = pager.ListWithAlloc(context.Background(), metav1.ListOptions{ResourceVersion: r.relistResourceVersion()})
}
if err == nil {
if unsupportedList, unsupportedListGVK := isUnsupportedTableListObject(list); unsupportedList {
err = fmt.Errorf("unsupported list gvk: %v, type: %v", unsupportedListGVK, r.typeDescription)
}
}
close(listCh)
}()
select {
@@ -738,6 +743,7 @@ func (r *Reflector) list(ctx context.Context) error {
panic(r)
case <-listCh:
}
initTrace.Step("Objects listed", trace.Field{Key: "error", Value: err})
if err != nil {
return fmt.Errorf("failed to list %v: %w", r.typeDescription, err)
@@ -1018,14 +1024,11 @@ loop:
continue
}
}
// For now, lets block unsupported Table
// resources for watchlist only
// we don't support receiving resources in Table format
// see #132926 for more info
if exitOnWatchListBookmarkReceived {
if unsupportedGVK := isUnsupportedTableObject(event.Object); unsupportedGVK {
utilruntime.HandleErrorWithContext(ctx, nil, "Unsupported watch event object gvk", "reflector", name, "actualGVK", event.Object.GetObjectKind().GroupVersionKind())
continue
}
if unsupportedGVK := isUnsupportedTableObject(event.Object); unsupportedGVK {
utilruntime.HandleErrorWithContext(ctx, nil, "Unsupported watch event object gvk", "reflector", name, "actualGVK", event.Object.GetObjectKind().GroupVersionKind())
continue
}
meta, err := meta.Accessor(event.Object)
if err != nil {
@@ -1321,3 +1324,12 @@ func isUnsupportedTableObject(rawObject runtime.Object) bool {
return unsupportedTableGVK[rawObject.GetObjectKind().GroupVersionKind()]
}
func isUnsupportedTableListObject(rawObject runtime.Object) (bool, schema.GroupVersionKind) {
unstructuredObj, ok := rawObject.(*unstructured.UnstructuredList)
if !ok {
return false, schema.GroupVersionKind{}
}
return unsupportedTableGVK[unstructuredObj.GetObjectKind().GroupVersionKind()], unstructuredObj.GetObjectKind().GroupVersionKind()
}