-
Notifications
You must be signed in to change notification settings - Fork 30
Use hostname for lxd registration. Code refactoring. #240
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
Conversation
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.
Pull Request Overview
This PR implements hostname-based naming conventions for LXD host registration with MAAS instead of using IP addresses, along with significant code refactoring to improve maintainability and structure.
- Use hostname-based naming convention (
lxd-host-<hostname>) for LXD host registration instead of IP-based naming - Refactor machine deletion logic into smaller, more focused functions
- Update LXD initializer to use normalized node names and clean up commented code
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/maas/lxd/host_maas_client.go | Enhanced registration logic to use hostname-based naming with fallback to IP, refactored function signatures |
| lxd-initializer/lxd-initializer.go | Updated to use normalized node names for host registration and removed commented code |
| lxd-initializer/lxd-initializer-daemonset.yaml | Updated container image version |
| controllers/templates/lxd_initializer_ds.yaml | Updated container image version |
| controllers/maasmachine_controller.go | Major refactoring of deletion logic into smaller functions and hostname-based LXD host operations |
| controllers/lxd_initializer_ds.go | Refactored large function into smaller, focused helper functions for better maintainability |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| hostName := canonicalLXDHostName(m.Hostname) | ||
| if hostName == "lxd-host-" { | ||
| return | ||
| } |
Copilot
AI
Sep 17, 2025
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.
The check for empty hostname suffix is fragile. If m.Hostname is empty or whitespace-only, canonicalLXDHostName will return 'lxd-host-' which matches this condition, but this logic assumes the hostname is always non-empty after trimming. Consider checking strings.TrimSpace(m.Hostname) == \"\" directly before calling canonicalLXDHostName.
| hostName := canonicalLXDHostName(m.Hostname) | ||
| if hostName == "lxd-host-" { | ||
| return err | ||
| } |
Copilot
AI
Sep 17, 2025
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.
Same issue as above - the check for empty hostname suffix is duplicated and fragile. Consider extracting this validation into a helper function or checking the hostname before calling canonicalLXDHostName.
* PCP-5152: Multiple node HCP cluster losing interface reference * Additional changes (#225) * Additional changes * trust password and code cleanup (#226) * Additional changes * Add gate to registration logic, seperate it to initializer and put grace period. Code cleanup. * Add gate to registration logic, seperate it to initializer and put grace period. Code cleanup. (#234) * Additional changes * Add gate to registration logic, seperate it to initializer and put grace period. Code cleanup. * - Gosec fix - Cleanup daemonset once all host are registered * Additional changes * Use hsotname for lxd registration. Code refactoring. (#240) * Use hsotname for lxd registration. Code refactoring. * merge conflict
* PCP-5152: Multiple node HCP cluster losing interface reference * Additional changes (#225) * Additional changes * trust password and code cleanup (#226) * Additional changes * Add gate to registration logic, seperate it to initializer and put grace period. Code cleanup. * Add gate to registration logic, seperate it to initializer and put grace period. Code cleanup. (#234) * Additional changes * Add gate to registration logic, seperate it to initializer and put grace period. Code cleanup. * - Gosec fix - Cleanup daemonset once all host are registered * Additional changes * Use hsotname for lxd registration. Code refactoring. (#240) * Use hsotname for lxd registration. Code refactoring. * merge conflict (cherry picked from commit 5939162)
…#244) * PCP-5152: Multiple node HCP cluster losing interface reference * Additional changes (#225) * Additional changes * trust password and code cleanup (#226) * Additional changes * Add gate to registration logic, seperate it to initializer and put grace period. Code cleanup. * Add gate to registration logic, seperate it to initializer and put grace period. Code cleanup. (#234) * Additional changes * Add gate to registration logic, seperate it to initializer and put grace period. Code cleanup. * - Gosec fix - Cleanup daemonset once all host are registered * Additional changes * Use hsotname for lxd registration. Code refactoring. (#240) * Use hsotname for lxd registration. Code refactoring. * merge conflict (cherry picked from commit 5939162) Co-authored-by: Amit Sahastrabuddhe <[email protected]>
No description provided.