Skip to content

Commit

Permalink
nftables monitor disable flag
Browse files Browse the repository at this point in the history
  • Loading branch information
cheina97 committed Nov 18, 2024
1 parent 5201cd5 commit eb43042
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 9 deletions.
2 changes: 1 addition & 1 deletion cmd/fabric/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func run(cmd *cobra.Command, _ []string) error {
return fmt.Errorf("unable to create firewall configuration reconciler: %w", err)
}

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

Expand Down
2 changes: 1 addition & 1 deletion cmd/gateway/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ func run(cmd *cobra.Command, _ []string) error {
return fmt.Errorf("unable to create firewall configuration reconciler: %w", err)
}

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

Expand Down
1 change: 1 addition & 0 deletions deployments/liqo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
| networking.enabled | bool | `true` | Use the default Liqo networking module. |
| 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. |
| 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. |
| 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. |
| networking.fabric.image.name | string | `"ghcr.io/liqotech/fabric"` | Image repository for the fabric pod. |
| networking.fabric.image.version | string | `""` | Custom version for the fabric image. If not specified, the global tag is used. |
| networking.fabric.pod.annotations | object | `{}` | Annotations for the fabric pod. |
Expand Down
1 change: 1 addition & 0 deletions deployments/liqo/templates/liqo-fabric-daemonset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ spec:
{{- if .Values.requirements.kernel.disabled }}
- --disable-kernel-version-check
{{- end }}
- --enable-nft-monitor={{ .Values.networking.fabric.config.nftablesMonitor }}
{{- if .Values.common.extraArgs }}
{{- toYaml .Values.common.extraArgs | nindent 10 }}
{{- end }}
Expand Down
5 changes: 5 additions & 0 deletions deployments/liqo/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@ networking:
# 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.
gatewayMasqueradeBypass: false
# -- 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.
nftablesMonitor: true

authentication:
# -- Enable/Disable the authentication module.
Expand Down
2 changes: 1 addition & 1 deletion docs/contributing/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,4 @@ When executing the unit tests from the *liqo-test* container, it is possible to
--accept-multiclient ./path/to/test/directory
```

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!
4. From the host, connect to *localhost:2345* with your remote debugging client of choice, and enjoy!
4 changes: 4 additions & 0 deletions pkg/fabric/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ const (
// FlagNameDisableARP is the flag to enable ARP.
FlagNameDisableARP FlagName = "disable-arp"

// FlagNameEnableNftMonitor is the flag to enable the nftables monitor.
FlagNameEnableNftMonitor FlagName = "enable-nft-monitor"

// FlagNameDisableKernelVersionCheck is the flag to enable the kernel version check.
FlagNameDisableKernelVersionCheck FlagName = "disable-kernel-version-check"
// FlagNameMinimumKernelVersion is the minimum kernel version required to run the wireguard interface.
Expand All @@ -63,6 +66,7 @@ func InitFlags(flagset *pflag.FlagSet, opts *Options) {
flagset.StringVar(&opts.ProbeAddr, FlagNameProbeAddr.String(), ":8081", "Address for the health probe endpoint")

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

flagset.BoolVar(&opts.DisableKernelVersionCheck, FlagNameDisableKernelVersionCheck.String(), false, "Disable the kernel version check")
flagset.Var(&opts.MinimumKernelVersion, string(FlagNameMinimumKernelVersion), "Minimum kernel version required to run the wireguard interface")
Expand Down
3 changes: 2 additions & 1 deletion pkg/fabric/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ type Options struct {
MetricsAddress string
ProbeAddr string

DisableARP bool
DisableARP bool
EnableNftMonitor bool

DisableKernelVersionCheck bool
MinimumKernelVersion kernelversion.KernelVersion
Expand Down
10 changes: 6 additions & 4 deletions pkg/firewall/firewallconfiguration_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,17 +162,19 @@ func (r *FirewallConfigurationReconciler) Reconcile(ctx context.Context, req ctr
}

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

src := make(chan event.GenericEvent)
go func() {
utilruntime.Must(netmonitor.InterfacesMonitoring(ctx, src, &netmonitor.Options{Nftables: &netmonitor.OptionsNftables{Delete: true}}))
}()
if enableNftMonitor {
go func() {
utilruntime.Must(netmonitor.InterfacesMonitoring(ctx, src, &netmonitor.Options{Nftables: &netmonitor.OptionsNftables{Delete: true}}))
}()
}
return ctrl.NewControllerManagedBy(mgr).Named(consts.CtrlFirewallConfiguration).
For(&networkingv1beta1.FirewallConfiguration{}, builder.WithPredicates(filterByLabelsPredicate)).
WatchesRawSource(NewFirewallWatchSource(src, NewFirewallWatchEventHandler(r.Client, r.LabelsSets))).
Expand Down
10 changes: 9 additions & 1 deletion pkg/liqoctl/install/k3s/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,13 @@ func (o *Options) Initialize(_ context.Context) error {

// Values returns the customized provider-specifc values file parameters.
func (o *Options) Values() map[string]interface{} {
return map[string]interface{}{}
return map[string]interface{}{
"networking": map[string]interface{}{
"fabric": map[string]interface{}{
"config": map[string]interface{}{
"nftablesMonitor": false,
},
},
},
}
}

0 comments on commit eb43042

Please sign in to comment.