mirror of
https://github.com/k3s-io/k3s.git
synced 2024-06-07 19:41:36 +00:00
9a849b1bb7
* changing package to k3s-io Signed-off-by: Luther Monson <luther.monson@gmail.com> Co-authored-by: Derek Nola <derek.nola@suse.com>
39 lines
891 B
Go
39 lines
891 B
Go
package datadir
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
|
|
"github.com/k3s-io/k3s/pkg/version"
|
|
"github.com/pkg/errors"
|
|
"github.com/rancher/wrangler/pkg/resolvehome"
|
|
)
|
|
|
|
var (
|
|
DefaultDataDir = "/var/lib/rancher/" + version.Program
|
|
DefaultHomeDataDir = "${HOME}/.rancher/" + version.Program
|
|
HomeConfig = "${HOME}/.kube/" + version.Program + ".yaml"
|
|
GlobalConfig = "/etc/rancher/" + version.Program + "/" + version.Program + ".yaml"
|
|
)
|
|
|
|
func Resolve(dataDir string) (string, error) {
|
|
return LocalHome(dataDir, false)
|
|
}
|
|
|
|
func LocalHome(dataDir string, forceLocal bool) (string, error) {
|
|
if dataDir == "" {
|
|
if os.Getuid() == 0 && !forceLocal {
|
|
dataDir = DefaultDataDir
|
|
} else {
|
|
dataDir = DefaultHomeDataDir
|
|
}
|
|
}
|
|
|
|
dataDir, err := resolvehome.Resolve(dataDir)
|
|
if err != nil {
|
|
return "", errors.Wrapf(err, "resolving %s", dataDir)
|
|
}
|
|
|
|
return filepath.Abs(dataDir)
|
|
}
|