-
Notifications
You must be signed in to change notification settings - Fork 242
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Spike] Use crc config
to use custom location for .crc directory
#4088
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,6 +37,7 @@ const ( | |
EmergencyLogin = "enable-emergency-login" | ||
PersistentVolumeSize = "persistent-volume-size" | ||
EnableBundleQuayFallback = "enable-bundle-quay-fallback" | ||
CrcDir = "crc-dir" | ||
) | ||
|
||
func RegisterSettings(cfg *Config) { | ||
|
@@ -141,13 +142,18 @@ func RegisterSettings(cfg *Config) { | |
|
||
cfg.AddSetting(EnableBundleQuayFallback, false, ValidateBool, SuccessfullyApplied, | ||
"If bundle download from the default location fails, fallback to quay.io (true/false, default: false)") | ||
cfg.AddSetting(CrcDir, constants.GetHomeDir(), validateDirectory, RequiresCRCSetup, | ||
"Location for .crc") | ||
|
||
if err := cfg.RegisterNotifier(Preset, presetChanged); err != nil { | ||
if err := cfg.RegisterNotifier(Preset, settingChanged); err != nil { | ||
logging.Debugf("Failed to register notifier for Preset: %v", err) | ||
} | ||
if err := cfg.RegisterNotifier(CrcDir, settingChanged); err != nil { | ||
logging.Debugf("Failed to register notifier for .crc directory: %v", err) | ||
} | ||
} | ||
|
||
func presetChanged(cfg *Config, _ string, _ interface{}) { | ||
func settingChanged(cfg *Config, _ string, _ interface{}) { | ||
UpdateDefaults(cfg) | ||
} | ||
|
||
|
@@ -167,6 +173,10 @@ func GetPreset(config Storage) preset.Preset { | |
return preset.ParsePreset(config.Get(Preset).AsString()) | ||
} | ||
|
||
func GetConfigDir(config Storage) string { | ||
return config.Get(CrcDir).AsString() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Related to the question: "Is this the config directory or crc directory?" |
||
} | ||
|
||
func defaultNetworkMode() network.Mode { | ||
if runtime.GOOS != "linux" { | ||
return network.UserNetworkingMode | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -164,7 +164,8 @@ func GetHomeDir() string { | |
} | ||
|
||
// EnsureBaseDirectoriesExist creates ~/.crc, ~/.crc/bin and ~/.crc/cache directories if it is not present | ||
func EnsureBaseDirectoriesExist() error { | ||
func EnsureBaseDirectoriesExist(configDir string) error { | ||
initialiseAllDirectories(configDir) | ||
baseDirectories := []string{CrcBaseDir, MachineCacheDir, CrcBinDir} | ||
for _, baseDir := range baseDirectories { | ||
err := os.MkdirAll(baseDir, 0750) | ||
|
@@ -175,6 +176,26 @@ func EnsureBaseDirectoriesExist() error { | |
return nil | ||
} | ||
|
||
func initialiseAllDirectories(crcDir string) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not just about directories, as there are also sockets, and configuration files. |
||
if crcDir == "" { | ||
return | ||
} | ||
CrcBaseDir = filepath.Join(crcDir, ".crc") | ||
CrcBinDir = filepath.Join(CrcBaseDir, "bin") | ||
CrcOcBinDir = filepath.Join(CrcBinDir, "oc") | ||
CrcPodmanBinDir = filepath.Join(CrcBinDir, "podman") | ||
CrcSymlinkPath = filepath.Join(CrcBinDir, "crc") | ||
ConfigPath = filepath.Join(CrcBaseDir, ConfigFile) | ||
LogFilePath = filepath.Join(CrcBaseDir, LogFile) | ||
DaemonLogFilePath = filepath.Join(CrcBaseDir, DaemonLogFile) | ||
MachineBaseDir = CrcBaseDir | ||
MachineCacheDir = filepath.Join(MachineBaseDir, "cache") | ||
MachineInstanceDir = filepath.Join(MachineBaseDir, "machines") | ||
DaemonSocketPath = filepath.Join(CrcBaseDir, "crc.sock") | ||
KubeconfigFilePath = filepath.Join(MachineInstanceDir, DefaultName, "kubeconfig") | ||
PasswdFilePath = filepath.Join(MachineInstanceDir, DefaultName, "passwd") | ||
} | ||
|
||
func GetPublicKeyPath() string { | ||
return filepath.Join(MachineInstanceDir, DefaultName, "id_ecdsa.pub") | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -168,6 +168,16 @@ func ValidatePath(path string) error { | |
return nil | ||
} | ||
|
||
// ValidateDirectory checks if provided path exists and has sufficient permissions | ||
func ValidateDirectory(path string) error { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is great for re-use |
||
file, err := os.CreateTemp(path, "tempfile") | ||
if err != nil { | ||
return &invalidPath{path: path} | ||
} | ||
defer os.Remove(file.Name()) | ||
return nil | ||
} | ||
|
||
type imagePullSecret struct { | ||
Auths map[string]map[string]interface{} `json:"auths"` | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this the config directory or crc directory?