Skip to content

Commit

Permalink
Machine instance dir stores more then one VM
Browse files Browse the repository at this point in the history
Since the machine instances dir at ~/.crc/machines/ store more then one
VM instance files, using MachineInstancesDir (plural) to  differentiate
from the InstanceDirName
  • Loading branch information
anjannath committed Jul 6, 2023
1 parent bb0625d commit 08a936c
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 21 deletions.
34 changes: 17 additions & 17 deletions pkg/crc/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,18 +98,18 @@ func GetDefaultBundle(preset crcpreset.Preset) string {
}

var (
CrcBaseDir = filepath.Join(GetHomeDir(), ".crc")
CrcBinDir = filepath.Join(CrcBaseDir, "bin")
CrcOcBinDir = filepath.Join(CrcBinDir, "oc")
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, InstanceDirName(), "kubeconfig")
CrcBaseDir = filepath.Join(GetHomeDir(), ".crc")
CrcBinDir = filepath.Join(CrcBaseDir, "bin")
CrcOcBinDir = filepath.Join(CrcBinDir, "oc")
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")
MachineInstancesDir = filepath.Join(MachineBaseDir, "machines")
DaemonSocketPath = filepath.Join(CrcBaseDir, "crc.sock")
KubeconfigFilePath = filepath.Join(MachineInstancesDir, InstanceDirName(), "kubeconfig")
)

func InstanceDirName() string {
Expand Down Expand Up @@ -173,24 +173,24 @@ func EnsureBaseDirectoriesExist() error {
}

func GetPublicKeyPath() string {
return filepath.Join(MachineInstanceDir, InstanceDirName(), "id_ecdsa.pub")
return filepath.Join(MachineInstancesDir, InstanceDirName(), "id_ecdsa.pub")
}

func GetPrivateKeyPath() string {
return filepath.Join(MachineInstanceDir, InstanceDirName(), "id_ecdsa")
return filepath.Join(MachineInstancesDir, InstanceDirName(), "id_ecdsa")
}

func GetHostDockerSocketPath() string {
return filepath.Join(MachineInstanceDir, InstanceDirName(), "docker.sock")
return filepath.Join(MachineInstancesDir, InstanceDirName(), "docker.sock")
}

// For backward compatibility to v 1.20.0
func GetRsaPrivateKeyPath() string {
return filepath.Join(MachineInstanceDir, InstanceDirName(), "id_rsa")
return filepath.Join(MachineInstancesDir, InstanceDirName(), "id_rsa")
}

func GetKubeAdminPasswordPath() string {
return filepath.Join(MachineInstanceDir, InstanceDirName(), "kubeadmin-password")
return filepath.Join(MachineInstancesDir, InstanceDirName(), "kubeadmin-password")
}

// TODO: follow the same pattern as oc and podman above
Expand Down
2 changes: 1 addition & 1 deletion pkg/crc/machine/generate_bundle_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func copyDiskImage(destDir string) (string, string, error) {

imageName := fmt.Sprintf("%s.qcow2", constants.InstanceName())

srcPath := filepath.Join(constants.MachineInstanceDir, constants.InstanceDirName(), imageName)
srcPath := filepath.Join(constants.MachineInstancesDir, constants.InstanceDirName(), imageName)
destPath := filepath.Join(destDir, imageName)

_, _, err := crcos.RunWithDefaultLocale("qemu-img", "convert", "-f", "qcow2", "-O", destFormat, srcPath, destPath)
Expand Down
2 changes: 1 addition & 1 deletion pkg/crc/machine/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -980,7 +980,7 @@ func bundleMismatchWithPreset(preset crcPreset.Preset, bundleMetadata *bundle.Cr
func updateCockpitConsoleBearerToken(sshRunner *crcssh.Runner) error {
logging.Info("Adding new bearer token for cockpit webconsole")

tokenPath := filepath.Join(constants.MachineInstanceDir, constants.InstanceDirName(), "cockpit-bearer-token")
tokenPath := filepath.Join(constants.MachineInstancesDir, constants.InstanceDirName(), "cockpit-bearer-token")
token := cluster.GenerateCockpitBearerToken()

if err := os.WriteFile(tokenPath, []byte(token), 0600); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/crc/oc/oc.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func UseOCWithConfig(machineName string) Config {
return Config{
Runner: crcos.NewLocalCommandRunner(),
OcExecutablePath: filepath.Join(constants.CrcOcBinDir, constants.OcExecutableName),
KubeconfigPath: filepath.Join(constants.MachineInstanceDir, machineName, "kubeconfig"),
KubeconfigPath: filepath.Join(constants.MachineInstancesDir, machineName, "kubeconfig"),
Context: constants.DefaultContext,
Cluster: constants.DefaultClusterName,
Timeout: defaultTimeout,
Expand Down
2 changes: 1 addition & 1 deletion pkg/crc/preflight/preflight_checks_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func removeHostsFileEntry() error {

func removeCRCMachinesDir() error {
logging.Debug("Deleting machines directory")
if err := os.RemoveAll(constants.MachineInstanceDir); err != nil {
if err := os.RemoveAll(constants.MachineInstancesDir); err != nil {
return fmt.Errorf("Failed to delete crc machines directory: %w", err)
}
return nil
Expand Down

0 comments on commit 08a936c

Please sign in to comment.