-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
helpers.go
57 lines (52 loc) · 1.5 KB
/
helpers.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// SPDX-License-Identifier: Apache-2.0
// Copyright 2021 The Kubernetes Authors
package store
import (
"errors"
"os"
"path/filepath"
"runtime"
)
// DefaultStoreDir returns the default location for the store.
// It's dependent on operating system:
//
// - Windows: %LocalAppData%\kubebuilder-envtest
// - OSX: ~/Library/Application Support/io.kubebuilder.envtest
// - Others: ${XDG_DATA_HOME:-~/.local/share}/kubebuilder-envtest
//
// Otherwise, it errors out. Note that these paths must not be relied upon
// manually.
func DefaultStoreDir() (string, error) {
var baseDir string
// find the base data directory
switch runtime.GOOS {
case "windows":
baseDir = os.Getenv("LocalAppData")
if baseDir == "" {
return "", errors.New("%LocalAppData% is not defined")
}
case "darwin", "ios":
homeDir := os.Getenv("HOME")
if homeDir == "" {
return "", errors.New("$HOME is not defined")
}
baseDir = filepath.Join(homeDir, "Library/Application Support")
default:
baseDir = os.Getenv("XDG_DATA_HOME")
if baseDir == "" {
homeDir := os.Getenv("HOME")
if homeDir == "" {
return "", errors.New("neither $XDG_DATA_HOME nor $HOME are defined")
}
baseDir = filepath.Join(homeDir, ".local/share")
}
}
// append our program-specific dir to it (OSX has a slightly different
// convention so try to follow that).
switch runtime.GOOS {
case "darwin", "ios":
return filepath.Join(baseDir, "io.kubebuilder.envtest"), nil
default:
return filepath.Join(baseDir, "kubebuilder-envtest"), nil
}
}