Browse code

Make kube-proxy iptables sync period configurable

Add an iptablesSyncPeriod field in the node config, used for setting up the interval between iptables syncs (defaults to 5s)

kargakis authored on 2015/10/05 23:13:11
Showing 8 changed files
... ...
@@ -73,6 +73,9 @@ type NodeConfig struct {
73 73
 	// command line arguments.  These are not migrated or validated, so if you use them they may become invalid.
74 74
 	// These values override other settings in NodeConfig which may cause invalid configurations.
75 75
 	KubeletArguments ExtendedArguments
76
+
77
+	// IPTablesSyncPeriod is how often iptable rules are refreshed
78
+	IPTablesSyncPeriod string
76 79
 }
77 80
 
78 81
 // NodeNetworkConfig provides network options for the node
... ...
@@ -62,6 +62,9 @@ func init() {
62 62
 			if obj.NetworkConfig.MTU == 0 {
63 63
 				obj.NetworkConfig.MTU = 1450
64 64
 			}
65
+			if len(obj.IPTablesSyncPeriod) == 0 {
66
+				obj.IPTablesSyncPeriod = "5s"
67
+			}
65 68
 		},
66 69
 		func(obj *EtcdStorageConfig) {
67 70
 			if len(obj.KubernetesStorageVersion) == 0 {
... ...
@@ -58,6 +58,9 @@ type NodeConfig struct {
58 58
 	// command line arguments.  These are not migrated or validated, so if you use them they may become invalid.
59 59
 	// These values override other settings in NodeConfig which may cause invalid configurations.
60 60
 	KubeletArguments ExtendedArguments `json:"kubeletArguments,omitempty"`
61
+
62
+	// IPTablesSyncPeriod is how often iptable rules are refreshed
63
+	IPTablesSyncPeriod string `json:"iptablesSyncPeriod"`
61 64
 }
62 65
 
63 66
 // NodeNetworkConfig provides network options for the node
... ...
@@ -24,6 +24,7 @@ dockerConfig:
24 24
 imageConfig:
25 25
   format: ""
26 26
   latest: false
27
+iptablesSyncPeriod: ""
27 28
 kind: NodeConfig
28 29
 masterKubeConfig: ""
29 30
 networkConfig:
... ...
@@ -3,6 +3,7 @@ package validation
3 3
 import (
4 4
 	"fmt"
5 5
 	"strings"
6
+	"time"
6 7
 
7 8
 	kapp "k8s.io/kubernetes/cmd/kubelet/app"
8 9
 	"k8s.io/kubernetes/pkg/util/fielderrors"
... ...
@@ -42,6 +43,10 @@ func ValidateNodeConfig(config *api.NodeConfig) fielderrors.ValidationErrorList
42 42
 
43 43
 	allErrs = append(allErrs, ValidateKubeletExtendedArguments(config.KubeletArguments).Prefix("kubeletArguments")...)
44 44
 
45
+	if _, err := time.ParseDuration(config.IPTablesSyncPeriod); err != nil {
46
+		allErrs = append(allErrs, fielderrors.NewFieldInvalid("iptablesSyncPeriod", config.IPTablesSyncPeriod, fmt.Sprintf("unable to parse iptablesSyncPeriod: %v. Examples with correct format: '5s', '1m', '2h22m'", err)))
47
+	}
48
+
45 49
 	return allErrs
46 50
 }
47 51
 
... ...
@@ -149,7 +149,6 @@ func (c *NodeConfig) RunProxy() {
149 149
 	endpointsConfig := pconfig.NewEndpointsConfig()
150 150
 	loadBalancer := proxy.NewLoadBalancerRR()
151 151
 	endpointsConfig.RegisterHandler(loadBalancer)
152
-	syncPeriod := 5 * time.Second
153 152
 
154 153
 	host, _, err := net.SplitHostPort(c.BindAddress)
155 154
 	if err != nil {
... ...
@@ -165,6 +164,11 @@ func (c *NodeConfig) RunProxy() {
165 165
 		protocol = iptables.ProtocolIpv6
166 166
 	}
167 167
 
168
+	syncPeriod, err := time.ParseDuration(c.IPTablesSyncPeriod)
169
+	if err != nil {
170
+		glog.Fatalf("Cannot parse the provided ip-tables sync period (%s) : %v", c.IPTablesSyncPeriod, err)
171
+	}
172
+
168 173
 	go util.Forever(func() {
169 174
 		proxier, err := proxy.NewProxier(loadBalancer, ip, iptables.New(kexec.New(), protocol), util.PortRange{}, syncPeriod)
170 175
 		if err != nil {
... ...
@@ -35,11 +35,12 @@ type NodeConfig struct {
35 35
 	Client *client.Client
36 36
 	// DockerClient is a client to connect to Docker
37 37
 	DockerClient dockertools.DockerInterface
38
-
39 38
 	// KubeletServer contains the KubeletServer configuration
40 39
 	KubeletServer *kapp.KubeletServer
41 40
 	// KubeletConfig is the configuration for the kubelet, fully initialized
42 41
 	KubeletConfig *kapp.KubeletConfig
42
+	// IPTablesSyncPeriod is how often iptable rules are refreshed
43
+	IPTablesSyncPeriod string
43 44
 }
44 45
 
45 46
 func BuildKubernetesNodeConfig(options configapi.NodeConfig) (*NodeConfig, error) {
... ...
@@ -184,6 +185,8 @@ func BuildKubernetesNodeConfig(options configapi.NodeConfig) (*NodeConfig, error
184 184
 
185 185
 		KubeletServer: server,
186 186
 		KubeletConfig: cfg,
187
+
188
+		IPTablesSyncPeriod: options.IPTablesSyncPeriod,
187 189
 	}
188 190
 
189 191
 	return config, nil
... ...
@@ -9,6 +9,7 @@ import (
9 9
 	"strconv"
10 10
 	"strings"
11 11
 
12
+	"github.com/spf13/cobra"
12 13
 	"github.com/spf13/pflag"
13 14
 
14 15
 	"k8s.io/kubernetes/pkg/master/ports"
... ...
@@ -17,10 +18,9 @@ import (
17 17
 	"github.com/openshift/origin/pkg/cmd/server/admin"
18 18
 	configapi "github.com/openshift/origin/pkg/cmd/server/api"
19 19
 	cmdutil "github.com/openshift/origin/pkg/cmd/util"
20
-	"github.com/spf13/cobra"
21 20
 )
22 21
 
23
-// NodeArgs is a struct that the command stores flag values into.  It holds a partially complete set of parameters for starting the master
22
+// NodeArgs is a struct that the command stores flag values into.  It holds a partially complete set of parameters for starting a node.
24 23
 // This object should hold the common set values, but not attempt to handle all cases.  The expected path is to use this object to create
25 24
 // a fully specified config later on.  If you need something not set here, then create a fully specified config file and pass that as argument
26 25
 // to starting the master.