2019-01-09 16:54:15 +00:00
|
|
|
package datadir
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"github.com/pkg/errors"
|
2019-05-09 22:05:51 +00:00
|
|
|
"github.com/rancher/wrangler/pkg/resolvehome"
|
2019-01-09 16:54:15 +00:00
|
|
|
)
|
|
|
|
|
2019-01-26 04:53:53 +00:00
|
|
|
const (
|
|
|
|
DefaultDataDir = "/var/lib/rancher/k3s"
|
|
|
|
DefaultHomeDataDir = "${HOME}/.rancher/k3s"
|
2019-02-19 17:46:35 +00:00
|
|
|
HomeConfig = "${HOME}/.kube/k3s.yaml"
|
|
|
|
GlobalConfig = "/etc/rancher/k3s/k3s.yaml"
|
2019-01-26 04:53:53 +00:00
|
|
|
)
|
|
|
|
|
2019-01-09 16:54:15 +00:00
|
|
|
func Resolve(dataDir string) (string, error) {
|
2019-03-08 22:47:44 +00:00
|
|
|
return LocalHome(dataDir, false)
|
|
|
|
}
|
|
|
|
|
|
|
|
func LocalHome(dataDir string, forceLocal bool) (string, error) {
|
2019-01-09 16:54:15 +00:00
|
|
|
if dataDir == "" {
|
2019-03-08 22:47:44 +00:00
|
|
|
if os.Getuid() == 0 && !forceLocal {
|
2019-01-26 04:53:53 +00:00
|
|
|
dataDir = DefaultDataDir
|
2019-01-09 16:54:15 +00:00
|
|
|
} else {
|
2019-01-26 04:53:53 +00:00
|
|
|
dataDir = DefaultHomeDataDir
|
2019-01-09 16:54:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
dataDir, err := resolvehome.Resolve(dataDir)
|
|
|
|
if err != nil {
|
|
|
|
return "", errors.Wrapf(err, "resolving %s", dataDir)
|
|
|
|
}
|
|
|
|
|
|
|
|
return dataDir, nil
|
|
|
|
}
|