Skip to content

Conversation

@maciej-lech
Copy link
Contributor

Contributor's Note

  • I have added / updated documentation in /docs for any user-facing features or additions.
  • I have added / updated acceptance tests in /fwprovider/tests for any new or updated resources / data sources.
  • I have ran make example to 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

  • Please vote on this pull request by adding a 👍 reaction to the original pull request comment to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for pull request followers and do not help prioritize the request

Closes #2219
Closes #2341

Signed-off-by: Maciej Lech <maciej.lech@mlit.pro>
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @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

  • Modern APT Source Support (PVE9+): The provider now supports the new DEB822 ".sources" file format for APT repositories, which is standard in Proxmox VE 9.0 and newer, while maintaining compatibility with the legacy ".list" format.
  • Proxmox Version-Aware Logic: Implemented dynamic detection of the Proxmox VE version to correctly determine and apply the appropriate APT source file paths and component naming conventions.
  • Updated Repository Path Handling: Refactored the logic for identifying supported file paths and generating component names for APT repositories to be version-aware, ensuring accurate configuration across different PVE versions.
  • Comprehensive Test Updates: Existing acceptance tests have been updated, and new unit tests added, to validate the correct behavior of APT repository management with both modern and legacy source formats.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a 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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

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.

Suggested change
if !proxmoxVersion.SupportModernAptSources() && v.kind == apitypes.StandardRepoHandleKindTest {
if proxmoxVersion != nil && !proxmoxVersion.SupportModernAptSources() && v.kind == apitypes.StandardRepoHandleKindTest {

Comment on lines +91 to +99
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(),
})
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This block of code for determining the Proxmox VE version is duplicated in fwprovider/nodes/apt/resource_standard_repo.go. To improve maintainability and avoid future inconsistencies, consider extracting this logic into a shared helper function.

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/`)),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
0: knownvalue.StringRegexp(regexp.MustCompile(`http?://([a-z]+\.)?debian\.org/debian/`)),
0: knownvalue.StringRegexp(regexp.MustCompile(`https?://([a-z]+\.)?debian\.org/debian/`)),

Comment on lines +73 to +81
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(),
})
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This block of code for determining the Proxmox VE version is duplicated in fwprovider/nodes/apt/datasource_standard_repo.go. To improve maintainability and avoid future inconsistencies, consider extracting this logic into a shared helper function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

1 participant