mirror of
https://github.com/YuzuZensai/netbird-kubernetes-operator.git
synced 2026-09-13 10:49:15 +00:00
Share Netbird client between all reconcilers (#122)
This changes the reconcilers to take a netbird client rather than creating their own on setup. Signed-off-by: Philip Laine <philip.laine@gmail.com>
This commit is contained in:
+10
-11
@@ -28,6 +28,8 @@ import (
|
|||||||
// to ensure that exec-entrypoint and run can make use of them.
|
// to ensure that exec-entrypoint and run can make use of them.
|
||||||
_ "k8s.io/client-go/plugin/pkg/client/auth"
|
_ "k8s.io/client-go/plugin/pkg/client/auth"
|
||||||
|
|
||||||
|
netbirdrest "github.com/netbirdio/netbird/shared/management/client/rest"
|
||||||
|
corev1 "k8s.io/api/core/v1"
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
|
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
|
||||||
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
|
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
|
||||||
@@ -38,8 +40,6 @@ import (
|
|||||||
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
|
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
|
||||||
"sigs.k8s.io/controller-runtime/pkg/webhook"
|
"sigs.k8s.io/controller-runtime/pkg/webhook"
|
||||||
|
|
||||||
corev1 "k8s.io/api/core/v1"
|
|
||||||
|
|
||||||
netbirdiov1 "github.com/netbirdio/kubernetes-operator/api/v1"
|
netbirdiov1 "github.com/netbirdio/kubernetes-operator/api/v1"
|
||||||
"github.com/netbirdio/kubernetes-operator/internal/controller"
|
"github.com/netbirdio/kubernetes-operator/internal/controller"
|
||||||
webhooknetbirdiov1 "github.com/netbirdio/kubernetes-operator/internal/webhook/v1"
|
webhooknetbirdiov1 "github.com/netbirdio/kubernetes-operator/internal/webhook/v1"
|
||||||
@@ -225,11 +225,13 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(netbirdAPIKey) > 0 {
|
if len(netbirdAPIKey) > 0 {
|
||||||
|
netbird := netbirdrest.New(managementURL, netbirdAPIKey)
|
||||||
|
|
||||||
if err = (&controller.NBRoutingPeerReconciler{
|
if err = (&controller.NBRoutingPeerReconciler{
|
||||||
Client: mgr.GetClient(),
|
Client: mgr.GetClient(),
|
||||||
|
Netbird: netbird,
|
||||||
ClientImage: clientImage,
|
ClientImage: clientImage,
|
||||||
ClusterName: clusterName,
|
ClusterName: clusterName,
|
||||||
APIKey: netbirdAPIKey,
|
|
||||||
ManagementURL: managementURL,
|
ManagementURL: managementURL,
|
||||||
NamespacedNetworks: namespacedNetworks,
|
NamespacedNetworks: namespacedNetworks,
|
||||||
DefaultLabels: defaultLabelsMap,
|
DefaultLabels: defaultLabelsMap,
|
||||||
@@ -258,8 +260,7 @@ func main() {
|
|||||||
|
|
||||||
if err = (&controller.NBResourceReconciler{
|
if err = (&controller.NBResourceReconciler{
|
||||||
Client: mgr.GetClient(),
|
Client: mgr.GetClient(),
|
||||||
APIKey: netbirdAPIKey,
|
Netbird: netbird,
|
||||||
ManagementURL: managementURL,
|
|
||||||
AllowAutomaticPolicyCreation: allowAutomaticPolicyCreation,
|
AllowAutomaticPolicyCreation: allowAutomaticPolicyCreation,
|
||||||
ClusterName: clusterName,
|
ClusterName: clusterName,
|
||||||
DefaultLabels: defaultLabelsMap,
|
DefaultLabels: defaultLabelsMap,
|
||||||
@@ -269,18 +270,16 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if err = (&controller.NBGroupReconciler{
|
if err = (&controller.NBGroupReconciler{
|
||||||
Client: mgr.GetClient(),
|
Client: mgr.GetClient(),
|
||||||
APIKey: netbirdAPIKey,
|
Netbird: netbird,
|
||||||
ManagementURL: managementURL,
|
|
||||||
}).SetupWithManager(mgr); err != nil {
|
}).SetupWithManager(mgr); err != nil {
|
||||||
setupLog.Error(err, "unable to create controller", "controller", "NBGroup")
|
setupLog.Error(err, "unable to create controller", "controller", "NBGroup")
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = (&controller.NBPolicyReconciler{
|
if err = (&controller.NBPolicyReconciler{
|
||||||
Client: mgr.GetClient(),
|
Client: mgr.GetClient(),
|
||||||
APIKey: netbirdAPIKey,
|
Netbird: netbird,
|
||||||
ManagementURL: managementURL,
|
|
||||||
}).SetupWithManager(mgr); err != nil {
|
}).SetupWithManager(mgr); err != nil {
|
||||||
setupLog.Error(err, "unable to create controller", "controller", "NBPolicy")
|
setupLog.Error(err, "unable to create controller", "controller", "NBPolicy")
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
|||||||
@@ -21,9 +21,7 @@ import (
|
|||||||
type NBGroupReconciler struct {
|
type NBGroupReconciler struct {
|
||||||
client.Client
|
client.Client
|
||||||
|
|
||||||
APIKey string
|
Netbird *netbird.Client
|
||||||
ManagementURL string
|
|
||||||
netbird *netbird.Client
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -82,7 +80,7 @@ func (r *NBGroupReconciler) Reconcile(ctx context.Context, req ctrl.Request) (re
|
|||||||
// syncNetBirdGroup reconciliation logic for non-deleted objects.
|
// syncNetBirdGroup reconciliation logic for non-deleted objects.
|
||||||
func (r *NBGroupReconciler) syncNetBirdGroup(ctx context.Context, nbGroup *netbirdiov1.NBGroup, logger logr.Logger) (ctrl.Result, error) {
|
func (r *NBGroupReconciler) syncNetBirdGroup(ctx context.Context, nbGroup *netbirdiov1.NBGroup, logger logr.Logger) (ctrl.Result, error) {
|
||||||
// Get all NetBird groups to ensure no group duplication
|
// Get all NetBird groups to ensure no group duplication
|
||||||
groups, err := r.netbird.Groups.List(ctx)
|
groups, err := r.Netbird.Groups.List(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error(errNetBirdAPI, "error listing groups", "err", err)
|
logger.Error(errNetBirdAPI, "error listing groups", "err", err)
|
||||||
return ctrl.Result{}, err
|
return ctrl.Result{}, err
|
||||||
@@ -97,7 +95,7 @@ func (r *NBGroupReconciler) syncNetBirdGroup(ctx context.Context, nbGroup *netbi
|
|||||||
// Create group if not exists, and update status.groupId
|
// Create group if not exists, and update status.groupId
|
||||||
if nbGroup.Status.GroupID == nil && group == nil {
|
if nbGroup.Status.GroupID == nil && group == nil {
|
||||||
logger.Info("NBGroup: Creating group on NetBird", "name", nbGroup.Spec.Name)
|
logger.Info("NBGroup: Creating group on NetBird", "name", nbGroup.Spec.Name)
|
||||||
group, err := r.netbird.Groups.Create(ctx, api.GroupRequest{
|
group, err := r.Netbird.Groups.Create(ctx, api.GroupRequest{
|
||||||
Name: nbGroup.Spec.Name,
|
Name: nbGroup.Spec.Name,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -144,7 +142,7 @@ func (r *NBGroupReconciler) handleDelete(ctx context.Context, nbGroup netbirdiov
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
err := r.netbird.Groups.Delete(ctx, *nbGroup.Status.GroupID)
|
err := r.Netbird.Groups.Delete(ctx, *nbGroup.Status.GroupID)
|
||||||
if err != nil && !strings.Contains(err.Error(), "not found") && !strings.Contains(err.Error(), "linked") {
|
if err != nil && !strings.Contains(err.Error(), "not found") && !strings.Contains(err.Error(), "linked") {
|
||||||
logger.Error(errNetBirdAPI, "error deleting group", "err", err)
|
logger.Error(errNetBirdAPI, "error deleting group", "err", err)
|
||||||
return err
|
return err
|
||||||
@@ -193,8 +191,6 @@ func (r *NBGroupReconciler) handleDelete(ctx context.Context, nbGroup netbirdiov
|
|||||||
|
|
||||||
// SetupWithManager sets up the controller with the Manager.
|
// SetupWithManager sets up the controller with the Manager.
|
||||||
func (r *NBGroupReconciler) SetupWithManager(mgr ctrl.Manager) error {
|
func (r *NBGroupReconciler) SetupWithManager(mgr ctrl.Manager) error {
|
||||||
r.netbird = netbird.New(r.ManagementURL, r.APIKey)
|
|
||||||
|
|
||||||
return ctrl.NewControllerManagedBy(mgr).
|
return ctrl.NewControllerManagedBy(mgr).
|
||||||
For(&netbirdiov1.NBGroup{}).
|
For(&netbirdiov1.NBGroup{}).
|
||||||
Named("nbgroup").
|
Named("nbgroup").
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ var _ = Describe("NBGroup Controller", func() {
|
|||||||
By("Reconciling the created resource")
|
By("Reconciling the created resource")
|
||||||
controllerReconciler := &NBGroupReconciler{
|
controllerReconciler := &NBGroupReconciler{
|
||||||
Client: k8sClient,
|
Client: k8sClient,
|
||||||
netbird: netbirdClient,
|
Netbird: netbirdClient,
|
||||||
}
|
}
|
||||||
|
|
||||||
mux.HandleFunc("/api/groups", func(w http.ResponseWriter, r *http.Request) {
|
mux.HandleFunc("/api/groups", func(w http.ResponseWriter, r *http.Request) {
|
||||||
@@ -123,7 +123,7 @@ var _ = Describe("NBGroup Controller", func() {
|
|||||||
By("Reconciling the created resource")
|
By("Reconciling the created resource")
|
||||||
controllerReconciler := &NBGroupReconciler{
|
controllerReconciler := &NBGroupReconciler{
|
||||||
Client: k8sClient,
|
Client: k8sClient,
|
||||||
netbird: netbirdClient,
|
Netbird: netbirdClient,
|
||||||
}
|
}
|
||||||
|
|
||||||
mux.HandleFunc("/api/groups", func(w http.ResponseWriter, r *http.Request) {
|
mux.HandleFunc("/api/groups", func(w http.ResponseWriter, r *http.Request) {
|
||||||
@@ -172,7 +172,7 @@ var _ = Describe("NBGroup Controller", func() {
|
|||||||
By("Reconciling the deleting resource")
|
By("Reconciling the deleting resource")
|
||||||
controllerReconciler := &NBGroupReconciler{
|
controllerReconciler := &NBGroupReconciler{
|
||||||
Client: k8sClient,
|
Client: k8sClient,
|
||||||
netbird: netbirdClient,
|
Netbird: netbirdClient,
|
||||||
}
|
}
|
||||||
|
|
||||||
method := ""
|
method := ""
|
||||||
@@ -198,7 +198,7 @@ var _ = Describe("NBGroup Controller", func() {
|
|||||||
By("Reconciling the deleting resource")
|
By("Reconciling the deleting resource")
|
||||||
controllerReconciler := &NBGroupReconciler{
|
controllerReconciler := &NBGroupReconciler{
|
||||||
Client: k8sClient,
|
Client: k8sClient,
|
||||||
netbird: netbirdClient,
|
Netbird: netbirdClient,
|
||||||
}
|
}
|
||||||
|
|
||||||
method := ""
|
method := ""
|
||||||
@@ -239,7 +239,7 @@ var _ = Describe("NBGroup Controller", func() {
|
|||||||
By("Reconciling the deleting resource")
|
By("Reconciling the deleting resource")
|
||||||
controllerReconciler := &NBGroupReconciler{
|
controllerReconciler := &NBGroupReconciler{
|
||||||
Client: k8sClient,
|
Client: k8sClient,
|
||||||
netbird: netbirdClient,
|
Netbird: netbirdClient,
|
||||||
}
|
}
|
||||||
|
|
||||||
method := ""
|
method := ""
|
||||||
@@ -266,7 +266,7 @@ var _ = Describe("NBGroup Controller", func() {
|
|||||||
It("should re-use existing group ID", func() {
|
It("should re-use existing group ID", func() {
|
||||||
controllerReconciler := &NBGroupReconciler{
|
controllerReconciler := &NBGroupReconciler{
|
||||||
Client: k8sClient,
|
Client: k8sClient,
|
||||||
netbird: netbirdClient,
|
Netbird: netbirdClient,
|
||||||
}
|
}
|
||||||
|
|
||||||
mux.HandleFunc("/api/groups", func(w http.ResponseWriter, r *http.Request) {
|
mux.HandleFunc("/api/groups", func(w http.ResponseWriter, r *http.Request) {
|
||||||
@@ -303,7 +303,7 @@ var _ = Describe("NBGroup Controller", func() {
|
|||||||
It("Should requeue and create group on next run", func() {
|
It("Should requeue and create group on next run", func() {
|
||||||
controllerReconciler := &NBGroupReconciler{
|
controllerReconciler := &NBGroupReconciler{
|
||||||
Client: k8sClient,
|
Client: k8sClient,
|
||||||
netbird: netbirdClient,
|
Netbird: netbirdClient,
|
||||||
}
|
}
|
||||||
|
|
||||||
mux.HandleFunc("/api/groups", func(w http.ResponseWriter, r *http.Request) {
|
mux.HandleFunc("/api/groups", func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|||||||
@@ -23,10 +23,8 @@ import (
|
|||||||
type NBPolicyReconciler struct {
|
type NBPolicyReconciler struct {
|
||||||
client.Client
|
client.Client
|
||||||
|
|
||||||
ClusterName string
|
Netbird *netbird.Client
|
||||||
APIKey string
|
ClusterName string
|
||||||
ManagementURL string
|
|
||||||
netbird *netbird.Client
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -119,7 +117,7 @@ func (r *NBPolicyReconciler) mapResources(ctx context.Context, nbPolicy *netbird
|
|||||||
func (r *NBPolicyReconciler) createPolicy(ctx context.Context, nbPolicy *netbirdiov1.NBPolicy, protocol string, sourceGroupIDs, destinationGroupIDs, ports []string, logger logr.Logger) (*string, error) {
|
func (r *NBPolicyReconciler) createPolicy(ctx context.Context, nbPolicy *netbirdiov1.NBPolicy, protocol string, sourceGroupIDs, destinationGroupIDs, ports []string, logger logr.Logger) (*string, error) {
|
||||||
policyName := fmt.Sprintf("%s %s", nbPolicy.Spec.Name, strings.ToUpper(protocol))
|
policyName := fmt.Sprintf("%s %s", nbPolicy.Spec.Name, strings.ToUpper(protocol))
|
||||||
logger.Info("Creating NetBird Policy", "name", policyName, "description", nbPolicy.Spec.Description, "protocol", protocol, "sources", sourceGroupIDs, "destinations", destinationGroupIDs, "ports", ports, "bidirectional", nbPolicy.Spec.Bidirectional)
|
logger.Info("Creating NetBird Policy", "name", policyName, "description", nbPolicy.Spec.Description, "protocol", protocol, "sources", sourceGroupIDs, "destinations", destinationGroupIDs, "ports", ports, "bidirectional", nbPolicy.Spec.Bidirectional)
|
||||||
policy, err := r.netbird.Policies.Create(ctx, api.PostApiPoliciesJSONRequestBody{
|
policy, err := r.Netbird.Policies.Create(ctx, api.PostApiPoliciesJSONRequestBody{
|
||||||
Enabled: true,
|
Enabled: true,
|
||||||
Name: policyName,
|
Name: policyName,
|
||||||
Description: &nbPolicy.Spec.Description,
|
Description: &nbPolicy.Spec.Description,
|
||||||
@@ -151,7 +149,7 @@ func (r *NBPolicyReconciler) createPolicy(ctx context.Context, nbPolicy *netbird
|
|||||||
func (r *NBPolicyReconciler) updatePolicy(ctx context.Context, policyID *string, nbPolicy *netbirdiov1.NBPolicy, protocol string, sourceGroupIDs, destinationGroupIDs, ports []string, logger logr.Logger) (*string, bool, error) {
|
func (r *NBPolicyReconciler) updatePolicy(ctx context.Context, policyID *string, nbPolicy *netbirdiov1.NBPolicy, protocol string, sourceGroupIDs, destinationGroupIDs, ports []string, logger logr.Logger) (*string, bool, error) {
|
||||||
policyName := fmt.Sprintf("%s %s", nbPolicy.Spec.Name, strings.ToUpper(protocol))
|
policyName := fmt.Sprintf("%s %s", nbPolicy.Spec.Name, strings.ToUpper(protocol))
|
||||||
logger.Info("Updating NetBird Policy", "name", policyName, "description", nbPolicy.Spec.Description, "protocol", protocol, "sources", sourceGroupIDs, "destinations", destinationGroupIDs, "ports", ports, "bidirectional", nbPolicy.Spec.Bidirectional)
|
logger.Info("Updating NetBird Policy", "name", policyName, "description", nbPolicy.Spec.Description, "protocol", protocol, "sources", sourceGroupIDs, "destinations", destinationGroupIDs, "ports", ports, "bidirectional", nbPolicy.Spec.Bidirectional)
|
||||||
_, err := r.netbird.Policies.Update(ctx, *policyID, api.PutApiPoliciesPolicyIdJSONRequestBody{
|
_, err := r.Netbird.Policies.Update(ctx, *policyID, api.PutApiPoliciesPolicyIdJSONRequestBody{
|
||||||
Enabled: true,
|
Enabled: true,
|
||||||
Name: policyName,
|
Name: policyName,
|
||||||
Description: &nbPolicy.Spec.Description,
|
Description: &nbPolicy.Spec.Description,
|
||||||
@@ -285,7 +283,7 @@ func (r *NBPolicyReconciler) syncPolicy(ctx context.Context, nbPolicy *netbirdio
|
|||||||
if len(nbPolicy.Spec.Protocols) > 0 && !slices.Contains(nbPolicy.Spec.Protocols, protocol) {
|
if len(nbPolicy.Spec.Protocols) > 0 && !slices.Contains(nbPolicy.Spec.Protocols, protocol) {
|
||||||
if policyID != nil {
|
if policyID != nil {
|
||||||
logger.Info("Deleting protocol policy as NBPolicy has restricted protocols", "protocol", protocol)
|
logger.Info("Deleting protocol policy as NBPolicy has restricted protocols", "protocol", protocol)
|
||||||
err := r.netbird.Policies.Delete(ctx, *policyID)
|
err := r.Netbird.Policies.Delete(ctx, *policyID)
|
||||||
if err != nil && !strings.Contains(err.Error(), "not found") {
|
if err != nil && !strings.Contains(err.Error(), "not found") {
|
||||||
nbPolicy.Status.Conditions = netbirdiov1.NBConditionFalse("APIError", fmt.Sprintf("Error deleting policy: %v", err))
|
nbPolicy.Status.Conditions = netbirdiov1.NBConditionFalse("APIError", fmt.Sprintf("Error deleting policy: %v", err))
|
||||||
return requeue, err
|
return requeue, err
|
||||||
@@ -307,7 +305,7 @@ func (r *NBPolicyReconciler) syncPolicy(ctx context.Context, nbPolicy *netbirdio
|
|||||||
} else if len(ports) == 0 || len(destGroups) == 0 || len(sourceGroups) == 0 {
|
} else if len(ports) == 0 || len(destGroups) == 0 || len(sourceGroups) == 0 {
|
||||||
// Delete policy
|
// Delete policy
|
||||||
logger.Info("Deleting policy", "protocol", protocol)
|
logger.Info("Deleting policy", "protocol", protocol)
|
||||||
err := r.netbird.Policies.Delete(ctx, *policyID)
|
err := r.Netbird.Policies.Delete(ctx, *policyID)
|
||||||
if err != nil && !strings.Contains(err.Error(), "not found") {
|
if err != nil && !strings.Contains(err.Error(), "not found") {
|
||||||
nbPolicy.Status.Conditions = netbirdiov1.NBConditionFalse("APIError", fmt.Sprintf("Error deleting policy: %v", err))
|
nbPolicy.Status.Conditions = netbirdiov1.NBConditionFalse("APIError", fmt.Sprintf("Error deleting policy: %v", err))
|
||||||
return requeue, err
|
return requeue, err
|
||||||
@@ -350,14 +348,14 @@ func (r *NBPolicyReconciler) syncPolicy(ctx context.Context, nbPolicy *netbirdio
|
|||||||
|
|
||||||
func (r *NBPolicyReconciler) handleDelete(ctx context.Context, nbPolicy *netbirdiov1.NBPolicy, logger logr.Logger) error {
|
func (r *NBPolicyReconciler) handleDelete(ctx context.Context, nbPolicy *netbirdiov1.NBPolicy, logger logr.Logger) error {
|
||||||
if nbPolicy.Status.TCPPolicyID != nil {
|
if nbPolicy.Status.TCPPolicyID != nil {
|
||||||
err := r.netbird.Policies.Delete(ctx, *nbPolicy.Status.TCPPolicyID)
|
err := r.Netbird.Policies.Delete(ctx, *nbPolicy.Status.TCPPolicyID)
|
||||||
if err != nil && !strings.Contains("not found", err.Error()) {
|
if err != nil && !strings.Contains("not found", err.Error()) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
nbPolicy.Status.TCPPolicyID = nil
|
nbPolicy.Status.TCPPolicyID = nil
|
||||||
}
|
}
|
||||||
if nbPolicy.Status.UDPPolicyID != nil {
|
if nbPolicy.Status.UDPPolicyID != nil {
|
||||||
err := r.netbird.Policies.Delete(ctx, *nbPolicy.Status.UDPPolicyID)
|
err := r.Netbird.Policies.Delete(ctx, *nbPolicy.Status.UDPPolicyID)
|
||||||
if err != nil && !strings.Contains("not found", err.Error()) {
|
if err != nil && !strings.Contains("not found", err.Error()) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -376,7 +374,7 @@ func (r *NBPolicyReconciler) handleDelete(ctx context.Context, nbPolicy *netbird
|
|||||||
|
|
||||||
// groupNamesToIDs map list of NetBird group names to group IDs
|
// groupNamesToIDs map list of NetBird group names to group IDs
|
||||||
func (r *NBPolicyReconciler) groupNamesToIDs(ctx context.Context, groupNames []string, logger logr.Logger) ([]string, error) {
|
func (r *NBPolicyReconciler) groupNamesToIDs(ctx context.Context, groupNames []string, logger logr.Logger) ([]string, error) {
|
||||||
groups, err := r.netbird.Groups.List(ctx)
|
groups, err := r.Netbird.Groups.List(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error(errNetBirdAPI, "Error listing Groups", "err", err)
|
logger.Error(errNetBirdAPI, "Error listing Groups", "err", err)
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -397,8 +395,6 @@ func (r *NBPolicyReconciler) groupNamesToIDs(ctx context.Context, groupNames []s
|
|||||||
|
|
||||||
// SetupWithManager sets up the controller with the Manager.
|
// SetupWithManager sets up the controller with the Manager.
|
||||||
func (r *NBPolicyReconciler) SetupWithManager(mgr ctrl.Manager) error {
|
func (r *NBPolicyReconciler) SetupWithManager(mgr ctrl.Manager) error {
|
||||||
r.netbird = netbird.New(r.ManagementURL, r.APIKey)
|
|
||||||
|
|
||||||
return ctrl.NewControllerManagedBy(mgr).
|
return ctrl.NewControllerManagedBy(mgr).
|
||||||
For(&netbirdiov1.NBPolicy{}).
|
For(&netbirdiov1.NBPolicy{}).
|
||||||
Named("nbpolicy").
|
Named("nbpolicy").
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ var _ = Describe("NBPolicy Controller", func() {
|
|||||||
It("should not create any policy", func() {
|
It("should not create any policy", func() {
|
||||||
controllerReconciler := &NBPolicyReconciler{
|
controllerReconciler := &NBPolicyReconciler{
|
||||||
Client: k8sClient,
|
Client: k8sClient,
|
||||||
netbird: netbirdClient,
|
Netbird: netbirdClient,
|
||||||
ClusterName: "Kubernetes",
|
ClusterName: "Kubernetes",
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -118,7 +118,7 @@ var _ = Describe("NBPolicy Controller", func() {
|
|||||||
It("should create 1 policy", func() {
|
It("should create 1 policy", func() {
|
||||||
controllerReconciler := &NBPolicyReconciler{
|
controllerReconciler := &NBPolicyReconciler{
|
||||||
Client: k8sClient,
|
Client: k8sClient,
|
||||||
netbird: netbirdClient,
|
Netbird: netbirdClient,
|
||||||
ClusterName: "Kubernetes",
|
ClusterName: "Kubernetes",
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -216,7 +216,7 @@ var _ = Describe("NBPolicy Controller", func() {
|
|||||||
It("should delete tcp policy", func() {
|
It("should delete tcp policy", func() {
|
||||||
controllerReconciler := &NBPolicyReconciler{
|
controllerReconciler := &NBPolicyReconciler{
|
||||||
Client: k8sClient,
|
Client: k8sClient,
|
||||||
netbird: netbirdClient,
|
Netbird: netbirdClient,
|
||||||
ClusterName: "Kubernetes",
|
ClusterName: "Kubernetes",
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -258,7 +258,7 @@ var _ = Describe("NBPolicy Controller", func() {
|
|||||||
It("should create 1 policy", func() {
|
It("should create 1 policy", func() {
|
||||||
controllerReconciler := &NBPolicyReconciler{
|
controllerReconciler := &NBPolicyReconciler{
|
||||||
Client: k8sClient,
|
Client: k8sClient,
|
||||||
netbird: netbirdClient,
|
Netbird: netbirdClient,
|
||||||
ClusterName: "Kubernetes",
|
ClusterName: "Kubernetes",
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -356,7 +356,7 @@ var _ = Describe("NBPolicy Controller", func() {
|
|||||||
It("should delete udp policy", func() {
|
It("should delete udp policy", func() {
|
||||||
controllerReconciler := &NBPolicyReconciler{
|
controllerReconciler := &NBPolicyReconciler{
|
||||||
Client: k8sClient,
|
Client: k8sClient,
|
||||||
netbird: netbirdClient,
|
Netbird: netbirdClient,
|
||||||
ClusterName: "Kubernetes",
|
ClusterName: "Kubernetes",
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -398,7 +398,7 @@ var _ = Describe("NBPolicy Controller", func() {
|
|||||||
It("Should delete protocol policy", func() {
|
It("Should delete protocol policy", func() {
|
||||||
controllerReconciler := &NBPolicyReconciler{
|
controllerReconciler := &NBPolicyReconciler{
|
||||||
Client: k8sClient,
|
Client: k8sClient,
|
||||||
netbird: netbirdClient,
|
Netbird: netbirdClient,
|
||||||
ClusterName: "Kubernetes",
|
ClusterName: "Kubernetes",
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -478,7 +478,7 @@ var _ = Describe("NBPolicy Controller", func() {
|
|||||||
It("Should give all information to Update method", func() {
|
It("Should give all information to Update method", func() {
|
||||||
controllerReconciler := &NBPolicyReconciler{
|
controllerReconciler := &NBPolicyReconciler{
|
||||||
Client: k8sClient,
|
Client: k8sClient,
|
||||||
netbird: netbirdClient,
|
Netbird: netbirdClient,
|
||||||
ClusterName: "Kubernetes",
|
ClusterName: "Kubernetes",
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -596,7 +596,7 @@ var _ = Describe("NBPolicy Controller", func() {
|
|||||||
It("should delete Policies", func() {
|
It("should delete Policies", func() {
|
||||||
controllerReconciler := &NBPolicyReconciler{
|
controllerReconciler := &NBPolicyReconciler{
|
||||||
Client: k8sClient,
|
Client: k8sClient,
|
||||||
netbird: netbirdClient,
|
Netbird: netbirdClient,
|
||||||
ClusterName: "Kubernetes",
|
ClusterName: "Kubernetes",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -33,12 +33,10 @@ var (
|
|||||||
type NBResourceReconciler struct {
|
type NBResourceReconciler struct {
|
||||||
client.Client
|
client.Client
|
||||||
|
|
||||||
APIKey string
|
Netbird *netbird.Client
|
||||||
ManagementURL string
|
|
||||||
AllowAutomaticPolicyCreation bool
|
AllowAutomaticPolicyCreation bool
|
||||||
ClusterName string
|
ClusterName string
|
||||||
DefaultLabels map[string]string
|
DefaultLabels map[string]string
|
||||||
netbird *netbird.Client
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reconcile is part of the main kubernetes reconciliation loop which aims to
|
// Reconcile is part of the main kubernetes reconciliation loop which aims to
|
||||||
@@ -377,7 +375,7 @@ func (r *NBResourceReconciler) handleGroupUpdate(ctx context.Context, nbResource
|
|||||||
}
|
}
|
||||||
|
|
||||||
if diffFound {
|
if diffFound {
|
||||||
_, err := r.netbird.Networks.Resources(nbResource.Spec.NetworkID).Update(ctx, resource.Id, api.NetworkResourceRequest{
|
_, err := r.Netbird.Networks.Resources(nbResource.Spec.NetworkID).Update(ctx, resource.Id, api.NetworkResourceRequest{
|
||||||
Name: nbResource.Spec.Name,
|
Name: nbResource.Spec.Name,
|
||||||
Description: &networkDescription,
|
Description: &networkDescription,
|
||||||
Address: nbResource.Spec.Address,
|
Address: nbResource.Spec.Address,
|
||||||
@@ -399,7 +397,7 @@ func (r *NBResourceReconciler) handleNetBirdResource(ctx context.Context, nbReso
|
|||||||
var resource *api.NetworkResource
|
var resource *api.NetworkResource
|
||||||
var err error
|
var err error
|
||||||
if nbResource.Status.NetworkResourceID != nil {
|
if nbResource.Status.NetworkResourceID != nil {
|
||||||
resource, err = r.netbird.Networks.Resources(nbResource.Spec.NetworkID).Get(ctx, *nbResource.Status.NetworkResourceID)
|
resource, err = r.Netbird.Networks.Resources(nbResource.Spec.NetworkID).Get(ctx, *nbResource.Status.NetworkResourceID)
|
||||||
if err != nil && !strings.Contains(err.Error(), "not found") {
|
if err != nil && !strings.Contains(err.Error(), "not found") {
|
||||||
logger.Error(errNetBirdAPI, "error getting network resource", "err", err)
|
logger.Error(errNetBirdAPI, "error getting network resource", "err", err)
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -408,7 +406,7 @@ func (r *NBResourceReconciler) handleNetBirdResource(ctx context.Context, nbReso
|
|||||||
|
|
||||||
// Create/Update upstream network resource
|
// Create/Update upstream network resource
|
||||||
if nbResource.Status.NetworkResourceID == nil && resource == nil {
|
if nbResource.Status.NetworkResourceID == nil && resource == nil {
|
||||||
resource, err := r.netbird.Networks.Resources(nbResource.Spec.NetworkID).Create(ctx, api.NetworkResourceRequest{
|
resource, err := r.Netbird.Networks.Resources(nbResource.Spec.NetworkID).Create(ctx, api.NetworkResourceRequest{
|
||||||
Address: nbResource.Spec.Address,
|
Address: nbResource.Spec.Address,
|
||||||
Enabled: true,
|
Enabled: true,
|
||||||
Groups: groupIDs,
|
Groups: groupIDs,
|
||||||
@@ -442,7 +440,7 @@ func (r *NBResourceReconciler) handleNetBirdResource(ctx context.Context, nbReso
|
|||||||
!util.Equivalent(resourceGroups, groupIDs) ||
|
!util.Equivalent(resourceGroups, groupIDs) ||
|
||||||
*resource.Description != networkDescription ||
|
*resource.Description != networkDescription ||
|
||||||
resource.Name != nbResource.Spec.Name {
|
resource.Name != nbResource.Spec.Name {
|
||||||
_, err = r.netbird.Networks.Resources(nbResource.Spec.NetworkID).Update(ctx, *nbResource.Status.NetworkResourceID, api.NetworkResourceRequest{
|
_, err = r.Netbird.Networks.Resources(nbResource.Spec.NetworkID).Update(ctx, *nbResource.Status.NetworkResourceID, api.NetworkResourceRequest{
|
||||||
Address: nbResource.Spec.Address,
|
Address: nbResource.Spec.Address,
|
||||||
Enabled: true,
|
Enabled: true,
|
||||||
Groups: groupIDs,
|
Groups: groupIDs,
|
||||||
@@ -615,7 +613,7 @@ func (r *NBResourceReconciler) handleDelete(ctx context.Context, req ctrl.Reques
|
|||||||
}
|
}
|
||||||
|
|
||||||
if nbResource.Status.NetworkResourceID != nil {
|
if nbResource.Status.NetworkResourceID != nil {
|
||||||
err := r.netbird.Networks.Resources(nbResource.Spec.NetworkID).Delete(ctx, *nbResource.Status.NetworkResourceID)
|
err := r.Netbird.Networks.Resources(nbResource.Spec.NetworkID).Delete(ctx, *nbResource.Status.NetworkResourceID)
|
||||||
if err != nil && !strings.Contains(err.Error(), "not found") {
|
if err != nil && !strings.Contains(err.Error(), "not found") {
|
||||||
logger.Error(errNetBirdAPI, "error deleting resource", "err", err)
|
logger.Error(errNetBirdAPI, "error deleting resource", "err", err)
|
||||||
return err
|
return err
|
||||||
@@ -671,8 +669,6 @@ func (r *NBResourceReconciler) handleDelete(ctx context.Context, req ctrl.Reques
|
|||||||
|
|
||||||
// SetupWithManager sets up the controller with the Manager.
|
// SetupWithManager sets up the controller with the Manager.
|
||||||
func (r *NBResourceReconciler) SetupWithManager(mgr ctrl.Manager) error {
|
func (r *NBResourceReconciler) SetupWithManager(mgr ctrl.Manager) error {
|
||||||
r.netbird = netbird.New(r.ManagementURL, r.APIKey)
|
|
||||||
|
|
||||||
return ctrl.NewControllerManagedBy(mgr).
|
return ctrl.NewControllerManagedBy(mgr).
|
||||||
For(&netbirdiov1.NBResource{}).
|
For(&netbirdiov1.NBResource{}).
|
||||||
Named("nbresource").
|
Named("nbresource").
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ var _ = Describe("NBResource Controller", func() {
|
|||||||
netbirdClient = netbird.New(server.URL, "ABC")
|
netbirdClient = netbird.New(server.URL, "ABC")
|
||||||
controllerReconciler = &NBResourceReconciler{
|
controllerReconciler = &NBResourceReconciler{
|
||||||
Client: k8sClient,
|
Client: k8sClient,
|
||||||
netbird: netbirdClient,
|
Netbird: netbirdClient,
|
||||||
ClusterName: "kubernetes",
|
ClusterName: "kubernetes",
|
||||||
DefaultLabels: map[string]string{"dog": "bark"},
|
DefaultLabels: map[string]string{"dog": "bark"},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,13 +27,12 @@ import (
|
|||||||
type NBRoutingPeerReconciler struct {
|
type NBRoutingPeerReconciler struct {
|
||||||
client.Client
|
client.Client
|
||||||
|
|
||||||
|
Netbird *netbird.Client
|
||||||
ClientImage string
|
ClientImage string
|
||||||
ClusterName string
|
ClusterName string
|
||||||
APIKey string
|
|
||||||
ManagementURL string
|
ManagementURL string
|
||||||
NamespacedNetworks bool
|
NamespacedNetworks bool
|
||||||
DefaultLabels map[string]string
|
DefaultLabels map[string]string
|
||||||
netbird *netbird.Client
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reconcile is part of the main kubernetes reconciliation loop which aims to
|
// Reconcile is part of the main kubernetes reconciliation loop which aims to
|
||||||
@@ -281,7 +280,7 @@ func (r *NBRoutingPeerReconciler) handleDeployment(ctx context.Context, req ctrl
|
|||||||
// handleRouter reconcile network routing peer in NetBird management API
|
// handleRouter reconcile network routing peer in NetBird management API
|
||||||
func (r *NBRoutingPeerReconciler) handleRouter(ctx context.Context, nbrp *netbirdiov1.NBRoutingPeer, nbGroup netbirdiov1.NBGroup, logger logr.Logger) error {
|
func (r *NBRoutingPeerReconciler) handleRouter(ctx context.Context, nbrp *netbirdiov1.NBRoutingPeer, nbGroup netbirdiov1.NBGroup, logger logr.Logger) error {
|
||||||
// Check NetworkRouter exists
|
// Check NetworkRouter exists
|
||||||
routers, err := r.netbird.Networks.Routers(*nbrp.Status.NetworkID).List(ctx)
|
routers, err := r.Netbird.Networks.Routers(*nbrp.Status.NetworkID).List(ctx)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error(errNetBirdAPI, "error listing network routers", "err", err)
|
logger.Error(errNetBirdAPI, "error listing network routers", "err", err)
|
||||||
@@ -295,7 +294,7 @@ func (r *NBRoutingPeerReconciler) handleRouter(ctx context.Context, nbrp *netbir
|
|||||||
nbrp.Status.RouterID = &routers[0].Id
|
nbrp.Status.RouterID = &routers[0].Id
|
||||||
} else {
|
} else {
|
||||||
// Create network router
|
// Create network router
|
||||||
router, err := r.netbird.Networks.Routers(*nbrp.Status.NetworkID).Create(ctx, api.NetworkRouterRequest{
|
router, err := r.Netbird.Networks.Routers(*nbrp.Status.NetworkID).Create(ctx, api.NetworkRouterRequest{
|
||||||
Enabled: true,
|
Enabled: true,
|
||||||
Masquerade: true,
|
Masquerade: true,
|
||||||
Metric: 9999,
|
Metric: 9999,
|
||||||
@@ -313,7 +312,7 @@ func (r *NBRoutingPeerReconciler) handleRouter(ctx context.Context, nbrp *netbir
|
|||||||
} else {
|
} else {
|
||||||
// Ensure network router settings are correct
|
// Ensure network router settings are correct
|
||||||
if !routers[0].Enabled || !routers[0].Masquerade || routers[0].Metric != 9999 || len(*routers[0].PeerGroups) != 1 || (*routers[0].PeerGroups)[0] != *nbGroup.Status.GroupID {
|
if !routers[0].Enabled || !routers[0].Masquerade || routers[0].Metric != 9999 || len(*routers[0].PeerGroups) != 1 || (*routers[0].PeerGroups)[0] != *nbGroup.Status.GroupID {
|
||||||
_, err = r.netbird.Networks.Routers(*nbrp.Status.NetworkID).Update(ctx, routers[0].Id, api.NetworkRouterRequest{
|
_, err = r.Netbird.Networks.Routers(*nbrp.Status.NetworkID).Update(ctx, routers[0].Id, api.NetworkRouterRequest{
|
||||||
Enabled: true,
|
Enabled: true,
|
||||||
Masquerade: true,
|
Masquerade: true,
|
||||||
Metric: 9999,
|
Metric: 9999,
|
||||||
@@ -341,7 +340,7 @@ func (r *NBRoutingPeerReconciler) handleSetupKey(ctx context.Context, req ctrl.R
|
|||||||
// Check if setup key exists
|
// Check if setup key exists
|
||||||
if nbrp.Status.SetupKeyID == nil {
|
if nbrp.Status.SetupKeyID == nil {
|
||||||
// Create new setup key with group Status.GroupID
|
// Create new setup key with group Status.GroupID
|
||||||
setupKey, err := r.netbird.SetupKeys.Create(ctx, api.CreateSetupKeyRequest{
|
setupKey, err := r.Netbird.SetupKeys.Create(ctx, api.CreateSetupKeyRequest{
|
||||||
AutoGroups: []string{*nbGroup.Status.GroupID},
|
AutoGroups: []string{*nbGroup.Status.GroupID},
|
||||||
Ephemeral: util.Ptr(true),
|
Ephemeral: util.Ptr(true),
|
||||||
Name: networkName,
|
Name: networkName,
|
||||||
@@ -395,7 +394,7 @@ func (r *NBRoutingPeerReconciler) handleSetupKey(ctx context.Context, req ctrl.R
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Check SetupKey is not revoked
|
// Check SetupKey is not revoked
|
||||||
setupKey, err := r.netbird.SetupKeys.Get(ctx, *nbrp.Status.SetupKeyID)
|
setupKey, err := r.Netbird.SetupKeys.Get(ctx, *nbrp.Status.SetupKeyID)
|
||||||
if err != nil && !strings.Contains(err.Error(), "not found") {
|
if err != nil && !strings.Contains(err.Error(), "not found") {
|
||||||
logger.Error(errNetBirdAPI, "error getting setup key", "err", err)
|
logger.Error(errNetBirdAPI, "error getting setup key", "err", err)
|
||||||
nbrp.Status.Conditions = netbirdiov1.NBConditionFalse("APIError", fmt.Sprintf("error getting setup key: %v", err))
|
nbrp.Status.Conditions = netbirdiov1.NBConditionFalse("APIError", fmt.Sprintf("error getting setup key: %v", err))
|
||||||
@@ -404,7 +403,7 @@ func (r *NBRoutingPeerReconciler) handleSetupKey(ctx context.Context, req ctrl.R
|
|||||||
|
|
||||||
if (err != nil && strings.Contains(err.Error(), "not found")) || setupKey == nil || setupKey.Revoked {
|
if (err != nil && strings.Contains(err.Error(), "not found")) || setupKey == nil || setupKey.Revoked {
|
||||||
if setupKey != nil && setupKey.Revoked {
|
if setupKey != nil && setupKey.Revoked {
|
||||||
err = r.netbird.SetupKeys.Delete(ctx, *nbrp.Status.SetupKeyID)
|
err = r.Netbird.SetupKeys.Delete(ctx, *nbrp.Status.SetupKeyID)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error(errNetBirdAPI, "error deleting setup key", "err", err)
|
logger.Error(errNetBirdAPI, "error deleting setup key", "err", err)
|
||||||
@@ -430,7 +429,7 @@ func (r *NBRoutingPeerReconciler) handleSetupKey(ctx context.Context, req ctrl.R
|
|||||||
if _, ok := skSecret.Data["setupKey"]; errors.IsNotFound(err) || !ok {
|
if _, ok := skSecret.Data["setupKey"]; errors.IsNotFound(err) || !ok {
|
||||||
// Someone deleted setup key secret
|
// Someone deleted setup key secret
|
||||||
// Revoke SK from NetBird and re-generate
|
// Revoke SK from NetBird and re-generate
|
||||||
err = r.netbird.SetupKeys.Delete(ctx, *nbrp.Status.SetupKeyID)
|
err = r.Netbird.SetupKeys.Delete(ctx, *nbrp.Status.SetupKeyID)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error(errNetBirdAPI, "error deleting setup key", "err", err)
|
logger.Error(errNetBirdAPI, "error deleting setup key", "err", err)
|
||||||
@@ -516,7 +515,7 @@ func (r *NBRoutingPeerReconciler) handleNetwork(ctx context.Context, req ctrl.Re
|
|||||||
|
|
||||||
if nbrp.Status.NetworkID == nil {
|
if nbrp.Status.NetworkID == nil {
|
||||||
// Check if network exists
|
// Check if network exists
|
||||||
networks, err := r.netbird.Networks.List(ctx)
|
networks, err := r.Netbird.Networks.List(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error(errNetBirdAPI, "error listing networks", "err", err)
|
logger.Error(errNetBirdAPI, "error listing networks", "err", err)
|
||||||
nbrp.Status.Conditions = netbirdiov1.NBConditionFalse("APIError", fmt.Sprintf("error listing networks: %v", err))
|
nbrp.Status.Conditions = netbirdiov1.NBConditionFalse("APIError", fmt.Sprintf("error listing networks: %v", err))
|
||||||
@@ -534,7 +533,7 @@ func (r *NBRoutingPeerReconciler) handleNetwork(ctx context.Context, req ctrl.Re
|
|||||||
nbrp.Status.NetworkID = &network.Id
|
nbrp.Status.NetworkID = &network.Id
|
||||||
} else {
|
} else {
|
||||||
logger.Info("creating network", "name", networkName)
|
logger.Info("creating network", "name", networkName)
|
||||||
network, err := r.netbird.Networks.Create(ctx, api.NetworkRequest{
|
network, err := r.Netbird.Networks.Create(ctx, api.NetworkRequest{
|
||||||
Name: networkName,
|
Name: networkName,
|
||||||
Description: &networkDescription,
|
Description: &networkDescription,
|
||||||
})
|
})
|
||||||
@@ -567,7 +566,7 @@ func (r *NBRoutingPeerReconciler) handleDelete(ctx context.Context, req ctrl.Req
|
|||||||
|
|
||||||
if nbrp.Status.SetupKeyID != nil {
|
if nbrp.Status.SetupKeyID != nil {
|
||||||
logger.Info("Deleting setup key", "id", *nbrp.Status.SetupKeyID)
|
logger.Info("Deleting setup key", "id", *nbrp.Status.SetupKeyID)
|
||||||
err = r.netbird.SetupKeys.Delete(ctx, *nbrp.Status.SetupKeyID)
|
err = r.Netbird.SetupKeys.Delete(ctx, *nbrp.Status.SetupKeyID)
|
||||||
if err != nil && !strings.Contains(err.Error(), "not found") {
|
if err != nil && !strings.Contains(err.Error(), "not found") {
|
||||||
logger.Error(errNetBirdAPI, "error deleting setupKey", "err", err)
|
logger.Error(errNetBirdAPI, "error deleting setupKey", "err", err)
|
||||||
return ctrl.Result{}, err
|
return ctrl.Result{}, err
|
||||||
@@ -606,7 +605,7 @@ func (r *NBRoutingPeerReconciler) handleDelete(ctx context.Context, req ctrl.Req
|
|||||||
|
|
||||||
if len(nbResourceList.Items) == 0 {
|
if len(nbResourceList.Items) == 0 {
|
||||||
logger.Info("Deleting NetBird Network", "id", *nbrp.Status.NetworkID)
|
logger.Info("Deleting NetBird Network", "id", *nbrp.Status.NetworkID)
|
||||||
err = r.netbird.Networks.Delete(ctx, *nbrp.Status.NetworkID)
|
err = r.Netbird.Networks.Delete(ctx, *nbrp.Status.NetworkID)
|
||||||
if err != nil && !strings.Contains(err.Error(), "not found") {
|
if err != nil && !strings.Contains(err.Error(), "not found") {
|
||||||
logger.Error(errNetBirdAPI, "error deleting Network", "err", err)
|
logger.Error(errNetBirdAPI, "error deleting Network", "err", err)
|
||||||
return ctrl.Result{}, err
|
return ctrl.Result{}, err
|
||||||
@@ -664,8 +663,6 @@ func (r *NBRoutingPeerReconciler) buildSecurityContext(nbrp *netbirdiov1.NBRouti
|
|||||||
|
|
||||||
// SetupWithManager sets up the controller with the Manager.
|
// SetupWithManager sets up the controller with the Manager.
|
||||||
func (r *NBRoutingPeerReconciler) SetupWithManager(mgr ctrl.Manager) error {
|
func (r *NBRoutingPeerReconciler) SetupWithManager(mgr ctrl.Manager) error {
|
||||||
r.netbird = netbird.New(r.ManagementURL, r.APIKey)
|
|
||||||
|
|
||||||
return ctrl.NewControllerManagedBy(mgr).
|
return ctrl.NewControllerManagedBy(mgr).
|
||||||
For(&netbirdiov1.NBRoutingPeer{}).
|
For(&netbirdiov1.NBRoutingPeer{}).
|
||||||
Named("nbroutingpeer").
|
Named("nbroutingpeer").
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ var _ = Describe("NBRoutingPeer Controller", func() {
|
|||||||
netbirdClient = netbird.New(server.URL, "ABC")
|
netbirdClient = netbird.New(server.URL, "ABC")
|
||||||
controllerReconciler = &NBRoutingPeerReconciler{
|
controllerReconciler = &NBRoutingPeerReconciler{
|
||||||
Client: k8sClient,
|
Client: k8sClient,
|
||||||
netbird: netbirdClient,
|
Netbird: netbirdClient,
|
||||||
ClientImage: "netbirdio/netbird:latest",
|
ClientImage: "netbirdio/netbird:latest",
|
||||||
ClusterName: "kubernetes",
|
ClusterName: "kubernetes",
|
||||||
DefaultLabels: make(map[string]string),
|
DefaultLabels: make(map[string]string),
|
||||||
|
|||||||
Reference in New Issue
Block a user