Skip to content

Commit 76c7185

Browse files
Merge pull request #2752 from pliurh/cm-enforcing-udn-loose-isolation
OCPBUGS-55962: Allow overriding OVN-Kubernetes configuration
2 parents 6688e9a + 1df74c4 commit 76c7185

File tree

4 files changed

+93
-1
lines changed

4 files changed

+93
-1
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,9 @@ data:
490490
local metrics_port=$2
491491
local ovn_metrics_port=$3
492492

493+
# Ensure ovn_advertised_udn_isolation_mode_flag is always defined
494+
ovn_advertised_udn_isolation_mode_flag=
495+
493496
if [[ $# -ne 3 ]]; then
494497
echo "Expected three arguments but got $#"
495498
exit 1
@@ -610,6 +613,10 @@ data:
610613
sysctl -w net.ipv6.conf.all.forwarding=0
611614
fi
612615

616+
if [[ "{{.AdvertisedUDNIsolationMode}}" != "" ]]; then
617+
ovn_advertised_udn_isolation_mode_flag="--advertised-udn-isolation-mode={{.AdvertisedUDNIsolationMode}}"
618+
fi
619+
613620
NETWORK_NODE_IDENTITY_ENABLE=
614621
if [[ "{{.NETWORK_NODE_IDENTITY_ENABLE}}" == "true" ]]; then
615622
NETWORK_NODE_IDENTITY_ENABLE="
@@ -679,6 +686,7 @@ data:
679686
--acl-logging-rate-limit "{{.OVNPolicyAuditRateLimit}}" \
680687
${gw_interface_flag} \
681688
${ip_forwarding_flag} \
689+
${ovn_advertised_udn_isolation_mode_flag} \
682690
${NETWORK_NODE_IDENTITY_ENABLE} \
683691
${ovn_v4_join_subnet_opt} \
684692
${ovn_v6_join_subnet_opt} \

pkg/bootstrap/types.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ type OVNConfigBoostrapResult struct {
3333
SmartNicModeLabel string
3434
SmartNicModeNodes []string
3535
MgmtPortResourceName string
36+
// ConfigOverrides contains the overrides for the OVN Kubernetes configuration
37+
// This is used to set the hidden OVN Kubernetes configuration in the cluster
38+
// It is a map of key-value pairs where the key is the configuration option and the
39+
// value is the configuration value.
40+
ConfigOverrides map[string]string
3641
}
3742

3843
// OVNUpdateStatus contains the status of existing daemonset

pkg/network/ovn_kubernetes.go

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ const OVN_NODE_IDENTITY_CERT_DURATION = "24h"
6868
const OVN_EGRESSIP_HEALTHCHECK_PORT = "9107"
6969

7070
const (
71-
OVSFlowsConfigMapName = "ovs-flows-config"
71+
OVSFlowsConfigMapName = "ovs-flows-config"
72+
OVNKubernetesConfigOverridesCMName = "ovn-kubernetes-config-overrides"
73+
7274
OVSFlowsConfigNamespace = names.APPLIED_NAMESPACE
7375
defaultV4InternalSubnet = "100.64.0.0/16"
7476
defaultV6InternalSubnet = "fd98::/64"
@@ -180,6 +182,7 @@ func renderOVNKubernetes(conf *operv1.NetworkSpec, bootstrapResult *bootstrap.Bo
180182
data.Data["NETWORK_NODE_IDENTITY_ENABLE"] = bootstrapResult.Infra.NetworkNodeIdentityEnabled
181183
data.Data["NodeIdentityCertDuration"] = OVN_NODE_IDENTITY_CERT_DURATION
182184
data.Data["IsNetworkTypeLiveMigration"] = false
185+
data.Data["AdvertisedUDNIsolationMode"] = bootstrapResult.OVN.OVNKubernetesConfig.ConfigOverrides["advertised-udn-isolation-mode"]
183186

184187
if conf.Migration != nil {
185188
if conf.Migration.MTU != nil && conf.Migration.Mode != operv1.LiveNetworkMigrationMode {
@@ -869,6 +872,11 @@ func bootstrapOVNConfig(conf *operv1.Network, kubeClient cnoclient.Client, hc *h
869872
return nil, fmt.Errorf("Node %s has multiple hardware offload labels.", nodeName)
870873
}
871874

875+
ovnConfigResult.ConfigOverrides, err = getOVNKubernetesConfigOverrides(kubeClient)
876+
if err != nil {
877+
return nil, fmt.Errorf("Could not get OVN Kubernetes config overrides: %w", err)
878+
}
879+
872880
klog.Infof("OVN configuration is now %+v", ovnConfigResult)
873881

874882
ovnConfigResult.DisableUDPAggregation = getDisableUDPAggregation(kubeClient.ClientFor("").CRClient())
@@ -1975,3 +1983,21 @@ func GetMasqueradeSubnet(conf *operv1.OVNKubernetesConfig) (v4Subnet, v6Subnet s
19751983
}
19761984
return
19771985
}
1986+
1987+
// getOVNKubernetesConfigOverrides retrieves OVN Kubernetes configuration overrides from the
1988+
// openshift-network-operator/ovn-kubernetes-config-overrides configmap.
1989+
// If the configmap exists, it returns the data as a map.
1990+
// If the configmap does not exist, it returns nil, indicating that no overrides are set
1991+
// and no error.
1992+
// If there is an error retrieving the configmap, it returns an error.
1993+
func getOVNKubernetesConfigOverrides(client cnoclient.Client) (map[string]string, error) {
1994+
configMap := &corev1.ConfigMap{}
1995+
if err := client.Default().CRClient().Get(context.TODO(),
1996+
types.NamespacedName{Name: OVNKubernetesConfigOverridesCMName, Namespace: names.APPLIED_NAMESPACE}, configMap); err != nil {
1997+
if apierrors.IsNotFound(err) {
1998+
return nil, nil
1999+
}
2000+
return nil, fmt.Errorf("unable to retrieve config from configmap %v: %s", OVNKubernetesConfigOverridesCMName, err)
2001+
}
2002+
return configMap.Data, nil
2003+
}

pkg/network/ovn_kubernetes_test.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3977,6 +3977,18 @@ func extractOVNKubeConfig(g *WithT, objs []*uns.Unstructured) string {
39773977
return ""
39783978
}
39793979

3980+
func extractOVNScriptLib(g *WithT, objs []*uns.Unstructured) string {
3981+
for _, obj := range objs {
3982+
if obj.GetKind() == "ConfigMap" && obj.GetName() == "ovnkube-script-lib" {
3983+
val, ok, err := uns.NestedString(obj.Object, "data", "ovnkube-lib.sh")
3984+
g.Expect(err).NotTo(HaveOccurred())
3985+
g.Expect(ok).To(BeTrue())
3986+
return val
3987+
}
3988+
}
3989+
return ""
3990+
}
3991+
39803992
// checkDaemonsetAnnotation check that all the daemonset have the annotation with the
39813993
// same key and value
39823994
func checkDaemonsetAnnotation(g *WithT, objs []*uns.Unstructured, key, value string) bool {
@@ -4192,3 +4204,44 @@ func Test_renderOVNKubernetes(t *testing.T) {
41924204
})
41934205
}
41944206
}
4207+
4208+
func TestRenderOVNKubernetes_AdvertisedUDNIsolationModeOverride(t *testing.T) {
4209+
g := NewGomegaWithT(t)
4210+
4211+
crd := OVNKubernetesConfig.DeepCopy()
4212+
config := &crd.Spec
4213+
fillDefaults(config, nil)
4214+
4215+
renderWithOverrides := func(overrides map[string]string) string {
4216+
bootstrapResult := fakeBootstrapResult()
4217+
bootstrapResult.OVN = bootstrap.OVNBootstrapResult{
4218+
ControlPlaneReplicaCount: 3,
4219+
OVNKubernetesConfig: &bootstrap.OVNConfigBoostrapResult{
4220+
DpuHostModeLabel: OVN_NODE_SELECTOR_DEFAULT_DPU_HOST,
4221+
DpuModeLabel: OVN_NODE_SELECTOR_DEFAULT_DPU,
4222+
SmartNicModeLabel: OVN_NODE_SELECTOR_DEFAULT_SMART_NIC,
4223+
MgmtPortResourceName: "",
4224+
HyperShiftConfig: &bootstrap.OVNHyperShiftBootstrapResult{
4225+
Enabled: false,
4226+
},
4227+
ConfigOverrides: overrides,
4228+
},
4229+
}
4230+
featureGatesCNO := getDefaultFeatureGates()
4231+
fakeClient := cnofake.NewFakeClient()
4232+
4233+
objs, _, err := renderOVNKubernetes(config, bootstrapResult, manifestDirOvn, fakeClient, featureGatesCNO)
4234+
g.Expect(err).NotTo(HaveOccurred())
4235+
return extractOVNScriptLib(g, objs)
4236+
}
4237+
4238+
t.Run("with advertised-udn-isolation-mode override", func(t *testing.T) {
4239+
ovnkubeScriptLib := renderWithOverrides(map[string]string{"advertised-udn-isolation-mode": "loose"})
4240+
g.Expect(ovnkubeScriptLib).To(ContainSubstring(`--advertised-udn-isolation-mode=loose"`))
4241+
})
4242+
4243+
t.Run("without advertised-udn-isolation-mode override", func(t *testing.T) {
4244+
ovnkubeScriptLib := renderWithOverrides(nil)
4245+
g.Expect(ovnkubeScriptLib).To(ContainSubstring(`--advertised-udn-isolation-mode="`))
4246+
})
4247+
}

0 commit comments

Comments
 (0)