@@ -31,6 +31,7 @@ type NBRoutingPeerReconciler struct {
3131 APIKey string
3232 ManagementURL string
3333 NamespacedNetworks bool
34+ DefaultLabels map [string ]string
3435 netbird * netbird.Client
3536}
3637
@@ -122,6 +123,13 @@ func (r *NBRoutingPeerReconciler) handleDeployment(ctx context.Context, req ctrl
122123 return err
123124 }
124125
126+ labels := r .DefaultLabels
127+ for k , v := range nbrp .Spec .Labels {
128+ labels [k ] = v
129+ }
130+ podLabels := labels
131+ podLabels ["app.kubernetes.io/name" ] = "netbird-router"
132+
125133 // Create deployment
126134 if errors .IsNotFound (err ) {
127135 var replicas int32 = 3
@@ -141,7 +149,7 @@ func (r *NBRoutingPeerReconciler) handleDeployment(ctx context.Context, req ctrl
141149 BlockOwnerDeletion : util .Ptr (true ),
142150 },
143151 },
144- Labels : nbrp . Spec . Labels ,
152+ Labels : labels ,
145153 Annotations : nbrp .Spec .Annotations ,
146154 },
147155 Spec : appsv1.DeploymentSpec {
@@ -153,9 +161,7 @@ func (r *NBRoutingPeerReconciler) handleDeployment(ctx context.Context, req ctrl
153161 },
154162 Template : corev1.PodTemplateSpec {
155163 ObjectMeta : v1.ObjectMeta {
156- Labels : map [string ]string {
157- "app.kubernetes.io/name" : "netbird-router" ,
158- },
164+ Labels : podLabels ,
159165 },
160166 Spec : corev1.PodSpec {
161167 NodeSelector : nbrp .Spec .NodeSelector ,
@@ -217,7 +223,7 @@ func (r *NBRoutingPeerReconciler) handleDeployment(ctx context.Context, req ctrl
217223 BlockOwnerDeletion : util .Ptr (true ),
218224 },
219225 }
220- updatedDeployment .ObjectMeta .Labels = nbrp . Spec . Labels
226+ updatedDeployment .ObjectMeta .Labels = labels
221227 for k , v := range nbrp .Spec .Annotations {
222228 updatedDeployment .ObjectMeta .Annotations [k ] = nbrp .Spec .Annotations [v ]
223229 }
@@ -233,6 +239,7 @@ func (r *NBRoutingPeerReconciler) handleDeployment(ctx context.Context, req ctrl
233239 }
234240 updatedDeployment .Spec .Template .Spec .Tolerations = nbrp .Spec .Tolerations
235241 updatedDeployment .Spec .Template .Spec .NodeSelector = nbrp .Spec .NodeSelector
242+ updatedDeployment .Spec .Template .ObjectMeta .Labels = podLabels
236243 updatedDeployment .Spec .Template .Spec .Volumes = nbrp .Spec .Volumes
237244 updatedDeployment .Spec .Template .ObjectMeta .Labels = map [string ]string {
238245 "app.kubernetes.io/name" : "netbird-router" ,
@@ -378,6 +385,7 @@ func (r *NBRoutingPeerReconciler) handleSetupKey(ctx context.Context, req ctrl.R
378385 BlockOwnerDeletion : util .Ptr (true ),
379386 },
380387 },
388+ Labels : r .DefaultLabels ,
381389 },
382390 StringData : map [string ]string {
383391 "setupKey" : setupKey .Key ,
@@ -402,7 +410,7 @@ func (r *NBRoutingPeerReconciler) handleSetupKey(ctx context.Context, req ctrl.R
402410 return & ctrl.Result {}, err
403411 }
404412
405- if ( err != nil && strings . Contains ( err . Error (), "not found" )) || setupKey .Revoked {
413+ if err != nil || setupKey .Revoked {
406414 if setupKey != nil && setupKey .Revoked {
407415 err = r .netbird .SetupKeys .Delete (ctx , * nbrp .Status .SetupKeyID )
408416
@@ -480,6 +488,7 @@ func (r *NBRoutingPeerReconciler) handleGroup(ctx context.Context, req ctrl.Requ
480488 },
481489 },
482490 Finalizers : []string {"netbird.io/group-cleanup" , "netbird.io/routing-peer-cleanup" },
491+ Labels : r .DefaultLabels ,
483492 },
484493 Spec : netbirdiov1.NBGroupSpec {
485494 Name : networkName ,
0 commit comments