Skip to content
This repository was archived by the owner on Aug 12, 2025. It is now read-only.

Commit 16a4a68

Browse files
committed
style: fix redundant and always nil returns
Signed-off-by: Chris Privitere <[email protected]>
1 parent cbb9710 commit 16a4a68

File tree

2 files changed

+18
-15
lines changed

2 files changed

+18
-15
lines changed

controllers/packetcluster_controller.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17+
// Package controllers contains PacketCluster controller logic.
1718
package controllers
1819

1920
import (
@@ -104,10 +105,11 @@ func (r *PacketClusterReconciler) Reconcile(ctx context.Context, req ctrl.Reques
104105
return r.reconcileDelete(ctx, clusterScope)
105106
}
106107

107-
return r.reconcileNormal(ctx, clusterScope)
108+
err = r.reconcileNormal(ctx, clusterScope)
109+
return ctrl.Result{}, err
108110
}
109111

110-
func (r *PacketClusterReconciler) reconcileNormal(ctx context.Context, clusterScope *scope.ClusterScope) (ctrl.Result, error) {
112+
func (r *PacketClusterReconciler) reconcileNormal(ctx context.Context, clusterScope *scope.ClusterScope) error {
111113
log := ctrl.LoggerFrom(ctx).WithValues("cluster", clusterScope.Cluster.Name)
112114
log.Info("Reconciling PacketCluster")
113115

@@ -131,15 +133,15 @@ func (r *PacketClusterReconciler) reconcileNormal(ctx context.Context, clusterSc
131133
ip, err := r.PacketClient.CreateIP(ctx, clusterScope.Namespace(), clusterScope.Name(), packetCluster.Spec.ProjectID, facility, metro)
132134
if err != nil {
133135
log.Error(err, "error reserving an ip")
134-
return ctrl.Result{}, err
136+
return err
135137
}
136138
clusterScope.PacketCluster.Spec.ControlPlaneEndpoint = clusterv1.APIEndpoint{
137139
Host: ip.To4().String(),
138140
Port: 6443,
139141
}
140142
case err != nil:
141143
log.Error(err, "error getting cluster IP")
142-
return ctrl.Result{}, err
144+
return err
143145
default:
144146
// If there is an ElasticIP with the right tag just use it again
145147
clusterScope.PacketCluster.Spec.ControlPlaneEndpoint = clusterv1.APIEndpoint{
@@ -151,14 +153,14 @@ func (r *PacketClusterReconciler) reconcileNormal(ctx context.Context, clusterSc
151153
if clusterScope.PacketCluster.Spec.VIPManager == "KUBE_VIP" {
152154
if err := r.PacketClient.EnableProjectBGP(ctx, packetCluster.Spec.ProjectID); err != nil {
153155
log.Error(err, "error enabling bgp for project")
154-
return ctrl.Result{}, err
156+
return err
155157
}
156158
}
157159

158160
clusterScope.PacketCluster.Status.Ready = true
159161
conditions.MarkTrue(packetCluster, infrav1.NetworkInfrastructureReadyCondition)
160162

161-
return ctrl.Result{}, nil
163+
return nil
162164
}
163165

164166
func (r *PacketClusterReconciler) reconcileDelete(_ context.Context, _ *scope.ClusterScope) (ctrl.Result, error) {

controllers/packetmachine_controller.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,8 @@ func (r *PacketMachineReconciler) Reconcile(ctx context.Context, req ctrl.Reques
143143

144144
// Handle deleted machines
145145
if !packetmachine.ObjectMeta.DeletionTimestamp.IsZero() {
146-
return r.reconcileDelete(ctx, machineScope)
146+
err = r.reconcileDelete(ctx, machineScope)
147+
return ctrl.Result{}, err
147148
}
148149

149150
return r.reconcile(ctx, machineScope)
@@ -435,7 +436,7 @@ func (r *PacketMachineReconciler) reconcile(ctx context.Context, machineScope *s
435436
return result, nil
436437
}
437438

438-
func (r *PacketMachineReconciler) reconcileDelete(ctx context.Context, machineScope *scope.MachineScope) (ctrl.Result, error) {
439+
func (r *PacketMachineReconciler) reconcileDelete(ctx context.Context, machineScope *scope.MachineScope) error {
439440
log := ctrl.LoggerFrom(ctx, "machine", machineScope.Machine.Name, "cluster", machineScope.Cluster.Name)
440441
log.Info("Reconciling Delete PacketMachine")
441442

@@ -453,13 +454,13 @@ func (r *PacketMachineReconciler) reconcileDelete(ctx context.Context, machineSc
453454
packet.DefaultCreateTags(machineScope.Namespace(), machineScope.Machine.Name, machineScope.Cluster.Name),
454455
)
455456
if err != nil {
456-
return ctrl.Result{}, err
457+
return err
457458
}
458459

459460
if dev == nil {
460461
log.Info("Server not found by tags, nothing left to do")
461462
controllerutil.RemoveFinalizer(packetmachine, infrav1.MachineFinalizer)
462-
return ctrl.Result{}, nil
463+
return nil
463464
}
464465

465466
device = dev
@@ -474,18 +475,18 @@ func (r *PacketMachineReconciler) reconcileDelete(ctx context.Context, machineSc
474475
// Probably somebody manually deleted the server from the UI or via API.
475476
log.Info("Server not found by id, nothing left to do")
476477
controllerutil.RemoveFinalizer(packetmachine, infrav1.MachineFinalizer)
477-
return ctrl.Result{}, nil
478+
return nil
478479
}
479480

480481
if resp.StatusCode == http.StatusForbidden {
481482
// When a server fails to provision it will return a 403
482483
log.Info("Server appears to have failed provisioning, nothing left to do")
483484
controllerutil.RemoveFinalizer(packetmachine, infrav1.MachineFinalizer)
484-
return ctrl.Result{}, nil
485+
return nil
485486
}
486487
}
487488

488-
return ctrl.Result{}, fmt.Errorf("error retrieving machine status %s: %w", packetmachine.Name, err)
489+
return fmt.Errorf("error retrieving machine status %s: %w", packetmachine.Name, err)
489490
}
490491

491492
device = dev
@@ -499,9 +500,9 @@ func (r *PacketMachineReconciler) reconcileDelete(ctx context.Context, machineSc
499500

500501
apiRequest := r.PacketClient.DevicesApi.DeleteDevice(ctx, device.GetId()).ForceDelete(force)
501502
if _, err := apiRequest.Execute(); err != nil { //nolint:bodyclose // see https://github.com/timakin/bodyclose/issues/42
502-
return ctrl.Result{}, fmt.Errorf("failed to delete the machine: %w", err)
503+
return fmt.Errorf("failed to delete the machine: %w", err)
503504
}
504505

505506
controllerutil.RemoveFinalizer(packetmachine, infrav1.MachineFinalizer)
506-
return ctrl.Result{}, nil
507+
return nil
507508
}

0 commit comments

Comments
 (0)