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

do not always error out while checking for existence of resources #151

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions internal/controller/clientprofile_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (

"github.com/go-logr/logr"
corev1 "k8s.io/api/core/v1"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/builder"
Expand Down Expand Up @@ -130,6 +131,10 @@ func (r *ClientProfileReconciler) Reconcile(ctx context.Context, req ctrl.Reques

func (r *ClientProfileReconcile) reconcile() error {
if err := r.loadAndValidate(); err != nil {
if k8serrors.IsNotFound(err) && r.clientProfile.UID == "" {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@leelavg wouldn't it make more sense to investigate the error object to see the target of the not found error?

r.log.Info("Client profile resource does not exists anymore, skipping reconcile")
return nil
}
return err
}

Expand Down
6 changes: 5 additions & 1 deletion internal/controller/driver_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,10 @@ func (r *DriverReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr
func (r *driverReconcile) reconcile() error {
// Load the driver desired state based on driver resource, operator config resource and default values.
if err := r.LoadAndValidateDesiredState(); err != nil {
if k8serrors.IsNotFound(err) && r.driver.UID == "" {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as last comment

r.log.Info("Driver resource does not exist anymore, skipping reconcile")
return nil
}
return err
}

Expand Down Expand Up @@ -255,7 +259,7 @@ func (r *driverReconcile) LoadAndValidateDesiredState() error {
// (Can happen if a driver with an identical name was created in a different namespace)
csiDriver := storagev1.CSIDriver{}
csiDriver.Name = r.driver.Name
if err := r.Get(r.ctx, client.ObjectKeyFromObject(&csiDriver), &csiDriver); client.IgnoreNotFound(err) != nil {
if err := r.Get(r.ctx, client.ObjectKeyFromObject(&csiDriver), &csiDriver); err != nil {
r.log.Error(err, "Failed to query the existence of a CSI Driver")
return err
}
Expand Down
Loading