Skip to content

Commit 4cbb94e

Browse files
committed
Add nftables and conntrack config support to kube-proxy
- Add NFTables arg mapping (masquerade-bit, masquerade-all, sync-period, min-sync-period) to allow proxy-mode: nftables - Add conntrack-tcp-be-liberal arg mapping - Add getStringList helper and use it for nodeport-addresses since it will support non-CIDR values in the future - Accept both nodeport-addresses (correct) and node-port-addresses (legacy misspelling) for NodePortAddresses config Assisted By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Signed-off-by: Benjamin Pickard <bpickard@redhat.com>
1 parent 953ceab commit 4cbb94e

2 files changed

Lines changed: 100 additions & 1 deletion

File tree

pkg/util/k8s/kubeproxy.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ func GenerateKubeProxyConfiguration(args map[string]operv1.ProxyArgumentList) (s
6363
kpc.IPTables.SyncPeriod.Duration = ka.getDuration("iptables-sync-period")
6464
kpc.IPTables.MinSyncPeriod.Duration = ka.getDuration("iptables-min-sync-period")
6565

66+
kpc.NFTables.MasqueradeBit = ka.getOptInt32("nftables-masquerade-bit")
67+
kpc.NFTables.MasqueradeAll = ka.getBool("nftables-masquerade-all")
68+
kpc.NFTables.SyncPeriod.Duration = ka.getDuration("nftables-sync-period")
69+
kpc.NFTables.MinSyncPeriod.Duration = ka.getDuration("nftables-min-sync-period")
70+
6671
kpc.IPVS.SyncPeriod.Duration = ka.getDuration("ipvs-sync-period")
6772
kpc.IPVS.MinSyncPeriod.Duration = ka.getDuration("ipvs-min-sync-period")
6873
kpc.IPVS.Scheduler = ka.getString("ipvs-scheduler")
@@ -84,10 +89,16 @@ func GenerateKubeProxyConfiguration(args map[string]operv1.ProxyArgumentList) (s
8489
if duration := ka.getDuration("conntrack-tcp-timeout-close-wait"); duration != 0 {
8590
kpc.Conntrack.TCPCloseWaitTimeout = &metav1.Duration{Duration: duration}
8691
}
92+
kpc.Conntrack.TCPBeLiberal = ka.getBool("conntrack-tcp-be-liberal")
8793

8894
kpc.ConfigSyncPeriod.Duration = ka.getDuration("config-sync-period")
8995

90-
kpc.NodePortAddresses = ka.getCIDRList("node-port-addresses")
96+
kpc.NodePortAddresses = ka.getStringList("nodeport-addresses")
97+
if kpc.NodePortAddresses == nil {
98+
kpc.NodePortAddresses = ka.getStringList("node-port-addresses")
99+
} else {
100+
ka.getStringList("node-port-addresses")
101+
}
91102

92103
// kpc.Winkernel : CNO's kube-proxy config is never used for Windows kube-proxy so
93104
// there's no need to allow overriding this.
@@ -217,6 +228,15 @@ func (ka *kpcArgs) getCIDRList(key string) []string {
217228
return values
218229
}
219230

231+
// getStringList parses a comma-separated list and returns an array of strings
232+
func (ka *kpcArgs) getStringList(key string) []string {
233+
value := ka.get(key)
234+
if value == "" {
235+
return nil
236+
}
237+
return strings.Split(value, ",")
238+
}
239+
220240
// getOptInt32 returns an optional int32
221241
func (ka *kpcArgs) getOptInt32(key string) *int32 {
222242
value := ka.get(key)

pkg/util/k8s/kubeproxy_test.go

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,85 @@ nodePortAddresses: null
396396
oomScoreAdj: null
397397
portRange: 1000+10
398398
showHiddenMetricsForVersion: ""
399+
winkernel:
400+
enableDSR: false
401+
forwardHealthCheckVip: false
402+
networkName: ""
403+
rootHnsEndpointName: ""
404+
sourceVip: ""
405+
`,
406+
},
407+
{
408+
description: "nftables overrides",
409+
overrides: map[string]operv1.ProxyArgumentList{
410+
"proxy-mode": {"nftables"},
411+
"nftables-masquerade-bit": {"14"},
412+
"nftables-masquerade-all": {"true"},
413+
"nftables-sync-period": {"30s"},
414+
"nftables-min-sync-period": {"10s"},
415+
},
416+
output: `
417+
apiVersion: kubeproxy.config.k8s.io/v1alpha1
418+
bindAddress: 0.0.0.0
419+
bindAddressHardFail: false
420+
clientConnection:
421+
acceptContentTypes: ""
422+
burst: 0
423+
contentType: ""
424+
kubeconfig: ""
425+
qps: 0
426+
clusterCIDR: ""
427+
configSyncPeriod: 0s
428+
conntrack:
429+
maxPerCore: null
430+
min: null
431+
tcpBeLiberal: false
432+
tcpCloseWaitTimeout: null
433+
tcpEstablishedTimeout: null
434+
udpStreamTimeout: 0s
435+
udpTimeout: 0s
436+
detectLocal:
437+
bridgeInterface: ""
438+
interfaceNamePrefix: ""
439+
detectLocalMode: ""
440+
enableProfiling: false
441+
healthzBindAddress: ""
442+
hostnameOverride: ""
443+
iptables:
444+
localhostNodePorts: null
445+
masqueradeAll: false
446+
masqueradeBit: 0
447+
minSyncPeriod: 0s
448+
syncPeriod: 0s
449+
ipvs:
450+
excludeCIDRs: null
451+
minSyncPeriod: 0s
452+
scheduler: ""
453+
strictARP: false
454+
syncPeriod: 0s
455+
tcpFinTimeout: 0s
456+
tcpTimeout: 0s
457+
udpTimeout: 0s
458+
kind: KubeProxyConfiguration
459+
logging:
460+
flushFrequency: 0
461+
options:
462+
json:
463+
infoBufferSize: "0"
464+
text:
465+
infoBufferSize: "0"
466+
verbosity: 0
467+
metricsBindAddress: 0.0.0.0:9102
468+
mode: nftables
469+
nftables:
470+
masqueradeAll: true
471+
masqueradeBit: 14
472+
minSyncPeriod: 10s
473+
syncPeriod: 30s
474+
nodePortAddresses: null
475+
oomScoreAdj: null
476+
portRange: ""
477+
showHiddenMetricsForVersion: ""
399478
winkernel:
400479
enableDSR: false
401480
forwardHealthCheckVip: false

0 commit comments

Comments
 (0)