func (r *routes) ListRoutes(ctx context.Context, clusterName string) ([]*cloudprovider.Route, error) {
	const op = "hcloud/ListRoutes"
	if err := r.reloadNetwork(ctx); err != nil {
		return nil, fmt.Errorf("%s: %w", op, err)
	}
	var routes []*cloudprovider.Route
	for _, route := range r.network.Routes {
		ro, err := r.hcloudRouteToRoute(route)
		if err != nil {
			if errors.Is(err, hcops.ErrNotFound) {
				klog.InfoS("server for route not found, deleting route in hcloud because the route is not functional",
					"op", op, "gateway", route.Gateway.String(), "err", fmt.Sprintf("%v", err))
				err = r.deleteRouteFromHcloud(ctx, route.Destination, route.Gateway)
				if err != nil {
					klog.InfoS("deleting the route failed, continue",
						"op", op, "gateway", route.Gateway.String(), "err", fmt.Sprintf("%v", err))
				}
				continue
			}
			return routes, fmt.Errorf("%s: %w", op, err)
		}
		routes = append(routes, ro)
	}
	return routes, nil
}
ListRoutes lists all managed routes that belong to the specified clusterName
package hcloud
import (
	"context"
	"errors"
	"fmt"
	"net"
	"time"
	"github.com/hetznercloud/hcloud-cloud-controller-manager/internal/hcops"
	"github.com/hetznercloud/hcloud-go/hcloud"
	"k8s.io/apimachinery/pkg/types"
	cloudprovider "k8s.io/cloud-provider"
	"k8s.io/klog/v2"
)
type routes struct {
	client      *hcloud.Client
	network     *hcloud.Network
	serverCache *hcops.AllServersCache
}
func newRoutes(client *hcloud.Client, networkID int) (*routes, error) {
	const op = "hcloud/newRoutes"
	networkObj, _, err := client.Network.GetByID(context.Background(), networkID)
	if err != nil {
		return nil, fmt.Errorf("%s: %w", op, err)
	}
	if networkObj == nil {
		return nil, fmt.Errorf("network not found: %d", networkID)
	}
	return &routes{
		client:      client,
		network:     networkObj,
		serverCache: &hcops.AllServersCache{LoadFunc: client.Server.All},
	}, nil
}
func (r *routes) reloadNetwork(ctx context.Context) error {
	const op = "hcloud/reloadNetwork"
	networkObj, _, err := r.client.Network.GetByID(ctx, r.network.ID)
	if err != nil {
		return fmt.Errorf("%s: %w", op, err)
	}
	if networkObj == nil {
		return fmt.Errorf("network not found: %s", r.network.Name)
	}
	r.network = networkObj
	return nil
}