diff --git a/pkg/registry/rbac/helpers.go b/pkg/registry/rbac/helpers.go index ca0b7188569..0e10a65b855 100644 --- a/pkg/registry/rbac/helpers.go +++ b/pkg/registry/rbac/helpers.go @@ -17,6 +17,8 @@ limitations under the License. package rbac import ( + "reflect" + "k8s.io/apimachinery/pkg/api/meta" "k8s.io/apimachinery/pkg/conversion" "k8s.io/apimachinery/pkg/runtime" @@ -25,6 +27,10 @@ import ( // IsOnlyMutatingGCFields checks finalizers and ownerrefs which GC manipulates // and indicates that only those fields are changing 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 copied := obj.DeepCopyObject() copiedMeta, err := meta.Accessor(copied) diff --git a/pkg/registry/rbac/helpers_test.go b/pkg/registry/rbac/helpers_test.go index 523f2de12a6..a371c7964c5 100644 --- a/pkg/registry/rbac/helpers_test.go +++ b/pkg/registry/rbac/helpers_test.go @@ -128,6 +128,19 @@ func TestIsOnlyMutatingGCFields(t *testing.T) { }, 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 {