Merge pull request #125 from squat/resync-period
cmd/kg,pkg: add --resync-period flag
This commit is contained in:
		| @@ -16,7 +16,6 @@ package main | ||||
|  | ||||
| import ( | ||||
| 	"errors" | ||||
| 	"flag" | ||||
| 	"fmt" | ||||
| 	"net" | ||||
| 	"net/http" | ||||
| @@ -24,12 +23,14 @@ import ( | ||||
| 	"os/signal" | ||||
| 	"strings" | ||||
| 	"syscall" | ||||
| 	"time" | ||||
|  | ||||
| 	"github.com/go-kit/kit/log" | ||||
| 	"github.com/go-kit/kit/log/level" | ||||
| 	"github.com/oklog/run" | ||||
| 	"github.com/prometheus/client_golang/prometheus" | ||||
| 	"github.com/prometheus/client_golang/prometheus/promhttp" | ||||
| 	flag "github.com/spf13/pflag" | ||||
| 	apiextensions "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset" | ||||
| 	"k8s.io/client-go/kubernetes" | ||||
| 	"k8s.io/client-go/tools/clientcmd" | ||||
| @@ -97,6 +98,7 @@ func Main() error { | ||||
| 	var port uint | ||||
| 	flag.UintVar(&port, "port", mesh.DefaultKiloPort, "The port over which WireGuard peers should communicate.") | ||||
| 	subnet := flag.String("subnet", mesh.DefaultKiloSubnet.String(), "CIDR from which to allocate addresses for WireGuard interfaces.") | ||||
| 	resyncPeriod := flag.Duration("resync-period", 30*time.Second, "How often should the Kilo controllers reconcile?") | ||||
| 	printVersion := flag.Bool("version", false, "Print version and exit") | ||||
| 	flag.Parse() | ||||
|  | ||||
| @@ -178,7 +180,7 @@ func Main() error { | ||||
| 		return fmt.Errorf("backend %v unknown; possible values are: %s", *backend, availableBackends) | ||||
| 	} | ||||
|  | ||||
| 	m, err := mesh.New(b, enc, gr, *hostname, uint32(port), s, *local, *cni, *cniPath, *iface, *cleanUpIface, *createIface, log.With(logger, "component", "kilo")) | ||||
| 	m, err := mesh.New(b, enc, gr, *hostname, uint32(port), s, *local, *cni, *cniPath, *iface, *cleanUpIface, *createIface, *resyncPeriod, log.With(logger, "component", "kilo")) | ||||
| 	if err != nil { | ||||
| 		return fmt.Errorf("failed to create Kilo mesh: %v", err) | ||||
| 	} | ||||
|   | ||||
							
								
								
									
										57
									
								
								docs/kg.md
									
									
									
									
									
								
							
							
						
						
									
										57
									
								
								docs/kg.md
									
									
									
									
									
								
							| @@ -16,40 +16,25 @@ The behavior of `kg` can be configured using the command line flags listed below | ||||
|  | ||||
| [embedmd]:# (../tmp/help.txt) | ||||
| ```txt | ||||
| Usage of bin/amd64/kg: | ||||
|   -backend string | ||||
|     	The backend for the mesh. Possible values: kubernetes (default "kubernetes") | ||||
|   -clean-up-interface | ||||
|     	Should Kilo delete its interface when it shuts down? | ||||
|   -cni | ||||
|     	Should Kilo manage the node's CNI configuration? (default true) | ||||
|   -cni-path string | ||||
|     	Path to CNI config. (default "/etc/cni/net.d/10-kilo.conflist") | ||||
|   -compatibility string | ||||
|     	Should Kilo run in compatibility mode? Possible values: flannel | ||||
|   -create-interface | ||||
|     	Should kilo create an interface on startup? (default true) | ||||
|   -encapsulate string | ||||
|     	When should Kilo encapsulate packets within a location? Possible values: never, crosssubnet, always (default "always") | ||||
|   -hostname string | ||||
|     	Hostname of the node on which this process is running. | ||||
|   -interface string | ||||
|     	Name of the Kilo interface to use; if it does not exist, it will be created. (default "kilo0") | ||||
|   -kubeconfig string | ||||
|     	Path to kubeconfig. | ||||
|   -listen string | ||||
|     	The address at which to listen for health and metrics. (default ":1107") | ||||
|   -local | ||||
|     	Should Kilo manage routes within a location? (default true) | ||||
|   -log-level string | ||||
|     	Log level to use. Possible values: all, debug, info, warn, error, none (default "info") | ||||
|   -master string | ||||
|     	The address of the Kubernetes API server (overrides any value in kubeconfig). | ||||
|   -mesh-granularity string | ||||
|     	The granularity of the network mesh to create. Possible values: location, full (default "location") | ||||
|   -port uint | ||||
|     	The port over which WireGuard peers should communicate. (default 51820) | ||||
|   -subnet string | ||||
|     	CIDR from which to allocate addresses for WireGuard interfaces. (default "10.4.0.0/16") | ||||
|   -version | ||||
| Usage of bin//linux/amd64/kg: | ||||
|       --backend string            The backend for the mesh. Possible values: kubernetes (default "kubernetes") | ||||
|       --clean-up-interface        Should Kilo delete its interface when it shuts down? | ||||
|       --cni                       Should Kilo manage the node's CNI configuration? (default true) | ||||
|       --cni-path string           Path to CNI config. (default "/etc/cni/net.d/10-kilo.conflist") | ||||
|       --compatibility string      Should Kilo run in compatibility mode? Possible values: flannel | ||||
|       --create-interface          Should kilo create an interface on startup? (default true) | ||||
|       --encapsulate string        When should Kilo encapsulate packets within a location? Possible values: never, crosssubnet, always (default "always") | ||||
|       --hostname string           Hostname of the node on which this process is running. | ||||
|       --interface string          Name of the Kilo interface to use; if it does not exist, it will be created. (default "kilo0") | ||||
|       --kubeconfig string         Path to kubeconfig. | ||||
|       --listen string             The address at which to listen for health and metrics. (default ":1107") | ||||
|       --local                     Should Kilo manage routes within a location? (default true) | ||||
|       --log-level string          Log level to use. Possible values: all, debug, info, warn, error, none (default "info") | ||||
|       --master string             The address of the Kubernetes API server (overrides any value in kubeconfig). | ||||
|       --mesh-granularity string   The granularity of the network mesh to create. Possible values: location, full (default "location") | ||||
|       --port uint                 The port over which WireGuard peers should communicate. (default 51820) | ||||
|       --resync-period duration    How often should the Kilo controllers reconcile? (default 30s) | ||||
|       --subnet string             CIDR from which to allocate addresses for WireGuard interfaces. (default "10.4.0.0/16") | ||||
|       --topology-label string     Kubernetes node label used to group nodes into logical locations. (default "topology.kubernetes.io/region") | ||||
|       --version                   Print version and exit | ||||
| ``` | ||||
|   | ||||
							
								
								
									
										1
									
								
								go.mod
									
									
									
									
									
								
							
							
						
						
									
										1
									
								
								go.mod
									
									
									
									
									
								
							| @@ -38,6 +38,7 @@ require ( | ||||
| 	github.com/onsi/gomega v1.5.0 // indirect | ||||
| 	github.com/prometheus/client_golang v0.9.2 | ||||
| 	github.com/spf13/cobra v0.0.4-0.20190321000552-67fc4837d267 | ||||
| 	github.com/spf13/pflag v1.0.3 | ||||
| 	github.com/stretchr/testify v1.3.0 // indirect | ||||
| 	github.com/vishvananda/netlink v1.0.0 | ||||
| 	github.com/vishvananda/netns v0.0.0-20180720170159-13995c7128cc // indirect | ||||
|   | ||||
							
								
								
									
										13
									
								
								go.sum
									
									
									
									
									
								
							
							
						
						
									
										13
									
								
								go.sum
									
									
									
									
									
								
							| @@ -1,6 +1,5 @@ | ||||
| cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= | ||||
| github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= | ||||
| github.com/PuerkitoBio/purell v1.1.0 h1:rmGxhojJlM0tuKtfdvliR84CFHljx9ag64t2xmVkjK4= | ||||
| github.com/PuerkitoBio/purell v1.1.0/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0= | ||||
| github.com/PuerkitoBio/purell v1.1.1 h1:WEQqlqaGbrPkxLJWfBwQmfEAE1Z7ONdDLqrN38tNFfI= | ||||
| github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0= | ||||
| @@ -40,17 +39,14 @@ github.com/go-kit/kit v0.8.0 h1:Wz+5lgoB0kkuqLEc6NVmwRknTKP6dTGbSqvhZtBI/j0= | ||||
| github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= | ||||
| github.com/go-logfmt/logfmt v0.4.0 h1:MP4Eh7ZCb31lleYCFuwm0oe4/YGak+5l1vA2NOE80nA= | ||||
| github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= | ||||
| github.com/go-openapi/jsonpointer v0.17.0 h1:nH6xp8XdXHx8dqveo0ZuJBluCO2qGrPbDNZ0dwoRHP0= | ||||
| github.com/go-openapi/jsonpointer v0.17.0/go.mod h1:cOnomiV+CVVwFLk0A/MExoFMjwdsUdVpsRhURCKh+3M= | ||||
| github.com/go-openapi/jsonpointer v0.19.0 h1:FTUMcX77w5rQkClIzDtTxvn6Bsa894CcrzNj2MMfeg8= | ||||
| github.com/go-openapi/jsonpointer v0.19.0/go.mod h1:cOnomiV+CVVwFLk0A/MExoFMjwdsUdVpsRhURCKh+3M= | ||||
| github.com/go-openapi/jsonreference v0.17.0 h1:yJW3HCkTHg7NOA+gZ83IPHzUSnUzGXhGmsdiCcMexbA= | ||||
| github.com/go-openapi/jsonreference v0.17.0/go.mod h1:g4xxGn04lDIRh0GJb5QlpE3HfopLOL6uZrK/VgnsK9I= | ||||
| github.com/go-openapi/jsonreference v0.19.0 h1:BqWKpV1dFd+AuiKlgtddwVIFQsuMpxfBDBHGfM2yNpk= | ||||
| github.com/go-openapi/jsonreference v0.19.0/go.mod h1:g4xxGn04lDIRh0GJb5QlpE3HfopLOL6uZrK/VgnsK9I= | ||||
| github.com/go-openapi/spec v0.19.0 h1:A4SZ6IWh3lnjH0rG0Z5lkxazMGBECtrZcbyYQi+64k4= | ||||
| github.com/go-openapi/spec v0.19.0/go.mod h1:XkF/MOi14NmjsfZ8VtAKf8pIlbZzyoTvZsdfssdxcBI= | ||||
| github.com/go-openapi/swag v0.17.0 h1:iqrgMg7Q7SvtbWLlltPrkMs0UBJI6oTSs79JFRUi880= | ||||
| github.com/go-openapi/swag v0.17.0/go.mod h1:AByQ+nYG6gQg71GINrmuDXCPWdL640yX49/kXLo40Tg= | ||||
| github.com/go-openapi/swag v0.19.0 h1:Kg7Wl7LkTPlmc393QZQ/5rQadPhi7pBVEMZxyTi0Ii8= | ||||
| github.com/go-openapi/swag v0.19.0/go.mod h1:AByQ+nYG6gQg71GINrmuDXCPWdL640yX49/kXLo40Tg= | ||||
| @@ -60,7 +56,6 @@ github.com/gogo/protobuf v1.2.1 h1:/s5zKNz0uPFCZ5hddgPdo2TK2TVrUNMn0OOX8/aZMTE= | ||||
| github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4= | ||||
| github.com/golang/groupcache v0.0.0-20181024230925-c65c006176ff h1:kOkM9whyQYodu09SJ6W3NCsHG7crFaJILQ22Gozp3lg= | ||||
| github.com/golang/groupcache v0.0.0-20181024230925-c65c006176ff/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= | ||||
| github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM= | ||||
| github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= | ||||
| github.com/golang/protobuf v1.3.1 h1:YF8+flBXS5eO826T4nzqPrxfhQThhXl0YzfuUPu4SBg= | ||||
| github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= | ||||
| @@ -91,7 +86,6 @@ github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= | ||||
| github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348 h1:MtvEpTB6LX3vkb4ax0b5D2DHbNAUsen0Gx5wZoq3lV4= | ||||
| github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348/go.mod h1:B69LEHPfb2qLo0BaaOLcbitczOKLWTsrBG9LczfCD4k= | ||||
| github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= | ||||
| github.com/mailru/easyjson v0.0.0-20180823135443-60711f1a8329 h1:2gxZ0XQIU/5z3Z3bUBu+FXuk2pFbkN6tcwi/pjyaDic= | ||||
| github.com/mailru/easyjson v0.0.0-20180823135443-60711f1a8329/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= | ||||
| github.com/mailru/easyjson v0.0.0-20190403194419-1ea4449da983 h1:wL11wNW7dhKIcRCHSm4sHKPWz0tt4mwBsVodG7+Xyqg= | ||||
| github.com/mailru/easyjson v0.0.0-20190403194419-1ea4449da983/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= | ||||
| @@ -131,7 +125,6 @@ github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg= | ||||
| github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= | ||||
| github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s= | ||||
| github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= | ||||
| github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w= | ||||
| github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= | ||||
| github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= | ||||
| github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= | ||||
| @@ -149,12 +142,10 @@ golang.org/x/lint v0.0.0-20190409202823-959b441ac422 h1:QzoH/1pFpZguR8NrRHLcO6jK | ||||
| golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= | ||||
| golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= | ||||
| golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= | ||||
| golang.org/x/net v0.0.0-20181005035420-146acd28ed58 h1:otZG8yDCO4LVps5+9bxOeNiCvgmOyt96J3roHTYs7oE= | ||||
| golang.org/x/net v0.0.0-20181005035420-146acd28ed58/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= | ||||
| golang.org/x/net v0.0.0-20181201002055-351d144fa1fc/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= | ||||
| golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= | ||||
| golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= | ||||
| golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3 h1:0GoQqolDA55aaLxZyTzK/Y2ePZzZTUrRacwib7cNsYQ= | ||||
| golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= | ||||
| golang.org/x/net v0.0.0-20190501004415-9ce7a6920f09 h1:KaQtG+aDELoNmXYas3TVkGNYRuq8JQ1aa7LJt8EXVyo= | ||||
| golang.org/x/net v0.0.0-20190501004415-9ce7a6920f09/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= | ||||
| @@ -166,18 +157,15 @@ golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJ | ||||
| golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= | ||||
| golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= | ||||
| golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= | ||||
| golang.org/x/sys v0.0.0-20190412213103-97732733099d h1:+R4KGOnez64A81RvjARKc4UT5/tI9ujCIVX+P5KiHuI= | ||||
| golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= | ||||
| golang.org/x/sys v0.0.0-20190429190828-d89cdac9e872 h1:cGjJzUd8RgBw428LXP65YXni0aiGNA4Bl+ls8SmLOm8= | ||||
| golang.org/x/sys v0.0.0-20190429190828-d89cdac9e872/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= | ||||
| golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= | ||||
| golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= | ||||
| golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= | ||||
| golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= | ||||
| golang.org/x/time v0.0.0-20181108054448-85acf8d2951c h1:fqgJT0MGcGpPgpWU7VRdRjuArfcOvC4AoJmILihzhDg= | ||||
| golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= | ||||
| golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= | ||||
| golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e h1:FDhOuMEY4JVRztM/gsbk+IKUQ8kj74bxZrgw87eMMVc= | ||||
| golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= | ||||
| golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= | ||||
| golang.org/x/tools v0.0.0-20190328211700-ab21143f2384 h1:TFlARGu6Czu1z7q93HTxcP1P+/ZFC/IKythI5RzrnRg= | ||||
| @@ -185,7 +173,6 @@ golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3 | ||||
| google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= | ||||
| google.golang.org/appengine v1.5.0 h1:KxkO13IPW4Lslp2bz+KHP2E3gtFlrIGNThxkZQ3g+4c= | ||||
| google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= | ||||
| gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= | ||||
| gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||||
| gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= | ||||
| gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||||
|   | ||||
| @@ -198,10 +198,11 @@ func chainToString(table, chain string) string { | ||||
|  | ||||
| // Controller is able to reconcile a given set of iptables rules. | ||||
| type Controller struct { | ||||
| 	v4     Client | ||||
| 	v6     Client | ||||
| 	errors chan error | ||||
| 	logger log.Logger | ||||
| 	v4           Client | ||||
| 	v6           Client | ||||
| 	errors       chan error | ||||
| 	logger       log.Logger | ||||
| 	resyncPeriod time.Duration | ||||
|  | ||||
| 	sync.Mutex | ||||
| 	rules      []Rule | ||||
| @@ -218,6 +219,13 @@ func WithLogger(logger log.Logger) ControllerOption { | ||||
| 	} | ||||
| } | ||||
|  | ||||
| // WithResyncPeriod modifies how often the controller reconciles. | ||||
| func WithResyncPeriod(resyncPeriod time.Duration) ControllerOption { | ||||
| 	return func(c *Controller) { | ||||
| 		c.resyncPeriod = resyncPeriod | ||||
| 	} | ||||
| } | ||||
|  | ||||
| // WithClients adds iptables clients to the controller. | ||||
| func WithClients(v4, v6 Client) ControllerOption { | ||||
| 	return func(c *Controller) { | ||||
| @@ -266,16 +274,18 @@ func (c *Controller) Run(stop <-chan struct{}) (<-chan error, error) { | ||||
| 	c.subscribed = true | ||||
| 	c.Unlock() | ||||
| 	go func() { | ||||
| 		t := time.NewTimer(c.resyncPeriod) | ||||
| 		defer close(c.errors) | ||||
| 		for { | ||||
| 			select { | ||||
| 			case <-time.After(30 * time.Second): | ||||
| 			case <-t.C: | ||||
| 				if err := c.reconcile(); err != nil { | ||||
| 					nonBlockingSend(c.errors, fmt.Errorf("failed to reconcile rules: %v", err)) | ||||
| 				} | ||||
| 				t.Reset(c.resyncPeriod) | ||||
| 			case <-stop: | ||||
| 				return | ||||
| 			} | ||||
| 			if err := c.reconcile(); err != nil { | ||||
| 				nonBlockingSend(c.errors, fmt.Errorf("failed to reconcile rules: %v", err)) | ||||
| 			} | ||||
| 		} | ||||
| 	}() | ||||
| 	return c.errors, nil | ||||
|   | ||||
| @@ -22,9 +22,9 @@ import ( | ||||
| ) | ||||
|  | ||||
| const ( | ||||
| 	// resyncPeriod is how often the mesh checks state if no events have been received. | ||||
| 	resyncPeriod = 30 * time.Second | ||||
| 	// DefaultKiloInterface is the default iterface created and used by Kilo. | ||||
| 	// checkInPeriod is how often nodes should check-in. | ||||
| 	checkInPeriod = 30 * time.Second | ||||
| 	// DefaultKiloInterface is the default interface created and used by Kilo. | ||||
| 	DefaultKiloInterface = "kilo0" | ||||
| 	// DefaultKiloPort is the default UDP port Kilo uses. | ||||
| 	DefaultKiloPort = 51820 | ||||
| @@ -70,7 +70,7 @@ type Node struct { | ||||
| // Ready indicates whether or not the node is ready. | ||||
| func (n *Node) Ready() bool { | ||||
| 	// Nodes that are not leaders will not have WireGuardIPs, so it is not required. | ||||
| 	return n != nil && n.Endpoint != nil && !(n.Endpoint.IP == nil && n.Endpoint.DNS == "") && n.Endpoint.Port != 0 && n.Key != nil && n.Subnet != nil && time.Now().Unix()-n.LastSeen < int64(resyncPeriod)*2/int64(time.Second) | ||||
| 	return n != nil && n.Endpoint != nil && !(n.Endpoint.IP == nil && n.Endpoint.DNS == "") && n.Endpoint.Port != 0 && n.Key != nil && n.Subnet != nil && time.Now().Unix()-n.LastSeen < int64(checkInPeriod)*2/int64(time.Second) | ||||
| } | ||||
|  | ||||
| // Peer represents a peer in the network. | ||||
|   | ||||
| @@ -65,6 +65,7 @@ type Mesh struct { | ||||
| 	priv         []byte | ||||
| 	privIface    int | ||||
| 	pub          []byte | ||||
| 	resyncPeriod time.Duration | ||||
| 	stop         chan struct{} | ||||
| 	subnet       *net.IPNet | ||||
| 	table        *route.Table | ||||
| @@ -85,7 +86,7 @@ type Mesh struct { | ||||
| } | ||||
|  | ||||
| // New returns a new Mesh instance. | ||||
| func New(backend Backend, enc encapsulation.Encapsulator, granularity Granularity, hostname string, port uint32, subnet *net.IPNet, local, cni bool, cniPath, iface string, cleanUpIface bool, createIface bool, logger log.Logger) (*Mesh, error) { | ||||
| func New(backend Backend, enc encapsulation.Encapsulator, granularity Granularity, hostname string, port uint32, subnet *net.IPNet, local, cni bool, cniPath, iface string, cleanUpIface bool, createIface bool, resyncPeriod time.Duration, logger log.Logger) (*Mesh, error) { | ||||
| 	if err := os.MkdirAll(kiloPath, 0700); err != nil { | ||||
| 		return nil, fmt.Errorf("failed to create directory to store configuration: %v", err) | ||||
| 	} | ||||
| @@ -143,7 +144,7 @@ func New(backend Backend, enc encapsulation.Encapsulator, granularity Granularit | ||||
| 		level.Debug(logger).Log("msg", "running without a private IP address") | ||||
| 	} | ||||
| 	level.Debug(logger).Log("msg", fmt.Sprintf("using %s as the public IP address", publicIP.String())) | ||||
| 	ipTables, err := iptables.New(iptables.WithLogger(log.With(logger, "component", "iptables"))) | ||||
| 	ipTables, err := iptables.New(iptables.WithLogger(log.With(logger, "component", "iptables")), iptables.WithResyncPeriod(resyncPeriod)) | ||||
| 	if err != nil { | ||||
| 		return nil, fmt.Errorf("failed to IP tables controller: %v", err) | ||||
| 	} | ||||
| @@ -234,7 +235,8 @@ func (m *Mesh) Run() error { | ||||
| 		} | ||||
| 	}() | ||||
| 	defer m.cleanUp() | ||||
| 	t := time.NewTimer(resyncPeriod) | ||||
| 	resync := time.NewTimer(m.resyncPeriod) | ||||
| 	checkIn := time.NewTimer(checkInPeriod) | ||||
| 	nw := m.Nodes().Watch() | ||||
| 	pw := m.Peers().Watch() | ||||
| 	var ne *NodeEvent | ||||
| @@ -245,13 +247,15 @@ func (m *Mesh) Run() error { | ||||
| 			m.syncNodes(ne) | ||||
| 		case pe = <-pw: | ||||
| 			m.syncPeers(pe) | ||||
| 		case <-t.C: | ||||
| 		case <-checkIn.C: | ||||
| 			m.checkIn() | ||||
| 			checkIn.Reset(checkInPeriod) | ||||
| 		case <-resync.C: | ||||
| 			if m.cni { | ||||
| 				m.updateCNIConfig() | ||||
| 			} | ||||
| 			m.applyTopology() | ||||
| 			t.Reset(resyncPeriod) | ||||
| 			resync.Reset(m.resyncPeriod) | ||||
| 		case <-m.stop: | ||||
| 			return nil | ||||
| 		} | ||||
|   | ||||
							
								
								
									
										1
									
								
								vendor/modules.txt
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								vendor/modules.txt
									
									
									
									
										vendored
									
									
								
							| @@ -154,6 +154,7 @@ github.com/prometheus/procfs/xfs | ||||
| ## explicit | ||||
| github.com/spf13/cobra | ||||
| # github.com/spf13/pflag v1.0.3 | ||||
| ## explicit | ||||
| github.com/spf13/pflag | ||||
| # github.com/stretchr/testify v1.3.0 | ||||
| ## explicit | ||||
|   | ||||
		Reference in New Issue
	
	Block a user