mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 03:41:45 +00:00
Prepare apiserver for operating on cached objects by not modifying them
This commit is contained in:
parent
170a9c050f
commit
7e434682e4
@ -27,11 +27,11 @@ import (
|
|||||||
|
|
||||||
// Interface can be implemented by anything that knows how to watch and report changes.
|
// Interface can be implemented by anything that knows how to watch and report changes.
|
||||||
type Interface interface {
|
type Interface interface {
|
||||||
// Stops watching. Will close the channel returned by ResultChan(). Releases
|
// Stop stops watching. Will close the channel returned by ResultChan(). Releases
|
||||||
// any resources used by the watch.
|
// any resources used by the watch.
|
||||||
Stop()
|
Stop()
|
||||||
|
|
||||||
// Returns a chan which will receive all the events. If an error occurs
|
// ResultChan returns a chan which will receive all the events. If an error occurs
|
||||||
// or Stop() is called, the implementation will close this channel and
|
// or Stop() is called, the implementation will close this channel and
|
||||||
// release any resources used by the watch.
|
// release any resources used by the watch.
|
||||||
ResultChan() <-chan Event
|
ResultChan() <-chan Event
|
||||||
|
@ -59,8 +59,14 @@ func doTransformObject(ctx context.Context, obj runtime.Object, opts interface{}
|
|||||||
if _, ok := obj.(*metav1.Status); ok {
|
if _, ok := obj.(*metav1.Status); ok {
|
||||||
return obj, nil
|
return obj, nil
|
||||||
}
|
}
|
||||||
if err := ensureNonNilItems(obj); err != nil {
|
|
||||||
return nil, err
|
// ensure that for empty lists we don't return <nil> items.
|
||||||
|
// This is safe to modify without deep-copying the object, as
|
||||||
|
// List objects themselves are never cached.
|
||||||
|
if meta.IsListType(obj) && meta.LenList(obj) == 0 {
|
||||||
|
if err := meta.SetList(obj, []runtime.Object{}); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch target := mediaType.Convert; {
|
switch target := mediaType.Convert; {
|
||||||
|
@ -356,16 +356,6 @@ func dedupOwnerReferencesAndAddWarning(obj runtime.Object, requestContext contex
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ensureNonNilItems ensures that for empty lists we don't return <nil> items.
|
|
||||||
func ensureNonNilItems(obj runtime.Object) error {
|
|
||||||
if meta.IsListType(obj) && meta.LenList(obj) == 0 {
|
|
||||||
if err := meta.SetList(obj, []runtime.Object{}); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func summarizeData(data []byte, maxLength int) string {
|
func summarizeData(data []byte, maxLength int) string {
|
||||||
switch {
|
switch {
|
||||||
case len(data) == 0:
|
case len(data) == 0:
|
||||||
|
Loading…
Reference in New Issue
Block a user