crc-org / crc

CRC is a tool to help you run containers. It manages a local OpenShift 4.x cluster, Microshift or a Podman VM optimized for testing and development purposes
https://crc.dev
Apache License 2.0
1.26k stars 239 forks source link

[BUG] Formulation of home directory is improper for Windows #2201

Open cameronkerrnz opened 3 years ago

cameronkerrnz commented 3 years ago

General information

CRC version

CodeReady Containers version: 1.24.0+5f06e84b
OpenShift version: 4.7.2 (embedded in executable)

CRC config

(empty).... but only because its looking in the wrong place

Host Operating System

PS H:\> systeminfo

Host Name:                 REDACTED
OS Name:                   Microsoft Windows 10 Enterprise
OS Version:                10.0.19042 N/A Build 19042
OS Manufacturer:           Microsoft Corporation
OS Configuration:          Member Workstation
OS Build Type:             Multiprocessor Free
Registered Owner:          REDACTED
Registered Organization:   REDACTED
Product ID:                00329-00000-00003-AA300
Original Install Date:     21/01/2021, 5:13:35 pm
System Boot Time:          9/04/2021, 3:43:36 pm
System Manufacturer:       Dell Inc.
System Model:              Precision 3551
System Type:               x64-based PC
Processor(s):              1 Processor(s) Installed.
                           [01]: Intel64 Family 6 Model 165 Stepping 2 GenuineIntel ~2400 Mhz
BIOS Version:              Dell Inc. 1.3.1, 29/09/2020
Windows Directory:         C:\WINDOWS
System Directory:          C:\WINDOWS\system32
Boot Device:               \Device\HarddiskVolume1
System Locale:             en-us;English (United States)
Input Locale:              00000481
Time Zone:                 (UTC+12:00) Auckland, Wellington
Total Physical Memory:     32,365 MB
Available Physical Memory: 24,350 MB
Virtual Memory: Max Size:  50,797 MB
Virtual Memory: Available: 41,147 MB
Virtual Memory: In Use:    9,650 MB
Page File Location(s):     C:\pagefile.sys
Domain:                    REDACTED
Logon Server:              \\REDACTED
Hotfix(s):                 7 Hotfix(s) Installed.
                           [01]: KB4601050
                           [02]: KB4562830
                           [03]: KB4570334
                           [04]: KB4577266
                           [05]: KB4580325
                           [06]: KB5000802
                           [07]: KB5000858
Network Card(s):           6 NIC(s) Installed.
                           [01]: Intel(R) Wi-Fi 6 AX201 160MHz
                                 Connection Name: Wi-Fi
                                 DHCP Enabled:    Yes
                                 DHCP Server:     10.64.32.21
                                 IP address(es)
                                 [01]: 10.96.83.193
                           [02]: Intel(R) Ethernet Connection (11) I219-LM
                                 Connection Name: Ethernet
                                 Status:          Media disconnected
                           [03]: Bluetooth Device (Personal Area Network)
                                 Connection Name: Bluetooth Network Connection
                                 Status:          Media disconnected
                           [04]: Realtek USB GbE Family Controller
                                 Connection Name: Ethernet 2
                                 Status:          Media disconnected
                           [05]: Hyper-V Virtual Ethernet Adapter
                                 Connection Name: vEthernet (Default Switch)
                                 DHCP Enabled:    No
                                 IP address(es)
                                 [01]: 172.27.240.1
                                 [02]: fe80::150:4096:715c:30eb
                           [06]: Cisco AnyConnect Secure Mobility Client Virtual Miniport Adapter for Windows x64
                                 Connection Name: Ethernet 4
                                 Status:          Hardware not present
Hyper-V Requirements:      A hypervisor has been detected. Features required for Hyper-V will not be displayed.

Steps to reproduce

This is applicable for users that have Roaming Profiles forced upon them. It is relates to performance issues that would be encountered by users with home directories that are network mounted (eg. over NFS).

  1. Boot a Windows client machine (eg Laptop) without being connected to its network (eg. developer at home)
  2. Observe that %HOMEDRIVE%%HOMEPATH% results in a local directory (== %USERPROFILE%) (eg. C:\Users\me)
  3. Run 'crc start' etc. and work with the product
  4. Go to work and reboot your machine (eg. to apply updates)
  5. Observe that %HOMEDRIVE%%HOMEPATH% results in an on-network location (eg. H:)
  6. Run 'crc start'

Analysis

In a similar vein, if I delete the CRC environment and start again while on-network, the directory "~.crc\cache" and "~.crc\machines" are also on-network, which is both very slow (which at scale becomes an issue for desktop support, network and storage teams).

On Windows, the cache and machines directories should not be ~.crc\cache (~.crc\machines) (where ~ is whatever the user's home directory is determined as), but should instead be housed within %LOCALAPPDATA% (eg. C:\Users\me\AppData\Local). The expectation would be that MachineBaseDir would be set to filepath.Join(os.UserCacheDir(), "crc"))

Golang (from version 1.12) will provide a suitable directory when you use os.UserCacheDir.

Similarly, there is os.UserConfigDir() and os.UserHomeDir(), which on Windows returns %APPDATA%, which when on-line for a roaming profile user is like C:\Users\me\AppData\Roaming

However, its probably not so useful to have the CRC configuration be remote (because it will get divorced from the machines if the user logs into a different machine), so I would advocate that the entirety of ~/.crc on Windows should really be in %LOCALAPPDATA% (filepath.Join(os.UserCacheDir(), "crc")), and a CRC installation should be understood to be a local-machine instance. At least this should be the default behaviour.

CRC attempts to determine what the user home directory using the code in GetHomeDrive(), but does not account for the fact that %HOMEDRIVE%%HOMEPATH% can be different in a connected (to profile server) versus disconnected (from profile server) state.

https://github.com/code-ready/crc/blob/f974ac2f80fddb69621b395ce0cc8e341cf75725/pkg/crc/constants/constants.go#L93-L105

Expected

crc start should successfully start my existing environment

Actual

crc start tells me to "Run 'crc setup' to unpack the bundle to disk"

Logs

Please consider posting the output of crc start --log-level debug on http://gist.github.com/ and post the link in the issue.

PS H:\> crc start --log-level debug
DEBU CodeReady Containers version: 1.24.0+5f06e84b
DEBU OpenShift version: 4.7.2 (embedded in executable)
DEBU Running 'crc start'
DEBU Total memory of system is 33937014784 bytes
Run 'crc setup' to unpack the bundle to disk

Workaround

In a PowerShell session, I can change the value of HOMEDRIVE and HOMEPATH, which is enough to steer crc in the correct direction to where the data actually is.

crc status --log-level debug
--> DEBU Checking file: H:\.crc\machines\crc\.crc-exist
--> Machine does not exist. Use 'crc start' to create it
$env:HOMEDRIVE = 'C:'
$env:HOMEPATH = '\Users\me'
crc status --log-level debug
--> DEBU Checking file: C:\Users\me\.crc\machines\crc\.crc-exist
--> finds the CRC VM

Please can this be added to the Known Issues. Possibly a wrapper script (eg. crc.bat or crc.ps1) may be a good idea.

praveenkumar commented 3 years ago

@cameronkerrnz Thank you for detail bug and also an analysis around what causing it and how it can be overcome. I think this should be fix as part of our code instead having it part of Known issues. Also we are working on the windows installer side which might take care of this usecase.

cc @anjannath @gbraad

cfergeau commented 3 years ago

Using os.UserCacheDir and friends was discussed a long time ago in https://github.com/code-ready/crc/issues/220, but we were not aware of the implications on remote Windows home dirs at the time

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.