Skip to content

Commit

Permalink
install: Auto-enable BPF masquerade
Browse files Browse the repository at this point in the history
By default, the BPF-based masquerading is disabled. Enable the feature
if the KPR=strict and a user haven't specified the helm's
"bpf.masquerade" option.

Signed-off-by: Martynas Pumputis <[email protected]>
  • Loading branch information
brb authored and tklauser committed Jan 12, 2023
1 parent b7a66a5 commit 31453a5
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions install/autodetect.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ func (k *K8sInstaller) autodetectAndValidate(ctx context.Context) error {
}

k.autodetectKubeProxy(ctx)
k.autoEnableBPFMasq()
return nil
}

Expand Down Expand Up @@ -236,5 +237,27 @@ func (k *K8sInstaller) autodetectKubeProxy(ctx context.Context) error {
fmt.Sprintf("k8sServiceHost=%s", apiServerHost),
fmt.Sprintf("k8sServicePort=%s", apiServerPort))
}

return nil
}

func (k *K8sInstaller) autoEnableBPFMasq() {
// Auto-enable BPF masquerading if KPR=strict
foundKPRStrict := k.params.KubeProxyReplacement == "strict"
foundMasq := false
for _, param := range k.params.HelmOpts.Values {
if !foundKPRStrict && param == "kubeProxyReplacement=strict" {
foundKPRStrict = true
continue
}
if strings.HasPrefix(param, "bpf.masquerade") {
foundMasq = true
break
}
}

if foundKPRStrict && !foundMasq {
k.params.HelmOpts.Values = append(k.params.HelmOpts.Values,
"bpf.masquerade=true")
}
}

0 comments on commit 31453a5

Please sign in to comment.