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 a26a5ab1d7
commit 9111b1f77e

@ -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 // If not found, the default will be used, which varies depending on whether
// k3s is being run as root or not. // k3s is being run as root or not.
func findDataDir(args []string) string { 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 := pflag.NewFlagSet("data-dir-set", pflag.ContinueOnError)
fs.ParseErrorsWhitelist.UnknownFlags = true fs.ParseErrorsWhitelist.UnknownFlags = true
fs.SetOutput(io.Discard) fs.SetOutput(io.Discard)

@ -266,11 +266,14 @@ func NewAgentCommand(action func(ctx *cli.Context) error) cli.Command {
EnvVar: version.ProgramUpper + "_URL", EnvVar: version.ProgramUpper + "_URL",
Destination: &AgentConfig.ServerURL, 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{ &cli.StringFlag{
Name: "data-dir,d", Name: "data-dir,d",
Usage: "(agent/data) Folder to hold state", Usage: "(agent/data) Folder to hold state",
Destination: &AgentConfig.DataDir, Destination: &AgentConfig.DataDir,
Value: "/var/lib/rancher/" + version.Program + "", Value: "/var/lib/rancher/" + version.Program + "",
EnvVar: version.ProgramUpper + "_DATA_DIR",
}, },
NodeNameFlag, NodeNameFlag,
WithNodeIDFlag, WithNodeIDFlag,

@ -28,6 +28,7 @@ var (
}, },
} }
CertRotateCACommandFlags = []cli.Flag{ CertRotateCACommandFlags = []cli.Flag{
DataDirFlag,
cli.StringFlag{ cli.StringFlag{
Name: "server,s", Name: "server,s",
Usage: "(cluster) Server to connect to", Usage: "(cluster) Server to connect to",
@ -35,11 +36,6 @@ var (
Value: "https://127.0.0.1:6443", Value: "https://127.0.0.1:6443",
Destination: &ServerConfig.ServerURL, 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{ cli.StringFlag{
Name: "path", Name: "path",
Usage: "Path to directory containing new CA certificates", Usage: "Path to directory containing new CA certificates",

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

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

Loading…
Cancel
Save