From c72cd2dec104cdcd715d992cbf826ea69fc9ca87 Mon Sep 17 00:00:00 2001 From: Ross Bryan Date: Tue, 27 Feb 2024 15:42:21 -0500 Subject: [PATCH] fix: nil check http response when err is not nil (PROJQUAY-6620) Topic: projquay-6507 The operator was panicking due to the httpResponse being nil and attempting to return the httpResponse.StatusCode in the response; the response was most likely nil due to a prior error when attempting to marshal json and build the http request itself. This now allows the error to be propagated out to the logs instead of causing the operator to panic Signed-off-by: Ross Bryan --- controllers/namespace_controller.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/controllers/namespace_controller.go b/controllers/namespace_controller.go index 529dc54a..cd5ed6e7 100644 --- a/controllers/namespace_controller.go +++ b/controllers/namespace_controller.go @@ -313,6 +313,15 @@ func (r *NamespaceIntegrationReconciler) setupResources(ctx context.Context, req // Check if Repository Exists _, repositoryHttpResponse, repositoryErr := quayClient.GetRepository(quayOrganizationName, imageStreamName) + if repositoryHttpResponse == nil { + return r.CoreComponents.ManageError(&core.QuayIntegrationCoreError{ + Object: namespace, + Message: "Error creating request to retrieve repository", + KeyAndValues: []interface{}{"Namespace", namespace.Name, "Name", imageStreamName}, + Error: repositoryErr.Error, + }) + } + if repositoryErr.Error != nil { return r.CoreComponents.ManageError(&core.QuayIntegrationCoreError{ Object: namespace,