Skip to content

Commit

Permalink
fix: nil check http response when err is not nil (PROJQUAY-6620)
Browse files Browse the repository at this point in the history
Topic: projquay-6620

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 <[email protected]>

fix: addtl nil checking http responses (PROJQUAY-6620)

chore: lint_controllers (PROJQUAY-6620)

chore: lint quay client (PROJQUAY-6620)
Signed-off-by: Ross Bryan <[email protected]>
  • Loading branch information
arborite-rh committed Feb 28, 2024
1 parent 2f224ad commit d0f1208
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 96 deletions.
17 changes: 0 additions & 17 deletions controllers/build_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,10 @@ type BuildIntegrationReconciler struct {
//+kubebuilder:rbac:groups=build.openshift.io,resources=builds,verbs=get;list;watch;create;update;patch

func (r *BuildIntegrationReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {

logging.Log.Info("Reconciling Build", "Request.Namespace", req.Namespace, "Request.Name", req.Name)

instance := &buildv1.Build{}
err := r.CoreComponents.ReconcilerBase.GetClient().Get(ctx, req.NamespacedName, instance)

if err != nil {
if apierrors.IsNotFound(err) {
return reconcile.Result{}, nil
Expand All @@ -69,7 +67,6 @@ func (r *BuildIntegrationReconciler) Reconcile(ctx context.Context, req ctrl.Req

// Get ImageStream Tag
buildImageStreamTagAnnotation, found := instance.GetAnnotations()[constants.BuildDestinationImageStreamAnnotation]

if !found {
// If annotation not found, ImageStreamTag import has been completed
return reconcile.Result{}, nil
Expand All @@ -88,7 +85,6 @@ func (r *BuildIntegrationReconciler) Reconcile(ctx context.Context, req ctrl.Req
}

buildImageStreamNamespace := buildImageStreamComponents[0]

imageNameTagComponents := strings.Split(buildImageStreamComponents[1], ":")

if len(imageNameTagComponents) != 2 {
Expand All @@ -98,7 +94,6 @@ func (r *BuildIntegrationReconciler) Reconcile(ctx context.Context, req ctrl.Req
KeyAndValues: []interface{}{"Namespace", instance.Namespace, "Build", instance.Name, "Annotation", buildImageStreamTagAnnotation, "Actual Size", len(imageNameTagComponents)},
Reason: "ProcessingError",
})

}

buildImageName := imageNameTagComponents[0]
Expand All @@ -107,23 +102,20 @@ func (r *BuildIntegrationReconciler) Reconcile(ctx context.Context, req ctrl.Req
logging.Log.Info("Importing ImageStream after Build", "ImageStream Namespace", buildImageStreamNamespace, "ImageStream Name", buildImageName, "ImageStream Tag", buildImageTag)

quayIntegration, result, err := r.CoreComponents.GetQuayIntegration(instance)

if err != nil {
return result, err
}

// First, Get the ImageStream
existingImageStream := &imagev1.ImageStream{}
err = r.CoreComponents.ReconcilerBase.GetClient().Get(ctx, types.NamespacedName{Namespace: buildImageStreamNamespace, Name: buildImageName}, existingImageStream)

if err != nil {
return r.CoreComponents.ManageError(&core.QuayIntegrationCoreError{
Object: instance,
Message: "Unable to locate ImageStream",
KeyAndValues: []interface{}{"Namespace", buildImageStreamNamespace, "Build", buildImageName},
Reason: "ProcessingError",
})

}

isi := &imagev1.ImageStreamImport{
Expand Down Expand Up @@ -154,7 +146,6 @@ func (r *BuildIntegrationReconciler) Reconcile(ctx context.Context, req ctrl.Req
}

err = r.CoreComponents.ReconcilerBase.GetClient().Create(ctx, isi)

if err != nil {
return r.CoreComponents.ManageError(&core.QuayIntegrationCoreError{
Object: instance,
Expand All @@ -167,7 +158,6 @@ func (r *BuildIntegrationReconciler) Reconcile(ctx context.Context, req ctrl.Req

// Update the Build
instance.GetAnnotations()[constants.BuildDestinationImageStreamTagImportedAnnotation] = "true"

err = r.CoreComponents.ReconcilerBase.GetClient().Update(ctx, instance)
if err != nil {
return r.CoreComponents.ManageError(&core.QuayIntegrationCoreError{
Expand All @@ -180,20 +170,15 @@ func (r *BuildIntegrationReconciler) Reconcile(ctx context.Context, req ctrl.Req
}

return reconcile.Result{}, nil

}

// SetupWithManager sets up the controller with the Manager.
func (r *BuildIntegrationReconciler) SetupWithManager(mgr ctrl.Manager) error {

buildPredicates := []predicate.Predicate{
predicate.Funcs{

UpdateFunc: func(e event.UpdateEvent) bool {

newBuild, ok := e.ObjectNew.(*buildv1.Build)

// Check to see if it has the Managed Annotations
_, managedAnnotationFound := e.ObjectNew.GetAnnotations()[constants.BuildOperatorManagedAnnotation]
_, imageStreamImportedAnnotationFound := e.ObjectNew.GetAnnotations()[constants.BuildDestinationImageStreamTagImportedAnnotation]

Expand All @@ -203,11 +188,9 @@ func (r *BuildIntegrationReconciler) SetupWithManager(mgr ctrl.Manager) error {

return true
},

CreateFunc: func(e event.CreateEvent) bool {
return false
},

DeleteFunc: func(e event.DeleteEvent) bool {
return false
},
Expand Down
Loading

0 comments on commit d0f1208

Please sign in to comment.