-
Notifications
You must be signed in to change notification settings - Fork 176
[WIP] refactor: replace hardcoded paths with constants from locationconsts.go (#3682) #4965
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
base: master
Are you sure you want to change the base?
[WIP] refactor: replace hardcoded paths with constants from locationconsts.go (#3682) #4965
Conversation
|
@eriknordmark this will be a multi-commit PR, module by module. |
|
@milan-zededa @christoph-zededa There is a minor opportunity to centralize the path eve/pkg/pillar/base/kubevirt.go Lines 15 to 16 in 7ab0c0b
eve/pkg/pillar/hypervisor/hypervisor.go Line 98 in 7ab0c0b
However, Line 15 in 7ab0c0b
Because Alternatively, we could just remove this function and refactor its limited use: |
|
@jeff-zed I'm not sure if I follow the issue with the pillar/base package. ? |
cyclical dependency |
…go (lf-edge#3682) This will close lf-edge#3682, after each module is refactored - each module will be a separate commit. - pkg/pillar/types/locationconsts.go: • add RunDir, PersistLogDir, PersistTmpDir, HostFSEtcDir constants • add LinuxKitConfigFile, MemoryMonitorPSICollectorDir constants • refactor existing paths to use base constants (RunDir, PersistDir) • fix comment formatting and typos - pkg/pillar/agentlog/agentlog.go: • replace hardcoded /persist paths with PersistDir/PersistLogDir constants • update comments to reference constant names instead of hardcoded paths - pkg/pillar/agentlog/eveversion.go: • replace hardcoded /run/eve.id with types.RunDir constant - pkg/pillar/agentlog/http-debug.go: • replace hardcoded /persist/tmp with types.PersistTmpDir • replace hardcoded /hostfs/etc path with types.HostFSEtcDir • add missing types import - pkg/pillar/agentlog/http-debug_test.go: • replace hardcoded paths with corresponding types constants - pkg/pillar/agentlog/cmd/psi-collector/main.go: • replace hardcoded path with types.MemoryMonitorPSICollectorDir - pkg/pillar/agentlog/cmd/psi-collector/README.md: • update documentation to reflect refactored constants Paths NOT changed: - System/kernel paths (/proc, /sys, /hostfs/sys) - these are fixed system interfaces - Device files (/dev/tty, /dev/null) - standard Unix device files - External software paths (/usr/lib/xen, /usr/local/share) - system-installed software - Test temporary paths - these are ephemeral and not part of EVE's directory structure Closes lf-edge#3682 Signed-off-by: jeff-zed <[email protected]>
…lepath.Join - pkg/pillar/agentlog/agentlog.go: replace concat with filepath.Join - pkg/pillar/agentlog/cmd/psi-collector/README.md: remove extraneous whitespace Signed-off-by: jeff-zed <[email protected]>
7ab0c0b to
802ab16
Compare
|
The runner deployment script seems to be malfunctioning. @rene is currently working on fixing it. |
- pkg/pillar/base/kubevirt.go: annotate why EveVirtTypeFile isn’t moved to types - pkg/pillar/base/touchfile.go: note WatchdogFileDir cyclical-import avoidance - pkg/pillar/hypervisor/hypervisor.go: use types.EveVirtTypeFile & types.SysfsPciDevicesDir - pkg/pillar/hypervisor/kvm.go: switch to types.SysfsPciDevicesDir for PCI resource path - pkg/pillar/hypervisor/pci.go: remove local sysfsPciDevices const, import types - pkg/pillar/pidfile/pidfile.go: replace defaultRundir with types.WatchdogPidDir - pkg/pillar/types/ifnametopci.go: remove pciPath, use SysfsPciDevicesDir + filepath.Join - pkg/pillar/types/locationconsts.go: introduce RunDir, Watchdog*/MemoryMonitor*/SysfsPciDevicesDir, update derived paths Signed-off-by: jeff-zed <[email protected]>
0986749 to
9084371
Compare
pkg/pillar/base/touchfile.go
Outdated
|
|
||
| const ( | ||
| //These contants are available in pkg/pillar/types/locationcnsts.go; however, using them | ||
| //causes a cyclical dependency. |
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.
☝️ Yetus errors to be fixed.
| CustomOVMFSettingsDir = "/hostfs/etc/ovmf" | ||
|
|
||
| // SysfsPciDevices - path in sysfs to the PCI devices | ||
| SysfsPciDevicesDir = "/sys/bus/pci/devices/" |
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.
☝️
rene
left a comment
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.
@jeff-zed apart from the Yetus errors yet to be fixed, it looks good to me...
There is still some more to commit. When I think I am done and it is ready for full review, I will add a comment indicating that for the reviewers. |
Until a PR is ready for review, we usually mark it as Draft and add [WIP] to the title. |
Thank you. |
- pkg/pillar/base/touchfile.go: updatecomments for WatchdogFileDir and WatchdogPidDir - pkg/pillar/types/locationconsts.go: update comment for SysfsPciDevicesDir Signed-off-by: jeff-zed <[email protected]>
- pkg/pillar/dpcreconciler/genericitems/ssh.go: import types and use types.RunDir - pkg/pillar/ssh/ssh.go: import types and use types.RunDir - pkg/pillar/nireconciler/genericitems/dnsmasq.go: comment for a candidate constant; replace hard-coded "/run/zedrouter" Signed-off-by: jeff-zed <[email protected]>
Thank you. This should also be helpful for EVE 15.3.0 that @eriknordmark tagged |
…utside pillar), cmd/domainmgr, pubsub - pkg/edgeview/src/network.go: import filepath and use Join - pkg/edgeview/src/system.go: use types.EdgeviewPath instead of "/run/edgeview" - pkg/pillar/cmd/domainmgr/domainmgr.go: use types.DomainMgrDirl - pkg/pillar/cmd/domainmgr/processes.go: remove local watch directories and use from pkg\pillar\locationconst.go - pkg/pillar/pubsub/checkmaxtime.go: annotate cyclical-dependency note - pkg/pillar/types/locationconsts.go: add DomainMgrDir = RunDir + "/domainmgr" Signed-off-by: jeff-zed <[email protected]>
|
Hi all. I noticed that pkg-deps.mk is currently ignored via .gitignore, but it needs to be versioned so CI picks up our updated dependency list. Would you prefer I remove the *.mk (or pkg-deps.mk) entry from .gitignore, or simply force-add this one file? There is also the question of whether edgeview should be modified to use the pkg/pillar/types/locationconst.go or not in the latest commit. Thanks! |
| "bytes" | ||
| "context" | ||
| "fmt" | ||
| "github.com/lf-edge/eve/pkg/pillar/types" |
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.
Please put this import below where the other non-std imports are placed.
| const ( | ||
| //PIDFile is the file to store the PID | ||
| PIDFile = types.MemoryMonitorDir + "/psi-collector/psi-collector.pid" | ||
| PIDFile = types.MemoryMonitorPSICollectorDir + "/psi-collector.pid" |
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.
You changed many other places to use filepath.Join but not here. Any particular reason?
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.
I think it does not work for const - #4965 (comment)
|
|
||
| const ( | ||
| partitionFile = "/run/eve.id" | ||
| partitionFile = types.RunDir + "/eve.id" |
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.
Ditto
| } | ||
|
|
||
| err = os.MkdirAll("/hostfs/etc/", 0755) | ||
| err = os.MkdirAll(types.HostFSEtcDir, 0755) |
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.
This is a test file hence it doesn't run on EVE but in the build environment, hence I'm confused by the references to /hostfs and /persist which only exist in the EVE runtime environment.
|
|
||
| const ( | ||
| // EveVirtTypeFile contains the virtualization type, ie kvm, xen or kubevirt | ||
| //This could be referenced from `pkg\pillar\types\locationconsts.go`, but it would cause |
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.
Please replace backslashes by forward slashes.
| return fmt.Errorf("checkAndCreatePidfile: %s", description) | ||
| } | ||
| rundir := defaultRundir | ||
| rundir := types.WatchdogPidDir |
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.
Incorrect. Should be RunDir
| } | ||
| if opt.baseDir == "" { | ||
| opt.baseDir = defaultRundir | ||
| opt.baseDir = types.WatchdogPidDir |
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.
Incorrect. Should be RunDir
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.
Two cases of wrong directory being used which needs to be fixed. See detailed comments.
Also, build is utterly failing due to
14.69 vet: ./network.go:305:50: undefined: types.DomainMgrDir
I think it is better (and sets less of a precendent) to not introduce locationconst values for the various /run/ directories, and it happens to avoid this internal vendoring issue (pkg/pillar being vendored into pkg/edgeview).
Also, any idea why golangcilint has issues on line 1 in pkg/edgeview/src/basics.go?
This PR resolves Issue #3682 by replacing hardcoded filesystem paths with centralized constants from
locationconsts.goacross the pillar modules, improving code maintainability and consistency. The refactoring centralizes path management while preserving existing functionality and maintaining clear separation between EVE-managed paths and system paths.Currently, 5 modules have been updated pending test verification (see commits for details):
pkg/pillar/types/locationconsts.go
pkg/pillar/agentlog/*
pkg/pillar/base/*
pkg/pillar/hypervisor/*
pkg/pillar/pidfile/*
PR dependencies
How to test and validate this PR
make test pkg/pillarChangelog notes
This addresses technical debt by centralizing filesystem path management, making future path changes easier to implement and reducing the risk of inconsistent path usage across the codebase.
PR Backports
N/A - This is a refactoring change that improves maintainability without changing functionality.
Checklist