update command line options documentation (#372)

* update command line options documentation

* add test for command line help doc
This commit is contained in:
Patrick Hemmer 2018-04-07 14:47:15 -04:00 committed by Murali Reddy
parent ed34187113
commit 4fd5cb812a
4 changed files with 101 additions and 38 deletions

View File

@ -99,34 +99,42 @@ Also you can choose to run kube-router as agent running on each cluster node. Al
### command line options ### command line options
``` ```
Usage of ./kube-router: Usage of kube-router:
--advertise-cluster-ip Add Cluster IP of the service to the RIB so that it gets advertises to the BGP peers. --advertise-cluster-ip Add Cluster IP of the service to the RIB so that it gets advertises to the BGP peers.
--advertise-external-ip Add External IP of service to the RIB so that it gets advertised to the BGP peers. --advertise-external-ip Add External IP of service to the RIB so that it gets advertised to the BGP peers.
--cleanup-config Cleanup iptables rules, ipvs, ipset configuration and exit. --advertise-loadbalancer-ip Add LoadbBalancer IP of service status as set by the LB provider to the RIB so that it gets advertised to the BGP peers.
--cluster-asn uint ASN number under which cluster nodes will run iBGP. --bgp-graceful-restart Enables the BGP Graceful Restart capability so that routes are preserved on unexpected restarts
--cluster-cidr string CIDR range of pods in the cluster. It is used to identify traffic originating from and destinated to pods. --cleanup-config Cleanup iptables rules, ipvs, ipset configuration and exit.
--config-sync-period duration The delay between apiserver configuration synchronizations (e.g. '5s', '1m'). Must be greater than 0. (default 1m0s) --cluster-asn uint ASN number under which cluster nodes will run iBGP.
--enable-overlay When enable-overlay set to true, IP-in-IP tunneling is used for pod-to-pod networking across nodes in different subnets. When set to false no tunneling is used and routing infrastrcture is expected to route traffic for pod-to-pod networking across nodes in different subnets (default true) --cluster-cidr string CIDR range of pods in the cluster. It is used to identify traffic originating from and destinated to pods.
--enable-pod-egress SNAT traffic from Pods to destinations outside the cluster. (default true) --config-sync-period duration The delay between apiserver configuration synchronizations (e.g. '5s', '1m'). Must be greater than 0. (default 1m0s)
--hairpin-mode Add iptable rules for every Service Endpoint to support hairpin traffic. --enable-ibgp Enables peering with nodes with the same ASN, if disabled will only peer with external BGP peers (default true)
-h, --help Print usage information. --enable-overlay When enable-overlay set to true, IP-in-IP tunneling is used for pod-to-pod networking across nodes in different subnets. When set to false no tunneling is used and routing infrastrcture is expected to route traffic for pod-to-pod networking across nodes in different subnets (default true)
--hostname-override string Overrides the NodeName of the node. Set this if kube-router is unable to determine your NodeName automatically. --enable-pod-egress SNAT traffic from Pods to destinations outside the cluster. (default true)
--iptables-sync-period duration The delay between iptables rule synchronizations (e.g. '5s', '1m'). Must be greater than 0. (default 1m0s) --enable-pprof Enables pprof for debugging performance and memory leak issues.
--ipvs-sync-period duration The delay between ipvs config synchronizations (e.g. '5s', '1m', '2h22m'). Must be greater than 0. (default 1m0s) --hairpin-mode Add iptable rules for every Service Endpoint to support hairpin traffic.
--kubeconfig string Path to kubeconfig file with authorization information (the master location is set by the master flag). --health-port uint16 Health check port, 0 = Disabled (default 20244)
--masquerade-all SNAT all traffic to cluster IP/node port. -h, --help Print usage information.
--master string The address of the Kubernetes API server (overrides any value in kubeconfig). --hostname-override string Overrides the NodeName of the node. Set this if kube-router is unable to determine your NodeName automatically.
--metrics-port int Prometheus metrics port to use ( default 8080 ) --iptables-sync-period duration The delay between iptables rule synchronizations (e.g. '5s', '1m'). Must be greater than 0. (default 1m0s)
--metrics-path string Path to serve Prometheus metrics on ( default /metrics ) --ipvs-sync-period duration The delay between ipvs config synchronizations (e.g. '5s', '1m', '2h22m'). Must be greater than 0. (default 1m0s)
--nodeport-bindon-all-ip For service of NodePort type create IPVS service that listens on all IP's of the node. --kubeconfig string Path to kubeconfig file with authorization information (the master location is set by the master flag).
--nodes-full-mesh Each node in the cluster will setup BGP peering with rest of the nodes. (default true) --masquerade-all SNAT all traffic to cluster IP/node port.
--peer-router-asns uintSlice ASN numbers of the BGP peer to which cluster nodes will advertise cluster ip and node's pod cidr. (default []) --master string The address of the Kubernetes API server (overrides any value in kubeconfig).
--peer-router-ips ipSlice The ip address of the external router to which all nodes will peer and advertise the cluster ip and pod cidr's. (default []) --metrics-path string Prometheus metrics path (default "/metrics")
--peer-router-passwords stringSlice Password for authenticating against the BGP peer defined with "--peer-router-ips". --metrics-port uint16 Prometheus metrics port, (Default 0, Disabled)
--routes-sync-period duration The delay between route updates and advertisements (e.g. '5s', '1m', '2h22m'). Must be greater than 0. (default 1m0s) --nodeport-bindon-all-ip For service of NodePort type create IPVS service that listens on all IP's of the node.
--run-firewall Enables Network Policy -- sets up iptables to provide ingress firewall for pods. (default true) --nodes-full-mesh Each node in the cluster will setup BGP peering with rest of the nodes. (default true)
--run-router Enables Pod Networking -- Advertises and learns the routes to Pods via iBGP. (default true) --peer-router-asns uints ASN numbers of the BGP peer to which cluster nodes will advertise cluster ip and node's pod cidr. (default [])
--run-service-proxy Enables Service Proxy -- sets up IPVS for Kubernetes Services. (default true)``` --peer-router-ips ipSlice The ip address of the external router to which all nodes will peer and advertise the cluster ip and pod cidr's. (default [])
--peer-router-multihop-ttl uint8 Enable eBGP multihop supports -- sets multihop-ttl. (Relevant only if ttl >= 2)
--peer-router-passwords strings Password for authenticating against the BGP peer defined with "--peer-router-ips".
--routes-sync-period duration The delay between route updates and advertisements (e.g. '5s', '1m', '2h22m'). Must be greater than 0. (default 1m0s)
--run-firewall Enables Network Policy -- sets up iptables to provide ingress firewall for pods. (default true)
--run-router Enables Pod Networking -- Advertises and learns the routes to Pods via iBGP. (default true)
--run-service-proxy Enables Service Proxy -- sets up IPVS for Kubernetes Services. (default true)
-v, --v string log level for V logs (default "0")
-V, --version Print version information.
``` ```
### requirements ### requirements

View File

@ -39,7 +39,7 @@ kube-router:
@echo Finished kube-router binary build. @echo Finished kube-router binary build.
test: gofmt ## Runs code quality pipelines (gofmt, tests, coverage, lint, etc) test: gofmt ## Runs code quality pipelines (gofmt, tests, coverage, lint, etc)
go test github.com/cloudnativelabs/kube-router/app/... github.com/cloudnativelabs/kube-router/utils/ go test github.com/cloudnativelabs/kube-router github.com/cloudnativelabs/kube-router/app/... github.com/cloudnativelabs/kube-router/utils/
vagrant-up: export docker=$(DOCKER) vagrant-up: export docker=$(DOCKER)
vagrant-up: export DEV_IMG=$(REGISTRY_DEV):$(IMG_TAG) vagrant-up: export DEV_IMG=$(REGISTRY_DEV):$(IMG_TAG)

View File

@ -14,7 +14,14 @@ import (
) )
func main() { func main() {
if err := Main(); err != nil {
fmt.Fprintf(os.Stderr, "%s\n", err)
os.Exit(1)
}
os.Exit(0)
}
func Main() error {
config := options.NewKubeRouterConfig() config := options.NewKubeRouterConfig()
config.AddFlags(pflag.CommandLine) config.AddFlags(pflag.CommandLine)
pflag.Parse() pflag.Parse()
@ -28,28 +35,26 @@ func main() {
if config.HelpRequested { if config.HelpRequested {
pflag.Usage() pflag.Usage()
os.Exit(0) return nil
} }
if config.Version { if config.Version {
app.PrintVersion(false) app.PrintVersion(false)
os.Exit(0) return nil
} }
if os.Geteuid() != 0 { if os.Geteuid() != 0 {
fmt.Fprintf(os.Stderr, "kube-router needs to be run with privileges to execute iptables, ipset and configure ipvs\n") return fmt.Errorf("kube-router needs to be run with privileges to execute iptables, ipset and configure ipvs")
os.Exit(1)
} }
if config.CleanupConfig { if config.CleanupConfig {
app.CleanupConfigAndExit() app.CleanupConfigAndExit()
os.Exit(0) return nil
} }
kubeRouter, err := app.NewKubeRouterDefault(config) kubeRouter, err := app.NewKubeRouterDefault(config)
if err != nil { if err != nil {
fmt.Fprintf(os.Stderr, "Failed to parse kube-router config: %v\n", err) return fmt.Errorf("Failed to parse kube-router config: %v", err)
os.Exit(1)
} }
if config.EnablePprof { if config.EnablePprof {
@ -60,7 +65,8 @@ func main() {
err = kubeRouter.Run() err = kubeRouter.Run()
if err != nil { if err != nil {
fmt.Fprintf(os.Stderr, "Failed to run kube-router: %v\n", err) return fmt.Errorf("Failed to run kube-router: %v", err)
os.Exit(1)
} }
return nil
} }

49
kube-router_test.go Normal file
View File

@ -0,0 +1,49 @@
package main
import (
"bytes"
"io"
"os"
"sync"
"testing"
)
func TestMainHelp(t *testing.T) {
origStderr := os.Stderr
stderrR, stderrW, _ := os.Pipe()
os.Stderr = stderrW
defer func() { os.Stderr = origStderr }()
stderrBuf := bytes.NewBuffer(nil)
wg := &sync.WaitGroup{}
wg.Add(1)
go func() {
io.Copy(stderrBuf, stderrR)
wg.Done()
}()
origArgs := os.Args
os.Args = []string{"kube-router", "--help"}
defer func() { os.Args = origArgs }()
if err := Main(); err != nil {
t.Fatalf("kube-router exited with error: %s\n", err)
}
stderrW.Close()
wg.Wait()
docF, err := os.Open("Documentation/README.md")
if err != nil {
t.Fatalf("could not open Documentation/README.md: %s\n", err)
}
docBuf := bytes.NewBuffer(nil)
docBuf.ReadFrom(docF)
docF.Close()
exp := append([]byte("```\n"), stderrBuf.Bytes()...)
exp = append(exp, []byte("```\n")...)
if !bytes.Contains(docBuf.Bytes(), exp) {
t.Errorf("Documentation/README.md 'command line options' section does not match `kube-router --help`.\nExpected:\n%s", exp)
}
}