Skip to content

Commit 7a21aa6

Browse files
authored
Merge pull request #5026 from SchSeba/fix_multus_networks
stop adding events to NAD if the network type is not ovn-k
2 parents deff5e6 + 2412b50 commit 7a21aa6

File tree

5 files changed

+38
-5
lines changed

5 files changed

+38
-5
lines changed

go-controller/pkg/config/cni.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,6 @@ func parseNetConfSingle(bytes []byte) (*ovncnitypes.NetConf, error) {
120120
}
121121

122122
func parseNetConfList(confList *libcni.NetworkConfigList) (*ovncnitypes.NetConf, error) {
123-
if len(confList.Plugins) > 1 {
124-
return nil, ErrorChainingNotSupported
125-
}
126-
127123
netconf := &ovncnitypes.NetConf{MTU: Default.MTU}
128124
if err := json.Unmarshal(confList.Plugins[0].Bytes, netconf); err != nil {
129125
return nil, err
@@ -134,6 +130,10 @@ func parseNetConfList(confList *libcni.NetworkConfigList) (*ovncnitypes.NetConf,
134130
return nil, ErrorAttachDefNotOvnManaged
135131
}
136132

133+
if len(confList.Plugins) > 1 {
134+
return nil, ErrorChainingNotSupported
135+
}
136+
137137
netconf.Name = confList.Name
138138
netconf.CNIVersion = confList.CNIVersion
139139

go-controller/pkg/networkmanager/nad_controller.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,11 @@ func (c *nadController) syncNAD(key string, nad *nettypes.NetworkAttachmentDefin
274274
if nad != nil {
275275
nadNetwork, err = util.ParseNADInfo(nad)
276276
if err != nil {
277+
// in case the type for the NAD is not ovn-k we should not record the error event
278+
if err.Error() == util.ErrorAttachDefNotOvnManaged.Error() {
279+
return nil
280+
}
281+
277282
if c.recorder != nil {
278283
c.recorder.Eventf(&corev1.ObjectReference{Kind: nad.Kind, Namespace: nad.Namespace, Name: nad.Name}, corev1.EventTypeWarning,
279284
"InvalidConfig", "Failed to parse network config: %v", err.Error())

go-controller/pkg/networkmanager/nad_controller_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,21 @@ func TestNADController(t *testing.T) {
469469
},
470470
},
471471
},
472+
{
473+
name: "non ovn-k NAD added",
474+
args: []args{
475+
{
476+
nad: "test/nad_1",
477+
network: &ovncnitypes.NetConf{
478+
NetConf: cnitypes.NetConf{
479+
Name: "test",
480+
Type: "sriov",
481+
},
482+
},
483+
wantErr: false,
484+
},
485+
},
486+
},
472487
}
473488
for _, tt := range tests {
474489
t.Run(tt.name, func(t *testing.T) {

go-controller/pkg/util/multi_network.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1151,6 +1151,9 @@ func ParseNADInfo(nad *nettypes.NetworkAttachmentDefinition) (NetInfo, error) {
11511151
func ParseNetConf(netattachdef *nettypes.NetworkAttachmentDefinition) (*ovncnitypes.NetConf, error) {
11521152
netconf, err := config.ParseNetConf([]byte(netattachdef.Spec.Config))
11531153
if err != nil {
1154+
if err.Error() == ErrorAttachDefNotOvnManaged.Error() {
1155+
return nil, err
1156+
}
11541157
return nil, fmt.Errorf("error parsing Network Attachment Definition %s/%s: %v", netattachdef.Namespace, netattachdef.Name, err)
11551158
}
11561159

go-controller/pkg/util/multi_network_test.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ func TestParseNetconf(t *testing.T) {
180180
"netAttachDefName": "default/tenantred"
181181
}
182182
`,
183-
expectedError: fmt.Errorf("error parsing Network Attachment Definition ns1/nad1: net-attach-def not managed by OVN"),
183+
expectedError: fmt.Errorf("net-attach-def not managed by OVN"),
184184
},
185185
{
186186
desc: "attachment definition with IPAM key defined, using a wrong type",
@@ -1154,6 +1154,16 @@ func TestSubnetOverlapCheck(t *testing.T) {
11541154
}
11551155
`,
11561156
},
1157+
{
1158+
desc: "return error when the network is not ovnk",
1159+
inputNetAttachDefConfigSpec: `
1160+
{
1161+
"name": "test",
1162+
"type": "sriov-cni"
1163+
}
1164+
`,
1165+
expectedError: ErrorAttachDefNotOvnManaged,
1166+
},
11571167
}
11581168

11591169
for _, test := range tests {

0 commit comments

Comments
 (0)