Skip to content
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] Setting directory for .crc folder #3966

Open
Maurycy-Krzeminski opened this issue Jan 19, 2024 · 13 comments
Open

[Spike] Setting directory for .crc folder #3966

Maurycy-Krzeminski opened this issue Jan 19, 2024 · 13 comments
Assignees
Labels
kind/enhancement New feature or request status/unclear description Task needs more description before work can start

Comments

@Maurycy-Krzeminski
Copy link
Contributor

Maurycy-Krzeminski commented Jan 19, 2024

Is there consideration to use XDG base directory, or maybe using some other named env variable that would allow to set where .crc folder should be?

From what i saw issue 220 about XDG was closed.

@anjannath
Copy link
Member

If we change the crc home dir, we should also do automated migration of the config file to the new location. I think XDG base directory as the default and allowing users to override with $CRC_HOME_DIR both should be added

@anjannath anjannath added the kind/enhancement New feature or request label Jan 22, 2024
@vyasgun
Copy link
Contributor

vyasgun commented Feb 7, 2024

/assign

@vyasgun
Copy link
Contributor

vyasgun commented Apr 2, 2024

Please correct me if I am wrong -- The .crc directory stores the cache, machine info, and socket for communicating with the crc daemon and is used in multiple parts of the lifecycle (setup, start). Just setting the environment variable can create a discrepancy if the user sets it multiple times

export CRC_HOME_DIR=/tmp/crc1
crc start
crc stop
export CRC_HOME_DIR=/tmp/crc2

It is difficult to keep track of all the values the variable can take and migrating over and over does not seem like a feasible idea. (I made a draft PR for this)

My suggestion is to use crc config to store the path of the .crc directory which can be set and unset using the crc config command. This makes validation easier, it's more explicit, and easier to keep track of. Also, it reinforces the idea that we cannot have multiple .crc directories each having its own cache, socket etc.

@praveenkumar
Copy link
Member

My suggestion is to use crc config to store the path of the .crc directory which can be set and unset using the crc config command. This makes validation easier, it's more explicit, and easier to keep track of. Also, it reinforces the idea that we cannot have multiple .crc directories each having its own cache, socket etc.

In this case also user can do following

crc config set base-directory foo
crc start
crc stop
crc config unset base-directory

One thing we can do as part config option is have a callback function which check if current set directory already have content or not, if it have let user know and ask for override otherwise carry on with provided option?

@vyasgun
Copy link
Contributor

vyasgun commented Apr 3, 2024

I was thinking we could migrate from the existing base directory (if nothing is set, we would use the default $HOME/.crc to the newly set one. (Unset could trigger reverse migration from the custom location to the default location).

@cfergeau
Copy link
Contributor

cfergeau commented Apr 3, 2024

My suggestion is to use crc config to store the path of the .crc directory which can be set and unset using the crc config command. This makes validation easier, it's more explicit, and easier to keep track of.

I'd first make that work well before thinking too much about corner cases (such has the user changing the base directory while using crc). Though a callback would make sense to check if there's already a configured directory. This callback could offer the user to migrate. But this is starting to get complicated ^^

The suggested approach will not solve the initial request to use the XDG directory structure, where we'd need to use ~/.cache/crc, ~/.local/share, and (.local/state and/or XDG_RUNTIME_DIR) (only mentioning this for clarity, not saying this has to be solved - it could be too late for that, though once we can relocate/migrate ~/.crc, we can think how hard it would be to have optional migration to XDG)

@gbraad
Copy link
Contributor

gbraad commented May 14, 2024

XDG directory structure

Which complicates deployment on platforms other than Linux, so this might not have been the solution to begin with.

The question that has not been answered is the 'Why' is this requested?

  • large files/storage requirement not available on the default location
  • permissions maybe not available
  • roaming profile or other issues with user directory on a network share/'removable media'
  • ...

@gbraad gbraad added the status/unclear description Task needs more description before work can start label May 14, 2024
@Maurycy-Krzeminski
Copy link
Contributor Author

For my case it was large files/storage requirement not available on the default location, currently I just run it from my fork with this one small change and this works for me commit

@gbraad gbraad changed the title Setting directory for .crc folder [Spike] Setting directory for .crc folder May 16, 2024
@gbraad
Copy link
Contributor

gbraad commented May 16, 2024

default location

are you on Linux or MacOS? Would a re-location with a symlink have worked?

The issue is that we use a standardized location to ensure the VM files are always in the same location; if we allow this to be configured, there can be a inconsistency; the VMM already has a registration with a VM called 'crc', while the executable sees nothing in it's own .crc/machines folder.

The commit you show is an elegant solution that might work for platforms that support this;

I would say:

  • if XDG_DATA_HOME (linux only) is set or a possible override CRC_DATA_HOME (all platforms?) is given.
  • check permissions in the home (something we didn't do before; as relocation might not be OK)
  • ...

@Maurycy-Krzeminski
Copy link
Contributor Author

I run it on Windows 10.
I didn't try to use symlinks, I will test them next week, mabe they actually solve all my problems.

@gbraad
Copy link
Contributor

gbraad commented May 16, 2024

On windows junctions might be able to do this, or a remapped location for a disk with Disk Manager. But be aware, on Windows you can NOT store VM disk files on anything that is a "Removable Media"; USB or disks that are dynamic.

I run it on Windows 10.

But most likely not with the XDG value, as this is unknown on a Windows system:

C:\> powershell
PS> $env:XDG_DATA_HOME
PS> $env:HOME
C:\Users\gbraad

Note: in your commit you check for an empty value, so that would be ignored. However, if this is not possible on the platform, best to use constants_linux.go for platform specific solution, or use an additional CRC_DATA_HOME to override either if existent, as this would work on all platforms and is more explicit. This would also allow you to set export CRC_DATA_HOME=$XDG_DATA_HOME to achieve the same.

@gbraad
Copy link
Contributor

gbraad commented May 17, 2024

As commented on the Spike PR by @vyasgun:


The objective of this spike was to test whether the crc config can be used to configure a custom .crc location. The conclusion is that it is not something that will solve the problem and could potentially cause unexpected issues in certain edge cases:

  • If VM has already been started, modifying .crc location could result in inconsistent behaviour.
  • The base case (for the default directory to open from) has to be defined outside of .crc folder as it will result in a chicken and egg problem.
  • The major request to use a custom directory mainly comes from having a custom location to store the larger files such as cache and machine configs. Using more straightforward solution such as using environment variable related configuration may be more helpful to accomplish this.
  • The original request for using XDG base directory env variables in certain cases may be solved using this commit:

Next steps:

  • Redefine the problem and come up with a solution that enables the user to manage their storage more effectively.

@praveenkumar
Copy link
Member

. The original request for using XDG base directory env variables in certain cases may be solved using this commit:

I think if this is something user want then we can set CRC_DATA_DIR env variable and can be used across platform but user should set required permission and selinux context to that directory manually before use it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/enhancement New feature or request status/unclear description Task needs more description before work can start
Projects
Status: Hold
Development

No branches or pull requests

6 participants