Add comments to iptables rules and ipsets

Fixes #2621
This commit is contained in:
Mike Bryant committed 2017-07-17 11:00:08 +01:00
1 parent efde637e1c
commit e10ce2345b
6 files changed
+42 -23

No files matched your search

+8
View File
@@ -1,6 +1,7 @@
package npc
import (
"fmt"
"strings"
"k8s.io/client-go/pkg/types"
@@ -29,6 +30,13 @@ func newRuleSpec(proto *string, srcHost *selectorSpec, dstHost *selectorSpec, ds
args = append(args, "--dport", *dstPort)
}
args = append(args, "-j", "ACCEPT")
srcComment := ""
if srcHost.nsName != "" {
srcComment = fmt.Sprintf("pods: namespace: %s, selector: %s", srcHost.nsName, 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))
key := strings.Join(args, " ")
return &ruleSpec{key, args}