Skip to content

Commit

Permalink
chore: remove double error logging in lvmcluster_controller
Browse files Browse the repository at this point in the history
  • Loading branch information
jakobmoellerdev committed Aug 25, 2023
1 parent 5c8d2ff commit cf48cb2
Showing 1 changed file with 13 additions and 22 deletions.
35 changes: 13 additions & 22 deletions controllers/lvmcluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func (r *LVMClusterReconciler) reconcile(ctx context.Context, instance *lvmv1alp
// The resource was deleted
if !instance.DeletionTimestamp.IsZero() {
// Check for existing LogicalVolumes
lvsExist, err := r.logicalVolumesExist(ctx, instance)
lvsExist, err := r.logicalVolumesExist(ctx)
if err != nil {
// check every 10 seconds if there are still PVCs present
return ctrl.Result{}, fmt.Errorf("failed to check if LogicalVolumes exist: %w", err)
Expand Down Expand Up @@ -293,14 +293,11 @@ func (r *LVMClusterReconciler) updateLVMClusterStatus(ctx context.Context, insta
}

func (r *LVMClusterReconciler) getExpectedVGCount(ctx context.Context, instance *lvmv1alpha1.LVMCluster) (int, error) {

var vgCount int

nodeList := &corev1.NodeList{}
err := r.Client.List(ctx, nodeList)
if err != nil {
r.Log.Error(err, "failed to list Nodes")
return 0, err
if err := r.Client.List(ctx, nodeList); err != nil {
return 0, fmt.Errorf("failed to list Nodes: %w", err)
}

for _, deviceClass := range instance.Spec.Storage.DeviceClasses {
Expand All @@ -325,8 +322,7 @@ func (r *LVMClusterReconciler) getExpectedVGCount(ctx context.Context, instance

matches, err := corev1helper.MatchNodeSelectorTerms(&nodeList.Items[i], deviceClass.NodeSelector)
if err != nil {
r.Log.Error(err, "failed to match node selector")
return 0, err
return 0, fmt.Errorf("failed to match node selector: %w", err)
}

if matches {
Expand All @@ -351,9 +347,7 @@ func (r *LVMClusterReconciler) checkIfOpenshift(ctx context.Context) error {
r.ClusterType = ClusterTypeOther
r.Log.Info("openshiftSCC not found, setting cluster type to other")
} else {
// Something went wrong
r.Log.Error(err, "failed to get SCC", "Name", openshiftSCCPrivilegedName)
return err
return fmt.Errorf("failed to get SCC %s", openshiftSCCPrivilegedName)
}
} else {
r.Log.Info("openshiftSCC found, setting cluster type to openshift")
Expand Down Expand Up @@ -395,13 +389,10 @@ func (r *LVMClusterReconciler) setRunningPodImage(ctx context.Context) error {
return nil
}

func (r *LVMClusterReconciler) logicalVolumesExist(ctx context.Context, instance *lvmv1alpha1.LVMCluster) (bool, error) {

func (r *LVMClusterReconciler) logicalVolumesExist(ctx context.Context) (bool, error) {
logicalVolumeList := &topolvmv1.LogicalVolumeList{}

if err := r.Client.List(ctx, logicalVolumeList); err != nil {
r.Log.Error(err, "failed to get Topolvm LogicalVolume list")
return false, err
return false, fmt.Errorf("failed to get TopoLVM LogicalVolume list: %w", err)
}
if len(logicalVolumeList.Items) > 0 {

Expand All @@ -425,15 +416,15 @@ func (r *LVMClusterReconciler) processDelete(ctx context.Context, instance *lvmv
}

for _, unit := range resourceDeletionList {
err := unit.ensureDeleted(r, ctx, instance)
if err != nil {
if err := unit.ensureDeleted(r, ctx, instance); err != nil {
return fmt.Errorf("failed cleaning up: %s %w", unit.getName(), err)
}
}
controllerutil.RemoveFinalizer(instance, lvmClusterFinalizer)
if err := r.Client.Update(context.TODO(), instance); err != nil {
r.Log.Info("failed to remove finalizer from LVMCluster", "LvmCluster", instance.Name)
return err

if update := controllerutil.RemoveFinalizer(instance, lvmClusterFinalizer); update {
if err := r.Client.Update(ctx, instance); err != nil {
return fmt.Errorf("failed to remove finalizer from LVMCluster %s: %w", instance.GetName(), err)
}
}
}

Expand Down

0 comments on commit cf48cb2

Please sign in to comment.