Skip to content

Commit 70f287e

Browse files
committed
keeper: don't set default user during flag definition
Don't set default user during flag definition but at startup or the user used to generate the doc will be written in the generated command doc.
1 parent d2f4a09 commit 70f287e

17 files changed

+33
-26
lines changed

cmd/keeper/cmd/keeper.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,6 @@ type config struct {
117117
var cfg config
118118

119119
func init() {
120-
user, err := util.GetUser()
121-
if err != nil {
122-
log.Fatalf("cannot get current user: %v", err)
123-
}
124-
125120
cmd.AddCommonFlags(CmdKeeper, &cfg.CommonConfig)
126121

127122
CmdKeeper.PersistentFlags().StringVar(&cfg.uid, "id", "", "keeper uid (must be unique in the cluster and can contain only lower-case letters, numbers and the underscore character). If not provided a random uid will be generated.")
@@ -137,7 +132,7 @@ func init() {
137132
CmdKeeper.PersistentFlags().StringVar(&cfg.pgReplPassword, "pg-repl-password", "", "postgres replication user password. Only one of --pg-repl-password or --pg-repl-passwordfile must be provided. Must be the same for all keepers.")
138133
CmdKeeper.PersistentFlags().StringVar(&cfg.pgReplPasswordFile, "pg-repl-passwordfile", "", "postgres replication user password file. Only one of --pg-repl-password or --pg-repl-passwordfile must be provided. Must be the same for all keepers.")
139134
CmdKeeper.PersistentFlags().StringVar(&cfg.pgSUAuthMethod, "pg-su-auth-method", "md5", "postgres superuser auth method. Default is md5.")
140-
CmdKeeper.PersistentFlags().StringVar(&cfg.pgSUUsername, "pg-su-username", user, "postgres superuser user name. Used for keeper managed instance access and pg_rewind based synchronization. It'll be created on db initialization. Defaults to the name of the effective user running stolon-keeper. Must be the same for all keepers.")
135+
CmdKeeper.PersistentFlags().StringVar(&cfg.pgSUUsername, "pg-su-username", "", "postgres superuser user name. Used for keeper managed instance access and pg_rewind based synchronization. It'll be created on db initialization. Defaults to the name of the effective user running stolon-keeper. Must be the same for all keepers.")
141136
CmdKeeper.PersistentFlags().StringVar(&cfg.pgSUPassword, "pg-su-password", "", "postgres superuser password. Only one of --pg-su-password or --pg-su-passwordfile must be provided. Must be the same for all keepers.")
142137
CmdKeeper.PersistentFlags().StringVar(&cfg.pgSUPasswordFile, "pg-su-passwordfile", "", "postgres superuser password file. Only one of --pg-su-password or --pg-su-passwordfile must be provided. Must be the same for all keepers)")
143138
CmdKeeper.PersistentFlags().BoolVar(&cfg.debug, "debug", false, "enable debug logging")
@@ -1867,6 +1862,18 @@ func keeper(c *cobra.Command, args []string) {
18671862
listenAddFlag = "pg-advertise-address"
18681863
)
18691864

1865+
flags := c.Flags()
1866+
1867+
if !flags.Changed("pg-su-username") {
1868+
// set the pgSuUsername to the current user
1869+
var user string
1870+
user, err = util.GetUser()
1871+
if err != nil {
1872+
log.Fatalf("cannot get current user: %v", err)
1873+
}
1874+
cfg.pgSUUsername = user
1875+
}
1876+
18701877
validAuthMethods := make(map[string]struct{})
18711878
validAuthMethods["trust"] = struct{}{}
18721879
validAuthMethods["md5"] = struct{}{}

doc/commands/stolon-keeper.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ stolon-keeper [flags]
2020
--log-color enable color in log output (default if attached to a terminal)
2121
--log-level string debug, info (default), warn or error (default "info")
2222
--metrics-listen-address string metrics listen address i.e "0.0.0.0:8080" (disabled by default)
23+
--pg-advertise-address string postgresql instance address from outside. Use it to expose ip different than local ip with a NAT networking config
24+
--pg-advertise-port string postgresql instance port from outside. Use it to expose port different than local port with a PAT networking config
2325
--pg-bin-path string absolute path to postgresql binaries. If empty they will be searched in the current PATH
24-
--pg-listen-address string postgresql instance listening address
26+
--pg-listen-address string postgresql instance listening address, local address used for the postgres instance. For all network interface, you can set the value to '*'.
2527
--pg-port string postgresql instance listening port (default "5432")
2628
--pg-repl-auth-method string postgres replication user auth method. Default is md5. (default "md5")
2729
--pg-repl-password string postgres replication user password. Only one of --pg-repl-password or --pg-repl-passwordfile must be provided. Must be the same for all keepers.
@@ -30,7 +32,7 @@ stolon-keeper [flags]
3032
--pg-su-auth-method string postgres superuser auth method. Default is md5. (default "md5")
3133
--pg-su-password string postgres superuser password. Only one of --pg-su-password or --pg-su-passwordfile must be provided. Must be the same for all keepers.
3234
--pg-su-passwordfile string postgres superuser password file. Only one of --pg-su-password or --pg-su-passwordfile must be provided. Must be the same for all keepers)
33-
--pg-su-username string postgres superuser user name. Used for keeper managed instance access and pg_rewind based synchronization. It'll be created on db initialization. Defaults to the name of the effective user running stolon-keeper. Must be the same for all keepers. (default "motaboy")
35+
--pg-su-username string postgres superuser user name. Used for keeper managed instance access and pg_rewind based synchronization. It'll be created on db initialization. Defaults to the name of the effective user running stolon-keeper. Must be the same for all keepers.
3436
--store-backend string store backend type (etcdv2/etcd, etcdv3, consul or kubernetes)
3537
--store-ca-file string verify certificates of HTTPS-enabled store servers using this CA bundle
3638
--store-cert-file string certificate file for client identification to the store
@@ -41,4 +43,4 @@ stolon-keeper [flags]
4143
--uid string keeper uid (must be unique in the cluster and can contain only lower-case letters, numbers and the underscore character). If not provided a random uid will be generated.
4244
```
4345

44-
###### Auto generated by spf13/cobra on 21-Aug-2018
46+
###### Auto generated by spf13/cobra on 28-Jan-2020

doc/commands/stolon-proxy.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@ stolon-proxy [flags]
3434
--tcp-keepalive-interval int set tcp keepalive interval (seconds)
3535
```
3636

37-
###### Auto generated by spf13/cobra on 21-Aug-2018
37+
###### Auto generated by spf13/cobra on 28-Jan-2020

doc/commands/stolon-sentinel.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ stolon-sentinel [flags]
2929
--store-skip-tls-verify skip store certificate verification (insecure!!!)
3030
```
3131

32-
###### Auto generated by spf13/cobra on 21-Aug-2018
32+
###### Auto generated by spf13/cobra on 28-Jan-2020

doc/commands/stolonctl.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,4 @@ stolonctl [flags]
4343
* [stolonctl update](stolonctl_update.md) - Update a cluster specification
4444
* [stolonctl version](stolonctl_version.md) - Display the version
4545

46-
###### Auto generated by spf13/cobra on 1-Mar-2019
46+
###### Auto generated by spf13/cobra on 28-Jan-2020

doc/commands/stolonctl_clusterdata.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,4 @@ Manage current cluster data
3737
* [stolonctl clusterdata read](stolonctl_clusterdata_read.md) - Retrieve the current cluster data
3838
* [stolonctl clusterdata write](stolonctl_clusterdata_write.md) - Write cluster data
3939

40-
###### Auto generated by spf13/cobra on 24-Nov-2018
40+
###### Auto generated by spf13/cobra on 28-Jan-2020

doc/commands/stolonctl_clusterdata_read.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,4 @@ stolonctl clusterdata read [flags]
4040

4141
* [stolonctl clusterdata](stolonctl_clusterdata.md) - Manage current cluster data
4242

43-
###### Auto generated by spf13/cobra on 24-Nov-2018
43+
###### Auto generated by spf13/cobra on 28-Jan-2020

doc/commands/stolonctl_clusterdata_write.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
Write cluster data
44

5-
### **Warning: This shouldn't be used if you don't know what you're doing**
6-
75
### Synopsis
86

97
Write cluster data
@@ -43,4 +41,4 @@ stolonctl clusterdata write [flags]
4341

4442
* [stolonctl clusterdata](stolonctl_clusterdata.md) - Manage current cluster data
4543

46-
###### Auto generated by spf13/cobra on 24-Nov-2018
44+
###### Auto generated by spf13/cobra on 28-Jan-2020

doc/commands/stolonctl_failkeeper.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,4 @@ stolonctl failkeeper [keeper uid] [flags]
3939

4040
* [stolonctl](stolonctl.md) - stolon command line client
4141

42-
###### Auto generated by spf13/cobra on 21-Aug-2018
42+
###### Auto generated by spf13/cobra on 28-Jan-2020

doc/commands/stolonctl_init.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,4 @@ stolonctl init [flags]
4141

4242
* [stolonctl](stolonctl.md) - stolon command line client
4343

44-
###### Auto generated by spf13/cobra on 21-Aug-2018
44+
###### Auto generated by spf13/cobra on 28-Jan-2020

doc/commands/stolonctl_promote.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,4 @@ stolonctl promote [flags]
4040

4141
* [stolonctl](stolonctl.md) - stolon command line client
4242

43-
###### Auto generated by spf13/cobra on 21-Aug-2018
43+
###### Auto generated by spf13/cobra on 28-Jan-2020

doc/commands/stolonctl_register.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,4 @@ stolonctl register [flags]
5050

5151
* [stolonctl](stolonctl.md) - stolon command line client
5252

53-
###### Auto generated by spf13/cobra on 1-Mar-2019
53+
###### Auto generated by spf13/cobra on 28-Jan-2020

doc/commands/stolonctl_removekeeper.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,4 @@ stolonctl removekeeper [keeper uid] [flags]
3939

4040
* [stolonctl](stolonctl.md) - stolon command line client
4141

42-
###### Auto generated by spf13/cobra on 21-Aug-2018
42+
###### Auto generated by spf13/cobra on 28-Jan-2020

doc/commands/stolonctl_spec.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,4 @@ stolonctl spec [flags]
4040

4141
* [stolonctl](stolonctl.md) - stolon command line client
4242

43-
###### Auto generated by spf13/cobra on 21-Aug-2018
43+
###### Auto generated by spf13/cobra on 28-Jan-2020

doc/commands/stolonctl_status.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,4 @@ stolonctl status [flags]
4040

4141
* [stolonctl](stolonctl.md) - stolon command line client
4242

43-
###### Auto generated by spf13/cobra on 27-Mar-2019
43+
###### Auto generated by spf13/cobra on 28-Jan-2020

doc/commands/stolonctl_update.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,4 @@ stolonctl update [flags]
4141

4242
* [stolonctl](stolonctl.md) - stolon command line client
4343

44-
###### Auto generated by spf13/cobra on 21-Aug-2018
44+
###### Auto generated by spf13/cobra on 28-Jan-2020

doc/commands/stolonctl_version.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,4 @@ stolonctl version [flags]
3939

4040
* [stolonctl](stolonctl.md) - stolon command line client
4141

42-
###### Auto generated by spf13/cobra on 21-Aug-2018
42+
###### Auto generated by spf13/cobra on 28-Jan-2020

0 commit comments

Comments
 (0)