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

chore: refactor controller #185

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Prev Previous commit
Next Next commit
fixes
  • Loading branch information
jodevsa committed Jul 7, 2024
commit b31625fed44c8a52932f753b48e2e6dd3f1d2a9b
18 changes: 4 additions & 14 deletions pkg/controllers/wireguardpeer_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,6 @@ func (r *WireguardPeerReconciler) Reconcile(ctx context.Context, req ctrl.Reques
}

if wireguard.Status.Status != v1alpha1.Ready {
log.Info("Waiting for wireguard to be ready")

err = r.updateStatus(ctx, newPeer, v1alpha1.Error, fmt.Sprintf("Waiting for %s to be ready", wireguard.Name))

if err != nil {
Expand All @@ -175,15 +173,6 @@ func (r *WireguardPeerReconciler) Reconcile(ctx context.Context, req ctrl.Reques
return ctrl.Result{}, nil
}

wireguardSecret := &corev1.Secret{}
secretRef := ""
for _, resource := range wireguard.Status.Resources {
if resource.Type == "secret" {
secretRef = resource.Name
}
}
err = r.Get(ctx, types.NamespacedName{Name: secretRef, Namespace: newPeer.Namespace}, wireguardSecret)

if len(newPeer.OwnerReferences) == 0 {
log.Info("Waiting for owner reference to be set " + wireguard.Name + " " + newPeer.Name)
ctrl.SetControllerReference(wireguard, newPeer, r.Scheme)
Expand All @@ -193,13 +182,14 @@ func (r *WireguardPeerReconciler) Reconcile(ctx context.Context, req ctrl.Reques
}
newPeer.Labels["app"] = "wireguard"
newPeer.Labels["instance"] = wireguard.Name

err = r.Update(ctx, newPeer)

if err != nil {
log.Error(err, "Failed to update peer with controller reference")
log.Error(err, "Failed to update peer with controller reference and labels")
return ctrl.Result{}, err
}

r.Update(ctx, newPeer)

return ctrl.Result{Requeue: true}, nil
}

Expand Down