in controllers/daemon/podendpoint_controller.go [62:99]
func (r *PodEndpointReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
log := log.FromContext(ctx)
// Got an event from cleanup ticker
if req.NamespacedName.Namespace == "" && req.NamespacedName.Name == "" {
if err := r.cleanUp(ctx); err != nil {
return ctrl.Result{}, fmt.Errorf("failed to clean up orphaned wireguard peers: %w", err)
}
}
podEndpoint := &egressgatewayv1alpha1.PodEndpoint{}
if err := r.Get(ctx, req.NamespacedName, podEndpoint); err != nil {
if apierrors.IsNotFound(err) {
// Object not found, return.
return ctrl.Result{}, nil
}
log.Error(err, "unable to fetch PodEndpoint instance")
return ctrl.Result{}, err
}
gwConfigKey := types.NamespacedName{
Namespace: podEndpoint.Namespace,
Name: podEndpoint.Spec.StaticGatewayConfiguration,
}
// Fetch the StaticGatewayConfiguration instance.
gwConfig := &egressgatewayv1alpha1.StaticGatewayConfiguration{}
if err := r.Get(ctx, gwConfigKey, gwConfig); err != nil {
return ctrl.Result{}, fmt.Errorf("failed to fetch StaticGatewayConfiguration(%s/%s): %w", gwConfigKey.Namespace, gwConfigKey.Name, err)
}
if !applyToNode(gwConfig) {
// gwConfig does not apply to this node
return ctrl.Result{}, nil
}
// Reconcile wireguard peer
return r.reconcile(ctx, gwConfig, podEndpoint)
}