Browse Source

Add K3S_DATA_DIR as env var for --data-dir flag

Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
pull/10647/head
Brad Davidson 4 months ago committed by Brad Davidson
parent
commit
9111b1f77e
  1. 7
      cmd/k3s/main.go
  2. 3
      pkg/cli/cmds/agent.go
  3. 6
      pkg/cli/cmds/certs.go
  4. 5
      pkg/cli/cmds/root.go
  5. 1
      pkg/cli/cmds/server.go

7
cmd/k3s/main.go

@ -86,11 +86,14 @@ func main() {
}
}
// findDataDir reads data-dir settings from the CLI args and config file.
// findDataDir reads data-dir settings from the environment, CLI args, and config file.
// If not found, the default will be used, which varies depending on whether
// k3s is being run as root or not.
func findDataDir(args []string) string {
var dataDir string
dataDir := os.Getenv(version.ProgramUpper + "_DATA_DIR")
if dataDir != "" {
return dataDir
}
fs := pflag.NewFlagSet("data-dir-set", pflag.ContinueOnError)
fs.ParseErrorsWhitelist.UnknownFlags = true
fs.SetOutput(io.Discard)

3
pkg/cli/cmds/agent.go

@ -266,11 +266,14 @@ func NewAgentCommand(action func(ctx *cli.Context) error) cli.Command {
EnvVar: version.ProgramUpper + "_URL",
Destination: &AgentConfig.ServerURL,
},
// Note that this is different from DataDirFlag used elswhere in the CLI,
// as this is bound to AgentConfig instead of ServerConfig.
&cli.StringFlag{
Name: "data-dir,d",
Usage: "(agent/data) Folder to hold state",
Destination: &AgentConfig.DataDir,
Value: "/var/lib/rancher/" + version.Program + "",
EnvVar: version.ProgramUpper + "_DATA_DIR",
},
NodeNameFlag,
WithNodeIDFlag,

6
pkg/cli/cmds/certs.go

@ -28,6 +28,7 @@ var (
},
}
CertRotateCACommandFlags = []cli.Flag{
DataDirFlag,
cli.StringFlag{
Name: "server,s",
Usage: "(cluster) Server to connect to",
@ -35,11 +36,6 @@ var (
Value: "https://127.0.0.1:6443",
Destination: &ServerConfig.ServerURL,
},
cli.StringFlag{
Name: "data-dir,d",
Usage: "(data) Folder to hold state default /var/lib/rancher/" + version.Program + " or ${HOME}/.rancher/" + version.Program + " if not root",
Destination: &ServerConfig.DataDir,
},
cli.StringFlag{
Name: "path",
Usage: "Path to directory containing new CA certificates",

5
pkg/cli/cmds/root.go

@ -41,10 +41,7 @@ func NewApp() *cli.App {
}
app.Flags = []cli.Flag{
DebugFlag,
&cli.StringFlag{
Name: "data-dir,d",
Usage: "(data) Folder to hold state (default: /var/lib/rancher/" + version.Program + " or ${HOME}/.rancher/" + version.Program + " if not root)",
},
DataDirFlag,
}
return app

1
pkg/cli/cmds/server.go

@ -117,6 +117,7 @@ var (
Name: "data-dir,d",
Usage: "(data) Folder to hold state default /var/lib/rancher/" + version.Program + " or ${HOME}/.rancher/" + version.Program + " if not root",
Destination: &ServerConfig.DataDir,
EnvVar: version.ProgramUpper + "_DATA_DIR",
}
ServerToken = &cli.StringFlag{
Name: "token,t",

Loading…
Cancel
Save