Skip to content

Commit a0e322d

Browse files
authored
[NPM] Add a protocol flag to namedport (#904)
* NPM today does not adhere to the protocol attached to a named port * fixing a UT * expanding ports to test
1 parent b76bbcf commit a0e322d

File tree

3 files changed

+58
-1
lines changed

3 files changed

+58
-1
lines changed

npm/translatePolicy.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,13 @@ func translateIngress(ns string, policyName string, targetSelector metav1.LabelS
313313
Chain: util.IptablesAzureIngressPortChain,
314314
Specs: append([]string(nil), targetSelectorIptEntrySpec...),
315315
}
316+
if portRule.Protocol != nil {
317+
entry.Specs = append(
318+
entry.Specs,
319+
util.IptablesProtFlag,
320+
string(*portRule.Protocol),
321+
)
322+
}
316323
entry.Specs = append(
317324
entry.Specs,
318325
util.IptablesModuleFlag,
@@ -385,6 +392,13 @@ func translateIngress(ns string, policyName string, targetSelector metav1.LabelS
385392
Chain: util.IptablesAzureIngressPortChain,
386393
Specs: append([]string(nil), targetSelectorIptEntrySpec...),
387394
}
395+
if portRule.Protocol != nil {
396+
entry.Specs = append(
397+
entry.Specs,
398+
util.IptablesProtFlag,
399+
string(*portRule.Protocol),
400+
)
401+
}
388402
entry.Specs = append(
389403
entry.Specs,
390404
util.IptablesModuleFlag,
@@ -616,6 +630,13 @@ func translateIngress(ns string, policyName string, targetSelector metav1.LabelS
616630
Chain: util.IptablesAzureIngressPortChain,
617631
Specs: append([]string(nil), targetSelectorIptEntrySpec...),
618632
}
633+
if portRule.Protocol != nil {
634+
entry.Specs = append(
635+
entry.Specs,
636+
util.IptablesProtFlag,
637+
string(*portRule.Protocol),
638+
)
639+
}
619640
entry.Specs = append(
620641
entry.Specs,
621642
iptPartialPodSpec...,
@@ -728,6 +749,13 @@ func translateIngress(ns string, policyName string, targetSelector metav1.LabelS
728749
Chain: util.IptablesAzureIngressPortChain,
729750
Specs: append([]string(nil), iptPartialNsSpec...),
730751
}
752+
if portRule.Protocol != nil {
753+
entry.Specs = append(
754+
entry.Specs,
755+
util.IptablesProtFlag,
756+
string(*portRule.Protocol),
757+
)
758+
}
731759
entry.Specs = append(
732760
entry.Specs,
733761
iptPartialPodSpec...,
@@ -942,6 +970,13 @@ func translateEgress(ns string, policyName string, targetSelector metav1.LabelSe
942970
Chain: util.IptablesAzureEgressPortChain,
943971
Specs: append([]string(nil), targetSelectorIptEntrySpec...),
944972
}
973+
if portRule.Protocol != nil {
974+
entry.Specs = append(
975+
entry.Specs,
976+
util.IptablesProtFlag,
977+
string(*portRule.Protocol),
978+
)
979+
}
945980
entry.Specs = append(
946981
entry.Specs,
947982
util.IptablesModuleFlag,
@@ -1014,6 +1049,13 @@ func translateEgress(ns string, policyName string, targetSelector metav1.LabelSe
10141049
Chain: util.IptablesAzureEgressPortChain,
10151050
Specs: append([]string(nil), targetSelectorIptEntrySpec...),
10161051
}
1052+
if portRule.Protocol != nil {
1053+
entry.Specs = append(
1054+
entry.Specs,
1055+
util.IptablesProtFlag,
1056+
string(*portRule.Protocol),
1057+
)
1058+
}
10171059
entry.Specs = append(
10181060
entry.Specs,
10191061
util.IptablesModuleFlag,
@@ -1254,6 +1296,13 @@ func translateEgress(ns string, policyName string, targetSelector metav1.LabelSe
12541296
entry.Specs,
12551297
targetSelectorIptEntrySpec...,
12561298
)
1299+
if portRule.Protocol != nil {
1300+
entry.Specs = append(
1301+
entry.Specs,
1302+
util.IptablesProtFlag,
1303+
string(*portRule.Protocol),
1304+
)
1305+
}
12571306
entry.Specs = append(
12581307
entry.Specs,
12591308
util.IptablesModuleFlag,
@@ -1371,6 +1420,13 @@ func translateEgress(ns string, policyName string, targetSelector metav1.LabelSe
13711420
entry.Specs,
13721421
iptPartialPodSpec...,
13731422
)
1423+
if portRule.Protocol != nil {
1424+
entry.Specs = append(
1425+
entry.Specs,
1426+
util.IptablesProtFlag,
1427+
string(*portRule.Protocol),
1428+
)
1429+
}
13741430
entry.Specs = append(
13751431
entry.Specs,
13761432
util.IptablesModuleFlag,

npm/translatePolicy_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3333,6 +3333,8 @@ func TestNamedPorts(t *testing.T) {
33333333
util.IptablesMatchSetFlag,
33343334
util.GetHashedName("app:server"),
33353335
util.IptablesDstFlag,
3336+
util.IptablesProtFlag,
3337+
"TCP",
33363338
util.IptablesModuleFlag,
33373339
util.IptablesSetModuleFlag,
33383340
util.IptablesMatchSetFlag,

test/cyclonus/install-cyclonus.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ spec:
2020
- --pod-creation-timeout-seconds=30
2121
- --job-timeout-seconds=2
2222
- --server-protocol=TCP,UDP
23-
- --server-port=80
2423
name: cyclonus
2524
imagePullPolicy: IfNotPresent
2625
image: mfenwick100/cyclonus:v0.4.7

0 commit comments

Comments
 (0)