Skip to content

Commit da8c24e

Browse files
committed
nftables monitor disable flag
1 parent f8312ec commit da8c24e

File tree

8 files changed

+29
-8
lines changed

8 files changed

+29
-8
lines changed

cmd/fabric/main.go

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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/templates/liqo-fabric-daemonset.yaml

Lines changed: 1 addition & 0 deletions
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

Lines changed: 5 additions & 0 deletions
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.

pkg/fabric/flags.go

Lines changed: 4 additions & 0 deletions
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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 6 additions & 4 deletions
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

Lines changed: 9 additions & 1 deletion
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)