Skip to content

Commit e318417

Browse files
danwinshipdeads2k
authored andcommitted
Fix a crash on a certain type of unsupported NetworkPolicy
1 parent 4bc1ee7 commit e318417

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

pkg/network/node/networkpolicy.go

+7-4
Original file line numberDiff line numberDiff line change
@@ -342,15 +342,18 @@ func (np *networkPolicyPlugin) parseNetworkPolicy(npns *npNamespace, policy *net
342342
return nil, fmt.Errorf("policy specifies unrecognized protocol %q", *port.Protocol)
343343
}
344344
var portNum int
345-
if port.Port.Type == intstr.Int {
345+
if port.Port == nil {
346+
// FIXME: implement this?
347+
return nil, fmt.Errorf("port fields with no port value are not implemented")
348+
} else if port.Port.Type != intstr.Int {
349+
// FIXME: implement this?
350+
return nil, fmt.Errorf("named port values (%q) are not implemented", port.Port.StrVal)
351+
} else {
346352
portNum = int(port.Port.IntVal)
347353
if portNum < 0 || portNum > 0xFFFF {
348354
// FIXME: validation should catch this
349355
return nil, fmt.Errorf("port value out of bounds %q", port.Port.IntVal)
350356
}
351-
} else {
352-
// FIXME: implement this
353-
return nil, fmt.Errorf("named port values (%q) are not yet implemented", port.Port.StrVal)
354357
}
355358
portFlows = append(portFlows, fmt.Sprintf("%s, tp_dst=%d, ", protocol, portNum))
356359
}

0 commit comments

Comments
 (0)