Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: nil check http response when err is not nil (PROJQUAY-6620) #111

Merged
merged 1 commit into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading