Skip to content

Commit c40beff

Browse files
cheina97adamjensenbot
authored andcommitted
nftables monitor disable flag
1 parent 22f77f2 commit c40beff

File tree

11 files changed

+37
-9
lines changed

11 files changed

+37
-9
lines changed

cmd/fabric/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ func run(cmd *cobra.Command, _ []string) error {
160160
return fmt.Errorf("unable to create firewall configuration reconciler: %w", err)
161161
}
162162

163-
if err := fwcr.SetupWithManager(cmd.Context(), mgr); err != nil {
163+
if err := fwcr.SetupWithManager(cmd.Context(), mgr, options.EnableNftMonitor); err != nil {
164164
return fmt.Errorf("unable to setup firewall configuration reconciler: %w", err)
165165
}
166166

cmd/gateway/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ func run(cmd *cobra.Command, _ []string) error {
201201
return fmt.Errorf("unable to create firewall configuration reconciler: %w", err)
202202
}
203203

204-
if err := fwcr.SetupWithManager(cmd.Context(), mgr); err != nil {
204+
if err := fwcr.SetupWithManager(cmd.Context(), mgr, true); err != nil {
205205
return fmt.Errorf("unable to setup firewall configuration reconciler: %w", err)
206206
}
207207

deployments/liqo/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
| networking.enabled | bool | `true` | Use the default Liqo networking module. |
8282
| networking.fabric.config.fullMasquerade | bool | `false` | Enabe/Disable the full masquerade mode for the fabric pod. It means that all traffic will be masquerade using the first external cidr IP, instead of using the pod IP. Full masquerade is useful when the cluster nodeports uses a PodCIDR IP to masqerade the incoming traffic. IMPORTANT: Please consider that enabling this feature will masquerade the source IP of traffic towards a remote cluster, making impossible for a pod that receives the traffic to know the original source IP. |
8383
| networking.fabric.config.gatewayMasqueradeBypass | bool | `false` | Enable/Disable the masquerade bypass for the gateway pods. It means that the packets from gateway pods will not be masqueraded from the host where the pod is scheduled. This is useful in scenarios where CNIs masquerade the traffic from pod to nodes. For example this is required when using the Azure CNI or Kindnet. |
84+
| networking.fabric.config.nftablesMonitor | bool | `true` | Enable/Disable the nftables monitor for the fabric pod. It means that the fabric pod will monitor the nftables rules and will restore them in case of changes. In some cases (like K3S), this monitor can cause a huge amount of CPU usage. If you are experiencing high CPU usage, you can disable this feature. |
8485
| networking.fabric.image.name | string | `"ghcr.io/liqotech/fabric"` | Image repository for the fabric pod. |
8586
| networking.fabric.image.version | string | `""` | Custom version for the fabric image. If not specified, the global tag is used. |
8687
| networking.fabric.pod.annotations | object | `{}` | Annotations for the fabric pod. |

deployments/liqo/templates/liqo-fabric-daemonset.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ spec:
4848
{{- if .Values.requirements.kernel.disabled }}
4949
- --disable-kernel-version-check
5050
{{- end }}
51+
- --enable-nft-monitor={{ .Values.networking.fabric.config.nftablesMonitor }}
5152
{{- if .Values.common.extraArgs }}
5253
{{- toYaml .Values.common.extraArgs | nindent 10 }}
5354
{{- end }}

deployments/liqo/values.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,11 @@ networking:
130130
# This is useful in scenarios where CNIs masquerade the traffic from pod to nodes.
131131
# For example this is required when using the Azure CNI or Kindnet.
132132
gatewayMasqueradeBypass: false
133+
# -- Enable/Disable the nftables monitor for the fabric pod.
134+
# It means that the fabric pod will monitor the nftables rules and will restore them in case of changes.
135+
# In some cases (like K3S), this monitor can cause a huge amount of CPU usage.
136+
# If you are experiencing high CPU usage, you can disable this feature.
137+
nftablesMonitor: true
133138

134139
authentication:
135140
# -- Enable/Disable the authentication module.

docs/contributing/contributing.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -137,4 +137,4 @@ When executing the unit tests from the *liqo-test* container, it is possible to
137137
--accept-multiclient ./path/to/test/directory
138138
```
139139

140-
4. From the host, connect to *localhost:2345* with your remote debugging client of choice (e.g. [GoLand](https://www.jetbrains.com/help/go/attach-to-running-go-processes-with-debugger.html#step-3-create-the-remote-run-debug-configuration-on-the-client-computer)), and enjoy!
140+
4. From the host, connect to *localhost:2345* with your remote debugging client of choice, and enjoy!

docs/installation/install.md

+6
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,12 @@ By default, the K3s installer stores the kubeconfig to access your cluster in th
303303
Make sure to properly refer to it when using *liqoctl* (e.g., setting the `KUBECONFIG` variable), and that the current user has permissions to read it.
304304
```
305305
306+
```{warning}
307+
- Due to an issue with K3s certificates, the `kubectl exec' command doesn't work properly when used on a pod scheduled on a virtual node.
308+
- Due to an issue with the [nftables golang library](https://github.com/google/nftables) and the pod running in *host network* in K3s, the firewall monitoring feature is disabled by default.
309+
This means that the firewall rules on the node will not be monitored and enforced by Liqo. If these rules are deleted or changed, Liqo won't restore them.
310+
```
311+
306312
**Installation**
307313
308314
Liqo can be installed on a K3s cluster with the following command:

pkg/fabric/flags.go

+4
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ const (
4040
// FlagNameDisableARP is the flag to enable ARP.
4141
FlagNameDisableARP FlagName = "disable-arp"
4242

43+
// FlagNameEnableNftMonitor is the flag to enable the nftables monitor.
44+
FlagNameEnableNftMonitor FlagName = "enable-nft-monitor"
45+
4346
// FlagNameDisableKernelVersionCheck is the flag to enable the kernel version check.
4447
FlagNameDisableKernelVersionCheck FlagName = "disable-kernel-version-check"
4548
// FlagNameMinimumKernelVersion is the minimum kernel version required to run the wireguard interface.
@@ -63,6 +66,7 @@ func InitFlags(flagset *pflag.FlagSet, opts *Options) {
6366
flagset.StringVar(&opts.ProbeAddr, FlagNameProbeAddr.String(), ":8081", "Address for the health probe endpoint")
6467

6568
flagset.BoolVar(&opts.DisableARP, FlagNameDisableARP.String(), false, "Disable ARP")
69+
flagset.BoolVar(&opts.EnableNftMonitor, FlagNameEnableNftMonitor.String(), true, "Enable nftables monitor")
6670

6771
flagset.BoolVar(&opts.DisableKernelVersionCheck, FlagNameDisableKernelVersionCheck.String(), false, "Disable the kernel version check")
6872
flagset.Var(&opts.MinimumKernelVersion, string(FlagNameMinimumKernelVersion), "Minimum kernel version required to run the wireguard interface")

pkg/fabric/options.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ type Options struct {
2626
MetricsAddress string
2727
ProbeAddr string
2828

29-
DisableARP bool
29+
DisableARP bool
30+
EnableNftMonitor bool
3031

3132
DisableKernelVersionCheck bool
3233
MinimumKernelVersion kernelversion.KernelVersion

pkg/firewall/firewallconfiguration_controller.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -162,17 +162,19 @@ func (r *FirewallConfigurationReconciler) Reconcile(ctx context.Context, req ctr
162162
}
163163

164164
// SetupWithManager register the FirewallConfigurationReconciler to the manager.
165-
func (r *FirewallConfigurationReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager) error {
165+
func (r *FirewallConfigurationReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, enableNftMonitor bool) error {
166166
klog.Infof("Starting FirewallConfiguration controller with labels %v", r.LabelsSets)
167167
filterByLabelsPredicate, err := forgeLabelsPredicate(r.LabelsSets)
168168
if err != nil {
169169
return err
170170
}
171171

172172
src := make(chan event.GenericEvent)
173-
go func() {
174-
utilruntime.Must(netmonitor.InterfacesMonitoring(ctx, src, &netmonitor.Options{Nftables: &netmonitor.OptionsNftables{Delete: true}}))
175-
}()
173+
if enableNftMonitor {
174+
go func() {
175+
utilruntime.Must(netmonitor.InterfacesMonitoring(ctx, src, &netmonitor.Options{Nftables: &netmonitor.OptionsNftables{Delete: true}}))
176+
}()
177+
}
176178
return ctrl.NewControllerManagedBy(mgr).Named(consts.CtrlFirewallConfiguration).
177179
For(&networkingv1beta1.FirewallConfiguration{}, builder.WithPredicates(filterByLabelsPredicate)).
178180
WatchesRawSource(NewFirewallWatchSource(src, NewFirewallWatchEventHandler(r.Client, r.LabelsSets))).

pkg/liqoctl/install/k3s/provider.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -67,5 +67,13 @@ func (o *Options) Initialize(_ context.Context) error {
6767

6868
// Values returns the customized provider-specifc values file parameters.
6969
func (o *Options) Values() map[string]interface{} {
70-
return map[string]interface{}{}
70+
return map[string]interface{}{
71+
"networking": map[string]interface{}{
72+
"fabric": map[string]interface{}{
73+
"config": map[string]interface{}{
74+
"nftablesMonitor": false,
75+
},
76+
},
77+
},
78+
}
7179
}

0 commit comments

Comments
 (0)