Allow references to groups by name (#195)

Group names are unique so we can safely use the name as a reference
method to groups. This makes assigning resources created in the cluster
to groups that already exist a lot easier.
This commit is contained in:
Philip Laine
2026-04-23 13:12:09 +02:00
committed by GitHub
parent 1a593dafc2
commit 99ef70603f
14 changed files with 139 additions and 71 deletions
+10 -4
View File
@@ -11,16 +11,22 @@ import (
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) {
func GetGroupIDs(ctx context.Context, k8sClient client.Client, nbClient *netbird.Client, refs []nbv1alpha1.GroupReference, namespace string) ([]string, error) {
groupIDs := []string{}
for _, ref := range refs {
switch {
case ref.ID != nil:
_, err := nbClient.Groups.Get(ctx, *ref.ID)
case ref.Name != nil:
group, err := nbClient.Groups.GetByName(ctx, *ref.Name)
if err != nil {
return nil, err
}
groupIDs = append(groupIDs, *ref.ID)
groupIDs = append(groupIDs, group.Id)
case ref.ID != nil:
group, err := nbClient.Groups.Get(ctx, *ref.ID)
if err != nil {
return nil, err
}
groupIDs = append(groupIDs, group.Id)
case ref.LocalRef != nil:
group := nbv1alpha1.Group{
ObjectMeta: metav1.ObjectMeta{