mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-26 05:03:09 +00:00
GC: Add check for nil interface
This commit is contained in:
parent
fef3b03188
commit
34ed25cf52
@ -17,6 +17,8 @@ limitations under the License.
|
|||||||
package rbac
|
package rbac
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"reflect"
|
||||||
|
|
||||||
"k8s.io/apimachinery/pkg/api/meta"
|
"k8s.io/apimachinery/pkg/api/meta"
|
||||||
"k8s.io/apimachinery/pkg/conversion"
|
"k8s.io/apimachinery/pkg/conversion"
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
@ -25,6 +27,10 @@ import (
|
|||||||
// IsOnlyMutatingGCFields checks finalizers and ownerrefs which GC manipulates
|
// IsOnlyMutatingGCFields checks finalizers and ownerrefs which GC manipulates
|
||||||
// and indicates that only those fields are changing
|
// and indicates that only those fields are changing
|
||||||
func IsOnlyMutatingGCFields(obj, old runtime.Object, equalities conversion.Equalities) bool {
|
func IsOnlyMutatingGCFields(obj, old runtime.Object, equalities conversion.Equalities) bool {
|
||||||
|
if old == nil || reflect.ValueOf(old).IsNil() {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
// make a copy of the newObj so that we can stomp for comparison
|
// make a copy of the newObj so that we can stomp for comparison
|
||||||
copied := obj.DeepCopyObject()
|
copied := obj.DeepCopyObject()
|
||||||
copiedMeta, err := meta.Accessor(copied)
|
copiedMeta, err := meta.Accessor(copied)
|
||||||
|
@ -128,6 +128,19 @@ func TestIsOnlyMutatingGCFields(t *testing.T) {
|
|||||||
},
|
},
|
||||||
expected: false,
|
expected: false,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "and nil",
|
||||||
|
obj: func() runtime.Object {
|
||||||
|
obj := newPod()
|
||||||
|
obj.OwnerReferences = append(obj.OwnerReferences, metav1.OwnerReference{Name: "foo"})
|
||||||
|
obj.Spec.RestartPolicy = kapi.RestartPolicyAlways
|
||||||
|
return obj
|
||||||
|
},
|
||||||
|
old: func() runtime.Object {
|
||||||
|
return (*kapi.Pod)(nil)
|
||||||
|
},
|
||||||
|
expected: false,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tc := range tests {
|
for _, tc := range tests {
|
||||||
|
Loading…
Reference in New Issue
Block a user