Prevent nil access when resource is nil (#1386)

When an error is returned frequently the resource is nil and results in nil.Name being called for the error.
This commit is contained in:
Thomas Shafer 2020-06-06 12:53:18 -07:00 committed by GitHub
parent b7125260dc
commit 2266252575
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 2 deletions

View File

@ -463,10 +463,11 @@ func (r *reconcilerImpl) updateFinalizersFiltered(ctx {{.contextContext|raw}}, r
{{else}}
patcher := r.Client.{{.group}}{{.version}}().{{.type|apiGroup}}(resource.Namespace)
{{end}}
resource, err = patcher.Patch(resource.Name, {{.typesMergePatchType|raw}}, patch)
resourceName := resource.Name
resource, err = patcher.Patch(resourceName, {{.typesMergePatchType|raw}}, patch)
if err != nil {
r.Recorder.Eventf(resource, {{.corev1EventTypeWarning|raw}}, "FinalizerUpdateFailed",
"Failed to update finalizers for %q: %v", resource.Name, err)
"Failed to update finalizers for %q: %v", resourceName, err)
} else {
r.Recorder.Eventf(resource, {{.corev1EventTypeNormal|raw}}, "FinalizerUpdate",
"Updated %q finalizers", resource.GetName())