-
Notifications
You must be signed in to change notification settings - Fork 453
Feat/manifest deployer symlink support #6751
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: main
Are you sure you want to change the base?
Feat/manifest deployer symlink support #6751
Conversation
- Add KubeSchedulerStatus and KubeControllerManagerStatus to K0sStatus - Implement lease checking in status handler to verify component health - Update k0s status command output to show component status - Fixes k0sproject#3435
- Enhanced FindManifestFilesInDir to resolve symlinks and skip broken ones - Added getAllStackDirectories to detect symlinked directories as stacks - Implemented symlink watching in StackApplier with dynamic event handling - Added comprehensive test coverage with 12 new test cases - Enables git-based manifest workflows with automatic reconciliation Fixes k0sproject#4402
twz123
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.
Thanks for working on this! Had a very quick first pass on this.
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.
Can you merge this into the existing manager_test.go file?
|
|
||
| fmt.Fprintln(w, "Kube-scheduler probing successful:", status.KubeSchedulerStatus.Success) | ||
| fmt.Fprintln(w, "Kube-scheduler probing last error: ", status.KubeSchedulerStatus.Message) | ||
|
|
||
| fmt.Fprintln(w, "Kube-controller-manager probing successful:", status.KubeControllerManagerStatus.Success) | ||
| fmt.Fprintln(w, "Kube-controller-manager probing last error: ", status.KubeControllerManagerStatus.Message) |
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.
Although this seems useful, it doesn't belong to this PR. Would you mind to shove this into another one?
| // First, try to resolve any symlinks in the directory path | ||
| resolvedDir, err := filepath.EvalSymlinks(dir) | ||
| if err != nil { | ||
| // If we can't resolve the directory path, use the original directory | ||
| // This can happen if the directory contains broken symlinks | ||
| resolvedDir = dir | ||
| } | ||
|
|
||
| // Get all yaml files in the resolved directory | ||
| files, err := filepath.Glob(filepath.Join(resolvedDir, manifestFilePattern)) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| for _, file := range files { | ||
| // Check if the file is a symlink and if it's broken | ||
| info, err := os.Lstat(file) | ||
| if err != nil { | ||
| continue // Skip if we can't even stat the file | ||
| } | ||
|
|
||
| if info.Mode()&os.ModeSymlink != 0 { | ||
| // It's a symlink, check if it's broken | ||
| _, err := os.Stat(file) | ||
| if err != nil { | ||
| continue // Skip broken symlinks | ||
| } | ||
| } | ||
|
|
||
| fileMap[file] = true | ||
| } |
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 wonder if this is necessary? Wouldn't the OS / file system handle this automatically?
Description
This PR adds comprehensive symlink support to the k0s Manifest Deployer, enabling users to store manifests in external locations (like git repositories) and symlink them into
/var/lib/k0s/manifestsfor automatic deployment and reconciliation. This directly addresses the feature request in issue #4402 where users want to maintain manifests in a central git repository and use symlinks for automatic deployment.Problem Solved:
Previously, the Manifest Deployer did not resolve symlinks in the manifests directory, did not listen for filesystem events behind symlinks, and could not detect symlinked directories as valid stacks or process symlinked manifest files.
Solution Implemented:
Fixes #4402
Type of change
How Has This Been Tested?
Automated Testing:
Added 12 comprehensive test cases across 3 test files:
File Discovery Tests (
pkg/applier/symlink_test.go):TestFindManifestFilesInDir_WithSymlinks- Tests symlinked directory resolutionTestFindManifestFilesInDir_WithSymlinkedFiles- Tests symlinked manifest file detectionTestFindManifestFilesInDir_BrokenSymlink- Tests graceful handling of broken symlinksTestFindManifestFilesInDir_MixedFilesAndSymlinks- Tests mixed regular and symlinked filesManager Integration Tests (
pkg/applier/manager_symlink_test.go):TestManager_WithSymlinkedStacks- Tests symlinked stack directory detection and applicationTestManager_WithSymlinkedStackAfterStart- Tests dynamic symlink creation after manager startupTestManager_WithBrokenSymlink- Tests manager tolerance of broken symlinksTestManager_WithSymlinkedManifestFile- Tests symlinked manifest file processingStack Applier Tests (
pkg/applier/stackapplier_symlink_test.go):TestStackApplier_WithSymlinkedDirectory- Tests stack applier with symlinked directoriesTestStackApplier_WithSymlinkedFiles- Tests stack applier with symlinked filesTestStackApplier_WithBrokenSymlink- Tests error handling for broken symlinksTestStackApplier_WithMixedFilesAndSymlinks- Tests mixed scenariosTo run tests: