Skip to content

Commit 2227fdd

Browse files
committed
MGMT-21314: CNO enable advanced gateway detection in ovnkube in dpu host mode
Adding required gateway value for ovnk in dpu-host mode This commit enables usage of ovn-kubernetes/ovn-kubernetes#5327
1 parent e913f47 commit 2227fdd

File tree

2 files changed

+103
-2
lines changed

2 files changed

+103
-2
lines changed

bindata/network/ovn-kubernetes/common/008-script-lib.yaml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -512,10 +512,19 @@ data:
512512

513513
echo "I$(date "+%m%d %H:%M:%S.%N") - starting ovnkube-node"
514514

515+
516+
if [ "{{.OVN_NODE_MODE}}" == "dpu-host" ]; then
517+
// this is required for the dpu-host mode to configure right gateway interface
518+
// https://github.com/ovn-kubernetes/ovn-kubernetes/pull/5327/files
519+
gateway_interface=derive-from-mgmt-port
520+
else
521+
gateway_interface=br-ex
522+
fi
523+
515524
if [ "{{.OVN_GATEWAY_MODE}}" == "shared" ]; then
516-
gateway_mode_flags="--gateway-mode shared --gateway-interface br-ex"
525+
gateway_mode_flags="--gateway-mode shared --gateway-interface ${gateway_interface}"
517526
elif [ "{{.OVN_GATEWAY_MODE}}" == "local" ]; then
518-
gateway_mode_flags="--gateway-mode local --gateway-interface br-ex"
527+
gateway_mode_flags="--gateway-mode local --gateway-interface ${gateway_interface}"
519528
else
520529
echo "Invalid OVN_GATEWAY_MODE: \"{{.OVN_GATEWAY_MODE}}\". Must be \"local\" or \"shared\"."
521530
exit 1

pkg/network/ovn_kubernetes_test.go

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import (
3636
cnofake "github.com/openshift/cluster-network-operator/pkg/client/fake"
3737
"github.com/openshift/cluster-network-operator/pkg/hypershift"
3838
"github.com/openshift/cluster-network-operator/pkg/names"
39+
"github.com/openshift/cluster-network-operator/pkg/render"
3940
)
4041

