mirror of
https://github.com/YuzuZensai/netbird-kubernetes-operator.git
synced 2026-09-13 10:49:15 +00:00
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>
This commit is contained in:
@@ -3,7 +3,6 @@ package controller
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/fluxcd/pkg/runtime/conditions"
|
||||
@@ -12,7 +11,6 @@ import (
|
||||
"github.com/netbirdio/netbird/shared/management/http/api"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
kerrors "k8s.io/apimachinery/pkg/api/errors"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
corev1ac "k8s.io/client-go/applyconfigurations/core/v1"
|
||||
"k8s.io/utils/ptr"
|
||||
ctrl "sigs.k8s.io/controller-runtime"
|
||||
@@ -20,6 +18,7 @@ import (
|
||||
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
|
||||
|
||||
nbv1alpha1 "github.com/netbirdio/kubernetes-operator/api/v1alpha1"
|
||||
"github.com/netbirdio/kubernetes-operator/internal/netbirdutil"
|
||||
"github.com/netbirdio/kubernetes-operator/internal/ssautil"
|
||||
)
|
||||
|
||||
@@ -52,32 +51,9 @@ func (r *SetupKeyReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c
|
||||
return r.reconcileDelete(ctx, sp, setupKey)
|
||||
}
|
||||
|
||||
// Get ids for auto groups.
|
||||
autoGroupIDs := []string{}
|
||||
for _, ref := range setupKey.Spec.AutoGroups {
|
||||
switch {
|
||||
case ref.ID != nil:
|
||||
_, err := r.Netbird.Groups.Get(ctx, *ref.ID)
|
||||
if err != nil {
|
||||
return ctrl.Result{}, err
|
||||
}
|
||||
autoGroupIDs = append(autoGroupIDs, *ref.ID)
|
||||
case ref.LocalRef != nil:
|
||||
group := nbv1alpha1.Group{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: ref.LocalRef.Name,
|
||||
Namespace: setupKey.Namespace,
|
||||
},
|
||||
}
|
||||
err = r.Client.Get(ctx, client.ObjectKeyFromObject(&group), &group)
|
||||
if err != nil {
|
||||
return ctrl.Result{}, err
|
||||
}
|
||||
if group.Status.GroupID == "" {
|
||||
return ctrl.Result{}, fmt.Errorf("group %s in auto groups list is not ready", group.Name)
|
||||
}
|
||||
autoGroupIDs = append(autoGroupIDs, group.Status.GroupID)
|
||||
}
|
||||
autoGroupIDs, err := netbirdutil.GetGroupIDs(ctx, r.Client, r.Netbird, setupKey.Spec.AutoGroups, setupKey.Namespace)
|
||||
if err != nil {
|
||||
return ctrl.Result{}, err
|
||||
}
|
||||
|
||||
controllerutil.AddFinalizer(setupKey, nbv1alpha1.NetbirdFinalizer)
|
||||
@@ -151,7 +127,7 @@ func (r *SetupKeyReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c
|
||||
AutoGroups: autoGroupIDs,
|
||||
Ephemeral: ptr.To(setupKey.Spec.Ephemeral),
|
||||
ExpiresIn: expiresIn,
|
||||
Name: req.Name,
|
||||
Name: setupKey.Spec.Name,
|
||||
Type: "reusable",
|
||||
UsageLimit: 0,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user