-
-
Notifications
You must be signed in to change notification settings - Fork 231
fix(apt): add support for modern APT sources (PVE9+) #2376
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?
Conversation
Signed-off-by: Maciej Lech <maciej.lech@mlit.pro>
Summary of ChangesHello @maciej-lech, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces crucial updates to the Proxmox Terraform provider to align with changes in APT repository management in Proxmox VE 9.0 and later. It enables the provider to seamlessly interact with both the new DEB822 ".sources" file format and the traditional ".list" format, based on the detected Proxmox VE version. This ensures robust and forward-compatible management of APT repositories, allowing users to configure Proxmox systems with the latest software distribution practices while retaining support for older environments. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
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.
Code Review
This pull request introduces support for modern APT sources found in Proxmox VE 9.0 and newer. The changes are well-structured, propagating version information through various layers of the provider to correctly handle different APT source formats. The addition of extensive tests for the new version-dependent logic is commendable.
I've identified a critical issue that could cause a panic due to a potential nil pointer dereference, a minor bug in a test's regular expression, and an opportunity to refactor some duplicated code to improve maintainability. Once these points are addressed, the changes will be solid.
| // For whatever reason the non-Ceph handle "test" kind does not use a dash in between the "pve" prefix. | ||
| if v.kind == apitypes.StandardRepoHandleKindTest { | ||
| // On PVE8, for whatever reason the non-Ceph handle "test" kind does not use a dash in between the "pve" prefix. | ||
| if !proxmoxVersion.SupportModernAptSources() && v.kind == apitypes.StandardRepoHandleKindTest { |
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 call to proxmoxVersion.SupportModernAptSources() will cause a nil pointer dereference if proxmoxVersion is nil. While call sites within this PR seem to pass a valid pointer, the IsSupportedFilePath function in this same file handles a nil proxmoxVersion, and it's good practice for public methods to be robust against nil inputs. You should add a nil check for proxmoxVersion before dereferencing it.
| if !proxmoxVersion.SupportModernAptSources() && v.kind == apitypes.StandardRepoHandleKindTest { | |
| if proxmoxVersion != nil && !proxmoxVersion.SupportModernAptSources() && v.kind == apitypes.StandardRepoHandleKindTest { |
| ver := version.MinimumProxmoxVersion | ||
| if versionResp, err := d.client.Version().Version(ctx); err == nil { | ||
| ver = versionResp.Version | ||
| } else { | ||
| tflog.Warn(ctx, "Failed to determine Proxmox VE version, assuming minimum supported version.", map[string]any{ | ||
| "error": err, | ||
| "assumed_version": ver.String(), | ||
| }) | ||
| } |
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.
| knownvalue.ListPartial( | ||
| map[int]knownvalue.Check{ | ||
| 0: knownvalue.StringRegexp(regexp.MustCompile(`https?://ftp\.([a-z]+\.)?debian\.org/debian`)), | ||
| 0: knownvalue.StringRegexp(regexp.MustCompile(`http?://([a-z]+\.)?debian\.org/debian/`)), |
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 regular expression http?://... will not match URLs starting with https://. It seems you intended to match both http and https. The previous regex https?://... was correct in this regard.
| 0: knownvalue.StringRegexp(regexp.MustCompile(`http?://([a-z]+\.)?debian\.org/debian/`)), | |
| 0: knownvalue.StringRegexp(regexp.MustCompile(`https?://([a-z]+\.)?debian\.org/debian/`)), |
| ver := version.MinimumProxmoxVersion | ||
| if versionResp, err := r.client.Version().Version(ctx); err == nil { | ||
| ver = versionResp.Version | ||
| } else { | ||
| tflog.Warn(ctx, "Failed to determine Proxmox VE version, assuming minimum supported version.", map[string]any{ | ||
| "error": err, | ||
| "assumed_version": ver.String(), | ||
| }) | ||
| } |
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.
Contributor's Note
/docsfor any user-facing features or additions./fwprovider/testsfor any new or updated resources / data sources.make exampleto verify that the change works as expected.Proof of Work
testacc.log
Some of tests failed, but I don't think any of failure is related to the changes.
example.log
Community Note
Closes #2219
Closes #2341