mirror of
https://github.com/kubernetes/client-go.git
synced 2026-05-14 19:17:56 +00:00
Merge pull request #136937 from p0lyn0mial/upstream-reflector-list-unsupported-table
client-go/reflector: reject Table format resources in List and Watch paths Kubernetes-commit: 3bc0b290e9c1cd81db1ed5119b242b5dfce931af
This commit is contained in:
26
tools/cache/reflector.go
vendored
26
tools/cache/reflector.go
vendored
@@ -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, let’s 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()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user