Skip to content

Commit

Permalink
fix: wggateway controllers pod watch
Browse files Browse the repository at this point in the history
  • Loading branch information
cheina97 committed Nov 14, 2024
1 parent 373dc94 commit 82441e5
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 2 deletions.
2 changes: 2 additions & 0 deletions deployments/liqo/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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{},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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{},
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/cruise/network/network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ 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.
stressMax = 3
stressMax = 100
)

func TestE2E(t *testing.T) {
Expand Down

0 comments on commit 82441e5

Please sign in to comment.