mirror of
https://github.com/YuzuZensai/netbird-kubernetes-operator.git
synced 2026-09-13 10:49:15 +00:00
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:
@@ -132,7 +132,7 @@ func (r *NetworkRouterReconciler) Reconcile(ctx context.Context, req ctrl.Reques
|
||||
nbv1alpha1ac.SetupKeySpec().
|
||||
WithName(fmt.Sprintf("networkrouter-%s", uniqueSuffix)).
|
||||
WithEphemeral(true).
|
||||
WithAutoGroups(nbv1alpha1ac.ResourceReference().WithID(group.Status.GroupID)),
|
||||
WithAutoGroups(nbv1alpha1ac.GroupReference().WithID(group.Status.GroupID)),
|
||||
)
|
||||
err = r.Client.Apply(ctx, setupKeyAC)
|
||||
if err != nil {
|
||||
|
||||
@@ -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{
|
||||
|
||||
Reference in New Issue
Block a user