Skip to content

Commit f89702f

Browse files
cheina97adamjensenbot
authored andcommitted
Network: fwcfg and rtcfg reque
1 parent 56e90e7 commit f89702f

File tree

8 files changed

+42
-5
lines changed

8 files changed

+42
-5
lines changed

deployments/liqo/templates/liqo-wireguard-gateway-client-template.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ spec:
2424
{{- include "liqo.metadataTemplate" $templateConfig | nindent 10 }}
2525
spec:
2626
replicas: {{ .Values.networking.gatewayTemplates.replicas }}
27+
strategy:
28+
type: Recreate
2729
selector:
2830
matchLabels:
2931
{{- include "liqo.labelsTemplate" $templateConfig | nindent 14 }}

deployments/liqo/templates/liqo-wireguard-gateway-server-template.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ spec:
4242
{{- include "liqo.metadataTemplate" $templateConfig | nindent 10 }}
4343
spec:
4444
replicas: {{ .Values.networking.gatewayTemplates.replicas }}
45+
strategy:
46+
type: Recreate
4547
selector:
4648
matchLabels:
4749
{{- include "liqo.labelsTemplate" $templateConfig | nindent 14 }}

pkg/firewall/firewallconfiguration_controller.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"context"
1919
"errors"
2020
"fmt"
21+
"time"
2122

2223
"github.com/google/nftables"
2324
apierrors "k8s.io/apimachinery/pkg/api/errors"
@@ -152,7 +153,7 @@ func (r *FirewallConfigurationReconciler) Reconcile(ctx context.Context, req ctr
152153

153154
klog.Infof("Applied firewallconfiguration %s", req.String())
154155

155-
return ctrl.Result{}, nil
156+
return ctrl.Result{RequeueAfter: 5 * time.Second}, nil
156157
}
157158

158159
// SetupWithManager register the FirewallConfigurationReconciler to the manager.

pkg/gateway/tunnel/wireguard/netlink.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package wireguard
1616

1717
import (
18+
"errors"
1819
"fmt"
1920

2021
"github.com/vishvananda/netlink"
@@ -29,6 +30,15 @@ import (
2930

3031
// InitWireguardLink inits the Wireguard interface.
3132
func InitWireguardLink(options *Options) error {
33+
exists, err := existsLink()
34+
if err != nil {
35+
return fmt.Errorf("cannot check if Wireguard interface exists: %w", err)
36+
}
37+
if exists {
38+
klog.Infof("Wireguard interface %q already exists", tunnel.TunnelInterfaceName)
39+
return nil
40+
}
41+
3242
if err := createLink(options); err != nil {
3343
return fmt.Errorf("cannot create Wireguard interface: %w", err)
3444
}
@@ -75,3 +85,14 @@ func createLink(options *Options) error {
7585
}
7686
return nil
7787
}
88+
89+
func existsLink() (bool, error) {
90+
_, err := common.GetLink(tunnel.TunnelInterfaceName)
91+
if err != nil {
92+
if errors.As(err, &netlink.LinkNotFoundError{}) {
93+
return false, nil
94+
}
95+
return false, err
96+
}
97+
return true, nil
98+
}

pkg/gateway/tunnel/wireguard/publickeys_controller.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232

3333
networkingv1alpha1 "github.com/liqotech/liqo/apis/networking/v1alpha1"
3434
"github.com/liqotech/liqo/pkg/consts"
35+
"github.com/liqotech/liqo/pkg/gateway"
3536
)
3637

3738
// cluster-role
@@ -72,6 +73,12 @@ func (r *PublicKeysReconciler) Reconcile(ctx context.Context, req ctrl.Request)
7273
return ctrl.Result{}, fmt.Errorf("unable to get the publicKey %q: %w", req.NamespacedName, err)
7374
}
7475

76+
if r.Options.GwOptions.Mode == gateway.ModeClient && r.Options.EndpointIP == nil {
77+
// We don't need to retry because the DNS resolution routine will wakeup this controller.
78+
klog.Warning("EndpointIP is not set yet. Maybe the DNS resolution is still in progress")
79+
return ctrl.Result{}, nil
80+
}
81+
7582
if err := configureDevice(r.Wgcl, r.Options, wgtypes.Key(publicKey.Spec.PublicKey)); err != nil {
7683
return ctrl.Result{}, err
7784
}

pkg/liqo-controller-manager/external-network/remapping/ip.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,14 +126,14 @@ func mutateFirewallConfigurationMasquerade(fwcfg *networkingv1alpha1.FirewallCon
126126

127127
func enforceFirewallConfigurationSpec(fwcfg *networkingv1alpha1.FirewallConfiguration, ip *ipamv1alpha1.IP) {
128128
table := &fwcfg.Spec.Table
129-
table.Name = &TableIPMappingGwName
129+
table.Name = ptr.To(fmt.Sprintf("%s-%s", TableIPMappingGwName, fwcfg.Namespace))
130130
table.Family = ptr.To(firewall.TableFamilyIPv4)
131131
enforceFirewallConfigurationChains(fwcfg, ip)
132132
}
133133

134134
func enforceFirewallConfigurationMasqSpec(fwcfg *networkingv1alpha1.FirewallConfiguration, ip *ipamv1alpha1.IP) {
135135
table := &fwcfg.Spec.Table
136-
table.Name = &TableIPMappingFabricName
136+
table.Name = ptr.To(fmt.Sprintf("%s-%s", TableIPMappingFabricName, fwcfg.Namespace))
137137
table.Family = ptr.To(firewall.TableFamilyIPv4)
138138
enforceFirewallConfigurationMasqChains(fwcfg, ip)
139139
}

pkg/route/routeconfiguration_controller.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"context"
1919
"errors"
2020
"fmt"
21+
"time"
2122

2223
apierrors "k8s.io/apimachinery/pkg/api/errors"
2324
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -165,7 +166,7 @@ func (r *RouteConfigurationReconciler) Reconcile(ctx context.Context, req ctrl.R
165166

166167
klog.Infof("Applied routeconfiguration %s", req.String())
167168

168-
return ctrl.Result{}, nil
169+
return ctrl.Result{RequeueAfter: 5 * time.Second}, nil
169170
}
170171

171172
// SetupWithManager register the RouteConfigurationReconciler to the manager.

pkg/utils/network/geneve/netlink.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,11 @@ func CreateGeneveInterface(name string, local, remote net.IP, id uint32, enableA
7676
if !geneveLink.Remote.Equal(remote) {
7777
klog.Warningf("geneve link already exists with different remote IP (%s -> %s), modifyng it",
7878
geneveLink.Remote.String(), remote.String())
79+
if err := netlink.LinkDel(geneveLink); err != nil {
80+
return fmt.Errorf("cannot delete geneve link: %w", err)
81+
}
7982
geneveLink = ForgeGeneveInterface(name, remote, id)
80-
if err := netlink.LinkModify(geneveLink); err != nil {
83+
if err := netlink.LinkAdd(geneveLink); err != nil {
8184
return fmt.Errorf("cannot modify geneve link: %w", err)
8285
}
8386
}

0 commit comments

Comments
 (0)