1 parent
4b5299d124
commit
2555e491e1
2 files changed
+28
-6
No files matched your search
+12
-6
@@ -30,13 +30,19 @@ func newRuleSpec(proto *string, srcHost *selectorSpec, dstHost *selectorSpec, ds
|
|||||||
args = append(args, "--dport", *dstPort)
|
args = append(args, "--dport", *dstPort)
|
||||||
}
|
}
|
||||||
args = append(args, "-j", "ACCEPT")
|
args = append(args, "-j", "ACCEPT")
|
||||||
srcComment := ""
|
srcComment := "anywhere"
|
||||||
if srcHost.nsName != "" {
|
if srcHost != nil {
|
||||||
srcComment = fmt.Sprintf("pods: namespace: %s, selector: %s", srcHost.nsName, srcHost.key)
|
if srcHost.nsName != "" {
|
||||||
} else {
|
srcComment = fmt.Sprintf("pods: namespace: %s, selector: %s", srcHost.nsName, srcHost.key)
|
||||||
srcComment = fmt.Sprintf("namespaces: selector: %s", srcHost.key)
|
} else {
|
||||||
|
srcComment = fmt.Sprintf("namespaces: selector: %s", srcHost.key)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
args = append(args, "-m", "comment", "--comment", fmt.Sprintf("%s -> namespace: %s, key: %s", srcComment, dstHost.nsName, dstHost.key))
|
dstComment := "anywhere"
|
||||||
|
if dstHost != nil {
|
||||||
|
dstComment = fmt.Sprintf("pods: namespace: %s, selector: %s", dstHost.nsName, dstHost.key)
|
||||||
|
}
|
||||||
|
args = append(args, "-m", "comment", "--comment", fmt.Sprintf("%s -> %s", srcComment, dstComment))
|
||||||
key := strings.Join(args, " ")
|
key := strings.Join(args, " ")
|
||||||
|
|
||||||
return &ruleSpec{key, args}
|
return &ruleSpec{key, args}
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package npc
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestRegressionHandleNil3095(t *testing.T) {
|
||||||
|
// Test for handling nil values
|
||||||
|
// https://github.com/weaveworks/weave/issues/3095
|
||||||
|
|
||||||
|
rs := newRuleSpec(nil, nil, nil, nil)
|
||||||
|
|
||||||
|
require.NotEqual(t, rs.key, "")
|
||||||
|
|
||||||
|
}
|
||||||
Reference in new issue
Block a user