From b242938b4fc6cb5d4b8525a9e00ebac0ac7f70a3 Mon Sep 17 00:00:00 2001 From: Francesco Cheinasso Date: Wed, 13 Nov 2024 19:05:10 +0100 Subject: [PATCH] fix: wggateway controllers pod watch --- deployments/liqo/templates/_helpers.tpl | 2 ++ .../external-network/wireguard/utils.go | 28 +++++++++++++++++++ .../wireguard/wggatewayclient_controller.go | 1 + .../wireguard/wggatewayserver_controller.go | 1 + test/e2e/cruise/network/network_test.go | 2 +- 5 files changed, 33 insertions(+), 1 deletion(-) diff --git a/deployments/liqo/templates/_helpers.tpl b/deployments/liqo/templates/_helpers.tpl index 158f34847d..dcfd06deb9 100644 --- a/deployments/liqo/templates/_helpers.tpl +++ b/deployments/liqo/templates/_helpers.tpl @@ -97,6 +97,8 @@ helm.sh/chart: {{ quote (include "liqo.chart" .) }} app.kubernetes.io/version: {{ quote (include "liqo.version" .) }} app.kubernetes.io/managed-by: {{ quote .Release.Service }} networking.liqo.io/component: "gateway" +networking.liqo.io/gateway-name: "{{"{{ .Name }}"}}" +networking.liqo.io/gateway-namespace: "{{"{{ .Namespace }}"}}" {{- if .isService }} networking.liqo.io/active: "true" {{- end }} diff --git a/pkg/liqo-controller-manager/networking/external-network/wireguard/utils.go b/pkg/liqo-controller-manager/networking/external-network/wireguard/utils.go index a1b6e45b3e..2296074cab 100644 --- a/pkg/liqo-controller-manager/networking/external-network/wireguard/utils.go +++ b/pkg/liqo-controller-manager/networking/external-network/wireguard/utils.go @@ -97,6 +97,34 @@ func clusterRoleBindingEnquerer(_ context.Context, obj client.Object) []ctrl.Req } } +func podEnquerer(_ context.Context, obj client.Object) []ctrl.Request { + pod, ok := obj.(*corev1.Pod) + if !ok { + return nil + } + + if pod.Labels == nil { + return nil + } + gwName, ok := pod.Labels[consts.GatewayNameLabel] + if !ok { + return nil + } + gwNs, ok := pod.Labels[consts.GatewayNamespaceLabel] + if !ok { + return nil + } + + return []ctrl.Request{ + { + NamespacedName: types.NamespacedName{ + Namespace: gwNs, + Name: gwName, + }, + }, + } +} + // ensureKeysSecret ensure the presence of the private and public keys for the Wireguard interface and save them inside a Secret resource and Options. func ensureKeysSecret(ctx context.Context, cl client.Client, wgObj metav1.Object, mode gateway.Mode) error { var controllerRef metav1.OwnerReference diff --git a/pkg/liqo-controller-manager/networking/external-network/wireguard/wggatewayclient_controller.go b/pkg/liqo-controller-manager/networking/external-network/wireguard/wggatewayclient_controller.go index 9de235c2d8..59a8ccc255 100644 --- a/pkg/liqo-controller-manager/networking/external-network/wireguard/wggatewayclient_controller.go +++ b/pkg/liqo-controller-manager/networking/external-network/wireguard/wggatewayclient_controller.go @@ -208,6 +208,7 @@ func (r *WgGatewayClientReconciler) SetupWithManager(mgr ctrl.Manager) error { For(&networkingv1beta1.WgGatewayClient{}). Owns(&appsv1.Deployment{}). Owns(&corev1.ServiceAccount{}). + Watches(&corev1.Pod{}, handler.EnqueueRequestsFromMapFunc(podEnquerer)). Watches(&rbacv1.ClusterRoleBinding{}, handler.EnqueueRequestsFromMapFunc(clusterRoleBindingEnquerer)). Watches(&corev1.Secret{}, diff --git a/pkg/liqo-controller-manager/networking/external-network/wireguard/wggatewayserver_controller.go b/pkg/liqo-controller-manager/networking/external-network/wireguard/wggatewayserver_controller.go index f9c4bfc198..b0bb56e3e4 100644 --- a/pkg/liqo-controller-manager/networking/external-network/wireguard/wggatewayserver_controller.go +++ b/pkg/liqo-controller-manager/networking/external-network/wireguard/wggatewayserver_controller.go @@ -224,6 +224,7 @@ func (r *WgGatewayServerReconciler) SetupWithManager(mgr ctrl.Manager) error { Owns(&appsv1.Deployment{}). Owns(&corev1.Service{}). Owns(&corev1.ServiceAccount{}). + Watches(&corev1.Pod{}, handler.EnqueueRequestsFromMapFunc(podEnquerer)). Watches(&rbacv1.ClusterRoleBinding{}, handler.EnqueueRequestsFromMapFunc(clusterRoleBindingEnquerer)). Watches(&corev1.Secret{}, diff --git a/test/e2e/cruise/network/network_test.go b/test/e2e/cruise/network/network_test.go index 127563da7f..61c8488fbf 100644 --- a/test/e2e/cruise/network/network_test.go +++ b/test/e2e/cruise/network/network_test.go @@ -44,7 +44,7 @@ import ( const ( // clustersRequired is the number of clusters required in this E2E test. - clustersRequired = 3 + clustersRequired = 2 // testName is the name of this E2E test. testName = "NETWORK" // StressMax is the maximum number of stress iterations.