Update Gateway API to use new resources (#201)

We dont want to promote the use of the "old" resources with NB prefix so
the Gateway API integration should only support the new ones.

---------

Signed-off-by: Philip Laine <philip.laine@gmail.com>
This commit is contained in:
Philip Laine
2026-04-23 16:11:15 +02:00
committed by GitHub
parent 99ef70603f
commit 876a0e1eb3
10 changed files with 209 additions and 219 deletions
+10 -10
View File
@@ -10,7 +10,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
gwv1 "sigs.k8s.io/gateway-api/apis/v1"
netbirdiov1 "github.com/netbirdio/kubernetes-operator/api/v1"
nbv1alpha1 "github.com/netbirdio/kubernetes-operator/api/v1alpha1"
)
func GetParentGateway(ctx context.Context, k8sClient client.Client, parent gwv1.ParentReference, namespace, controllerName string) (*gwv1.Gateway, error) {
@@ -36,29 +36,29 @@ func GetParentGateway(ctx context.Context, k8sClient client.Client, parent gwv1.
return gw, nil
}
func GetGatewayRoutingPeer(ctx context.Context, k8sClient client.Client, gw gwv1.Gateway) (*netbirdiov1.NBRoutingPeer, error) {
routingPeerName, err := GetRoutingPeerName(gw.Spec.Listeners)
func GetGatewayNetworkRouter(ctx context.Context, k8sClient client.Client, gw *gwv1.Gateway) (*nbv1alpha1.NetworkRouter, error) {
netRouterName, err := GetNetworkRouterName(gw.Spec.Listeners)
if err != nil {
return nil, err
}
nbrp := &netbirdiov1.NBRoutingPeer{}
err = k8sClient.Get(ctx, types.NamespacedName{Namespace: gw.Namespace, Name: routingPeerName}, nbrp)
netRouter := &nbv1alpha1.NetworkRouter{}
err = k8sClient.Get(ctx, types.NamespacedName{Namespace: gw.Namespace, Name: netRouterName}, netRouter)
if err != nil {
return nil, err
}
return nbrp, nil
return netRouter, nil
}
func GetRoutingPeerName(listeners []gwv1.Listener) (string, error) {
func GetNetworkRouterName(listeners []gwv1.Listener) (string, error) {
if len(listeners) > 1 {
return "", errors.New("netbird Gateway only supports a single listener")
}
group, kind, ok := strings.Cut(string(listeners[0].Protocol), "/")
if !ok {
return "", fmt.Errorf("invalid protocol %s, expected gateway.netbird.io/NBRoutingPeer", listeners[0].Protocol)
return "", fmt.Errorf("invalid protocol %s, expected gateway.netbird.io/NetworkRouter", listeners[0].Protocol)
}
if group != "gateway.netbird.io" || kind != "NBRoutingPeer" {
return "", fmt.Errorf("invalid group %s and kind %s, expected gateway.netbird.io/NBRoutingPeer", group, kind)
if group != "gateway.netbird.io" || kind != "NetworkRouter" {
return "", fmt.Errorf("invalid group %s and kind %s, expected gateway.netbird.io/NetworkRouter", group, kind)
}
return string(listeners[0].Name), nil
}