Files
netbird-kubernetes-operator/internal/netbirdutil/group.go
T
Philip LaineandGitHub 6768a76c9c Add network router and resource (#189)
This change adds two new resources, NetworkRouter and NetworkResource,
which enable clusters to expose Kubernetes services to Netbird.

The NetworkRouter is responsible for creating the network, group, setup
key and routing peer all of which are unique to the isntance. Along with
the deployment of the client in the cluster.

The NetworkResource exposes a service by linking to the specific router
it wants to expose to. This makes coupling between the resource and
network easy to understand.

Routers also set a DNS zone which is used to give names to resources
based on the name and namespace of the service being exposed.

Part of #172

Signed-off-by: Philip Laine <philip.laine@gmail.com>
2026-04-23 08:55:49 +02:00

43 lines
1.1 KiB
Go

package netbirdutil
import (
"context"
"fmt"
netbird "github.com/netbirdio/netbird/shared/management/client/rest"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
nbv1alpha1 "github.com/netbirdio/kubernetes-operator/api/v1alpha1"
)
func GetGroupIDs(ctx context.Context, k8sClient client.Client, nbClient *netbird.Client, refs []nbv1alpha1.ResourceReference, namespace string) ([]string, error) {
groupIDs := []string{}
for _, ref := range refs {
switch {
case ref.ID != nil:
_, err := nbClient.Groups.Get(ctx, *ref.ID)
if err != nil {
return nil, err
}
groupIDs = append(groupIDs, *ref.ID)
case ref.LocalRef != nil:
group := nbv1alpha1.Group{
ObjectMeta: metav1.ObjectMeta{
Name: ref.LocalRef.Name,
Namespace: namespace,
},
}
err := k8sClient.Get(ctx, client.ObjectKeyFromObject(&group), &group)
if err != nil {
return nil, err
}
if group.Status.GroupID == "" {
return nil, fmt.Errorf("group %s in groups list is not ready", group.Name)
}
groupIDs = append(groupIDs, group.Status.GroupID)
}
}
return groupIDs, nil
}