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: use consistent return statements across components #48

Merged
merged 1 commit into from
Dec 27, 2021
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
7 changes: 4 additions & 3 deletions controllers/topolvm_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,11 @@ func (c topolvmController) ensureCreated(r *LVMClusterReconciler, ctx context.Co

if err != nil {
r.Log.Error(err, "csi controller reconcile failure", "name", desiredDeployment.Name)
return err
} else {
r.Log.Info("csi controller", "operation", result, "name", desiredDeployment.Name)
}

return nil
return err
}

func (c topolvmController) ensureDeleted(r *LVMClusterReconciler, ctx context.Context, lvmCluster *lvmv1alpha1.LVMCluster) error {
Expand All @@ -75,13 +74,15 @@ func (c topolvmController) ensureDeleted(r *LVMClusterReconciler, ctx context.Co
if err = r.Client.Delete(ctx, existingDeployment); err != nil {
r.Log.Error(err, "failed to delete topolvm controller deployment", "TopolvmController", existingDeployment.Name)
return err
} else {
r.Log.Info("initiated topolvm controller deployment deletion", "TopolvmController", existingDeployment.Name)
}
} else {
// set deletion in-progress for next reconcile to confirm deletion
return fmt.Errorf("topolvm controller deployment %s is already marked for deletion", existingDeployment.Name)
}

return nil
return err
}

func (c topolvmController) updateStatus(r *LVMClusterReconciler, ctx context.Context, lvmCluster *lvmv1alpha1.LVMCluster) error {
Expand Down
20 changes: 10 additions & 10 deletions controllers/topolvm_csi_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,17 @@ func (c csiDriver) getName() string {
func (c csiDriver) ensureCreated(r *LVMClusterReconciler, ctx context.Context, lvmCluster *lvmv1alpha1.LVMCluster) error {
csiDriverResource := getCSIDriverResource()
result, err := cutil.CreateOrUpdate(ctx, r.Client, csiDriverResource, func() error {
// no need to mutate any field
return nil
})
// CSIDriver resource is an immutable resource and can have result either Created or Unchanged and it's clusterscoped
switch result {
case cutil.OperationResultCreated:
r.Log.Info("csi driver", "operation", result, "name", csiDriverResource.Name)
case cutil.OperationResultNone:
r.Log.Info("csi driver", "operation", result, "name", csiDriverResource.Name)
default:

if err != nil {
r.Log.Error(err, "csi driver reconcile failure", "name", csiDriverResource.Name)
return err
} else {
r.Log.Info("csi driver", "operation", result, "name", csiDriverResource.Name)
}
return nil

return err
}

func (c csiDriver) ensureDeleted(r *LVMClusterReconciler, ctx context.Context, lvmCluster *lvmv1alpha1.LVMCluster) error {
Expand All @@ -64,13 +62,15 @@ func (c csiDriver) ensureDeleted(r *LVMClusterReconciler, ctx context.Context, l
if err = r.Client.Delete(ctx, csiDriverResource); err != nil {
r.Log.Error(err, "failed to delete topolvm csi driver", "TopolvmCSIDriverName", csiDriverResource.Name)
return err
} else {
r.Log.Info("initiated topolvm csi driver deletion", "TopolvmCSIDriverName", csiDriverResource.Name)
}
} else {
// set deletion in-progress for next reconcile to confirm deletion
return fmt.Errorf("topolvm csi driver %s is already marked for deletion", csiDriverResource.Name)
}

return nil
return err
}

func (c csiDriver) updateStatus(r *LVMClusterReconciler, ctx context.Context, lvmCluster *lvmv1alpha1.LVMCluster) error {
Expand Down