4142
var (
@@ -4192,3 +4193,94 @@ func Test_renderOVNKubernetes(t *testing.T) {
41924193
})
41934194
}
41944195
}
4196+
4197+
func TestOVNKubernetesScriptLibGatewayInterface(t *testing.T) {
4198+
g := NewGomegaWithT(t)
4199+
4200+
testCases := []struct {
4201+
name string
4202+
ovnNodeMode string
4203+
expectedGatewayInterface string
4204+
}{
4205+
{
4206+
name: "dpu-host mode uses derive-from-mgmt-port",
4207+
ovnNodeMode: "dpu-host",
4208+
expectedGatewayInterface: "derive-from-mgmt-port",
4209+
},
4210+
{
4211+
name: "non-dpu-host mode uses br-ex",
4212+
ovnNodeMode: "full",
4213+
expectedGatewayInterface: "br-ex",
4214+
},
4215+
}
4216+
4217+
for _, tc := range testCases {
4218+
t.Run(tc.name, func(t *testing.T) {
4219+
// Create render data
4220+
data := render.MakeRenderData()
4221+
data.Data["OVN_NODE_MODE"] = tc.ovnNodeMode
4222+
data.Data["OVN_GATEWAY_MODE"] = "shared"
4223+
4224+
// Set all required template variables for 008-script-lib.yaml
4225+
data.Data["ReleaseVersion"] = "4.15.0"
4226+
data.Data["OVNPolicyAuditDestination"] = "null"
4227+
data.Data["OVNPolicyAuditSyslogFacility"] = "local0"
4228+
data.Data["OVN_LOG_PATTERN_CONSOLE"] = "%D{%Y-%m-%dT%H:%M:%S.###Z}|%05N|%c%T|%p|%m"
4229+
data.Data["NorthdThreads"] = "1"
4230+
data.Data["OVNPolicyAuditMaxFileSize"] = "50"
4231+
data.Data["OVNPolicyAuditMaxLogFiles"] = "5"
4232+
data.Data["OVN_NB_INACTIVITY_PROBE"] = "60000"
4233+
data.Data["OVN_NORTHD_BACKOFF_MS"] = "300"
4234+
data.Data["PlatformType"] = "AWS"
4235+
data.Data["OVN_CONTROLLER_INACTIVITY_PROBE"] = "30000"
4236+
data.Data["GenevePort"] = "8061"
4237+
data.Data["OVNHybridOverlayVXLANPort"] = ""
4238+
data.Data["OVN_MULTI_NETWORK_ENABLE"] = "false"
4239+
data.Data["OVN_NETWORK_SEGMENTATION_ENABLE"] = "false"
4240+
data.Data["OVN_ROUTE_ADVERTISEMENTS_ENABLE"] = "false"
4241+
data.Data["OVN_OBSERVABILITY_ENABLE"] = "false"
4242+
data.Data["OVN_MULTI_NETWORK_POLICY_ENABLE"] = "false"
4243+
data.Data["OVN_ADMIN_NETWORK_POLICY_ENABLE"] = "false"
4244+
data.Data["DNS_NAME_RESOLVER_ENABLE"] = "false"
4245+
data.Data["IP_FORWARDING_MODE"] = "Restricted"
4246+
data.Data["NETWORK_NODE_IDENTITY_ENABLE"] = "false"
4247+
data.Data["NodeIdentityCertDuration"] = "24h"
4248+
data.Data["V4JoinSubnet"] = ""
4249+
data.Data["V6JoinSubnet"] = ""
4250+
data.Data["V4MasqueradeSubnet"] = ""
4251+
data.Data["V6MasqueradeSubnet"] = ""
4252+
data.Data["V4TransitSwitchSubnet"] = ""
4253+
data.Data["V6TransitSwitchSubnet"] = ""
4254+
data.Data["OVNPolicyAuditRateLimit"] = "20"
4255+
data.Data["IsNetworkTypeLiveMigration"] = false
4256+
data.Data["OVNIPsecEnable"] = false
4257+
data.Data["OVNIPsecEncap"] = "Auto"
4258+
4259+
// Render the script-lib template
4260+
scriptLibPath := "../../bindata/network/ovn-kubernetes/common/008-script-lib.yaml"
4261+
objs, err := render.RenderTemplate(scriptLibPath, &data)
4262+
g.Expect(err).NotTo(HaveOccurred(), "Template rendering should succeed for %s", tc.name)
4263+
g.Expect(objs).To(HaveLen(1), "Should render exactly one object")
4264+
4265+
// Verify it's a ConfigMap with the expected name
4266+
obj := objs[0]
4267+
g.Expect(obj.GetKind()).To(Equal("ConfigMap"))
4268+
g.Expect(obj.GetName()).To(Equal("ovnkube-script-lib"))
4269+
4270+
// Extract the script content from the ConfigMap
4271+
scriptData, found, err := uns.NestedString(obj.Object, "data", "ovnkube-lib.sh")
4272+
g.Expect(err).NotTo(HaveOccurred())
4273+
g.Expect(found).To(BeTrue(), "Should find ovnkube-lib.sh in ConfigMap data")
4274+
4275+
// Validate gateway interface assignment
4276+
expectedGatewayAssignment := fmt.Sprintf("gateway_interface=%s", tc.expectedGatewayInterface)
4277+
g.Expect(scriptData).To(ContainSubstring(expectedGatewayAssignment),
4278+
"Script should contain correct gateway interface assignment for %s mode", tc.ovnNodeMode)
4279+
4280+
// Validate that gateway_mode_flags uses the variable
4281+
g.Expect(scriptData).To(ContainSubstring("--gateway-interface ${gateway_interface}"),
4282+
"Script should use gateway_interface variable in gateway_mode_flags")
4283+
4284+
})
4285+
}
4286+
}

0 commit comments

Comments
 (0)