Add --max-list-size option for ipset lists
and default it to 1024 for cases where the size is fixed by the kernel
This commit is contained in:
1 parent
791d9aecfc
commit
4c1c2a5661
2 files changed
+10
-2
No files matched your search
+7
-1
@@ -1,6 +1,7 @@
|
|||||||
package ipset
|
package ipset
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -40,6 +41,7 @@ type entryKey struct {
|
|||||||
type ipset struct {
|
type ipset struct {
|
||||||
*log.Logger
|
*log.Logger
|
||||||
enableComments bool
|
enableComments bool
|
||||||
|
maxListSize int
|
||||||
// List of users per ipset entry. User is either a namespace or a pod.
|
// List of users per ipset entry. User is either a namespace or a pod.
|
||||||
// There might be multiple users for the same ipset & entry pair because
|
// There might be multiple users for the same ipset & entry pair because
|
||||||
// events from k8s API server might be out of order causing duplicate IPs:
|
// events from k8s API server might be out of order causing duplicate IPs:
|
||||||
@@ -47,10 +49,11 @@ type ipset struct {
|
|||||||
users map[entryKey]map[types.UID]struct{}
|
users map[entryKey]map[types.UID]struct{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(logger *log.Logger) Interface {
|
func New(logger *log.Logger, maxListSize int) Interface {
|
||||||
ips := &ipset{
|
ips := &ipset{
|
||||||
Logger: logger,
|
Logger: logger,
|
||||||
enableComments: true,
|
enableComments: true,
|
||||||
|
maxListSize: maxListSize,
|
||||||
users: make(map[entryKey]map[types.UID]struct{}),
|
users: make(map[entryKey]map[types.UID]struct{}),
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,6 +74,9 @@ func New(logger *log.Logger) Interface {
|
|||||||
|
|
||||||
func (i *ipset) Create(ipsetName Name, ipsetType Type) error {
|
func (i *ipset) Create(ipsetName Name, ipsetType Type) error {
|
||||||
args := []string{"create", string(ipsetName), string(ipsetType)}
|
args := []string{"create", string(ipsetName), string(ipsetType)}
|
||||||
|
if ipsetType == ListSet && i.maxListSize > 0 {
|
||||||
|
args = append(args, fmt.Sprintf("size %d", i.maxListSize))
|
||||||
|
}
|
||||||
if i.enableComments {
|
if i.enableComments {
|
||||||
args = append(args, "comment")
|
args = append(args, "comment")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ var (
|
|||||||
allowMcast bool
|
allowMcast bool
|
||||||
nodeName string
|
nodeName string
|
||||||
legacy bool
|
legacy bool
|
||||||
|
maxList int
|
||||||
)
|
)
|
||||||
|
|
||||||
func handleError(err error) { common.CheckFatal(err) }
|
func handleError(err error) { common.CheckFatal(err) }
|
||||||
@@ -152,7 +153,7 @@ func root(cmd *cobra.Command, args []string) {
|
|||||||
ipt, err := iptables.New()
|
ipt, err := iptables.New()
|
||||||
handleError(err)
|
handleError(err)
|
||||||
|
|
||||||
ips := ipset.New(common.LogLogger())
|
ips := ipset.New(common.LogLogger(), maxList)
|
||||||
|
|
||||||
handleError(resetIPTables(ipt))
|
handleError(resetIPTables(ipt))
|
||||||
handleError(resetIPSets(ips))
|
handleError(resetIPSets(ips))
|
||||||
@@ -245,6 +246,7 @@ func main() {
|
|||||||
rootCmd.PersistentFlags().BoolVar(&allowMcast, "allow-mcast", true, "allow all multicast traffic")
|
rootCmd.PersistentFlags().BoolVar(&allowMcast, "allow-mcast", true, "allow all multicast traffic")
|
||||||
rootCmd.PersistentFlags().StringVar(&nodeName, "node-name", "", "only generate rules that apply to this node")
|
rootCmd.PersistentFlags().StringVar(&nodeName, "node-name", "", "only generate rules that apply to this node")
|
||||||
rootCmd.PersistentFlags().BoolVar(&legacy, "use-legacy-netpol", false, "use legacy network policies (pre k8s 1.7 vsn)")
|
rootCmd.PersistentFlags().BoolVar(&legacy, "use-legacy-netpol", false, "use legacy network policies (pre k8s 1.7 vsn)")
|
||||||
|
rootCmd.PersistentFlags().IntVar(&maxList, "max-list-size", 1024, "maximum size of ipset list (for namespaces)")
|
||||||
|
|
||||||
handleError(rootCmd.Execute())
|
handleError(rootCmd.Execute())
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user