Skip to content
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

allow to add ips to vrouter nics #565

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

Thiryn
Copy link
Contributor

@Thiryn Thiryn commented Jul 29, 2024

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue 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 PR followers and do not help prioritize the request

Description

References

closes #564

New or Affected Resource(s)

  • opennebula_virtual_router_nic

Checklist

  • I have created an issue and I have mentioned it in References
  • My code follows the style guidelines of this project (use go fmt)
  • My changes generate no new warnings or errors
  • I have updated the unit tests and they pass succesfuly
  • I have commented my code, particularly in hard-to-understand areas
  • I have updated the documentation (if needed)
  • I have updated the changelog file

@Thiryn
Copy link
Contributor Author

Thiryn commented Jul 29, 2024

Will update docs and changelog if this gets accepted

@Thiryn
Copy link
Contributor Author

Thiryn commented Aug 20, 2024

Found out the reason why the CI is failing, I didn't see the provider tests are creating 2 VRouter instance, and obviously we can't attach 2 non-floating IP to the instances.
What's the best way to tackle this in your opinion ? Should I isolate the NIC IP attachement test in a separate test file? I'm not familiar enough with the provider test to know if there is a way to delete a specific resource from a previous test step.

Scratch that, I didn't see that the test contained previous resources too, I think I should be able to update the test to cover the use cases correctly.

adapt the tests to ensure there is only one vrouter instance when creating nic with non-floating IPs
@Thiryn Thiryn marked this pull request as draft August 21, 2024 13:12
@Thiryn
Copy link
Contributor Author

Thiryn commented Aug 21, 2024

just putting this back as draft until I fix the tests entirely

@Thiryn
Copy link
Contributor Author

Thiryn commented Aug 26, 2024

A couple things have changed:

  • The NIC delete function now waits on the leases to be freed. There is a sync issue in ON where even when the NIC gets freed, the IP lease isn't quite free for another few seconds. I made this specific error a retry-able error.
  • I added some tests:
    • Testing with and without floating IP
    • Removing the 2nd vrouter instance before attaching the first NIC, as we obviously can't assign a static IP to 2 different VRouter VMs
    • Did some housekeeping and arranged the test terraform for that file in a uniform manner (4-spaces seemed to be the standard, I used that)

@Thiryn Thiryn marked this pull request as ready for review August 26, 2024 12:24
Copy link

This pull request is stale because it has been open for 30 days with no activity and it is not in a milestone. Remove 'status: stale' label or comment, or this will be closed in 5 days.

Copy link
Collaborator

@treywelsh treywelsh left a comment

Choose a reason for hiding this comment

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

I took a quick look at the PR. Thanks for this contribution.
It's nice to have some tests in it.

Reworking the commit history would be nice:
Please take a look at master commit names, they're often prepended with an issue number and F for feature, B for bug (I tried to keep more or less then OpenNebula way to name the commits)
As a side note: formatting the acceptance test adds a bit of noise to the whole PR changes, maybe that should be in a separate commit but it's not a big deal

resource.TestCheckResourceAttrSet("opennebula_virtual_router.test", "gid"),
resource.TestCheckResourceAttrSet("opennebula_virtual_router.test", "uname"),
resource.TestCheckResourceAttrSet("opennebula_virtual_router.test", "gname"),
resource.TestCheckResourceAttr("opennebula_virtual_router_nic.nic_floating_IP_specified", "floating_ip", "true"),
Copy link
Collaborator

Choose a reason for hiding this comment

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

when snake case is used, keep it lowercase to be consistent

@@ -209,6 +219,13 @@ func resourceOpennebulaVirtualRouterNICRead(ctx context.Context, d *schema.Resou

floatingIP, _ := nic.GetStr("FLOATING_IP")
floatingOnly, _ := nic.GetStr("FLOATING_ONLY")
ip, _ := nic.Get("IP")

// For VRouter NICs, floating IPs are set using the "IP" field, but it is represented in the ON API
Copy link
Collaborator

Choose a reason for hiding this comment

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

tiny typo: ONE

Copy link
Collaborator

@sk4zuzu sk4zuzu Oct 16, 2024

Choose a reason for hiding this comment

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

Hi! I believe this implementation suggestion is incorrect. If you look at implementation of a virtual machine https://registry.terraform.io/providers/OpenNebula/opennebula/latest/docs/resources/virtual_machine#nic there is the computed_ip "attribute" at the same time the ip is a "parameter". The VR NIC is somewhat similar and I believe it should follow the same convention. 🤔

Copy link
Contributor Author

@Thiryn Thiryn Oct 29, 2024

Choose a reason for hiding this comment

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

I understand the need for consistency, but do we really want two fields, an ip to set and a computed_ip to get? It seems counterintuitive, and a bit of an anti-pattern.

@@ -101,6 +101,13 @@ func vrNICAttach(ctx context.Context, timeout time.Duration, controller *goca.Co
updatedNICsLoop:
for i, nic := range updatedNICs {

// For VRouter NICs, floating IPs are set using the "IP" field, but it is represented in the ON API
Copy link
Collaborator

Choose a reason for hiding this comment

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

unless I miss something it seems that this whole code part in helpers_vr.go is useless ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These few lines enable the IP to be set on the NIC resource for vrouter. On VRouter NICs that use floating IP, ON represents the IP in the VROUTER_IP field.
This loop is ran when updating NICs. Without this, when running terraform apply to update the NIC would yield an empty IP (and therefore trigger a recreation when not necessary)

})
return diags
}
err = resource.RetryContext(ctx, d.Timeout(schema.TimeoutCreate), func() *resource.RetryError {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Did you ensured that prepending the Delete call with a waitForVNetworkState call wouldn't fix this ?
As a side note, you're using TimeoutCreate in the delete method here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It does in the tests. This was explicitly a problem with floating IPs if I remember. It happens that ON takes a little more time to release floating IPs and it was creating test failures (see one of such tests here https://github.com/Thiryn/terraform-provider-opennebula/actions/runs/10548061643/job/29221515518#step:10:575).

In reality, this fix should also be applied to the AR resources, but this isn't the point of this PR. The only reason the fix is limited to the network, is because we use the now-deprecated feature of AR entries in the vnet resources in our VR tests https://github.com/OpenNebula/terraform-provider-opennebula/blob/master/opennebula/resource_opennebula_virtual_router_test.go#L285-L289

@sk4zuzu sk4zuzu self-assigned this Oct 16, 2024
Copy link
Collaborator

@sk4zuzu sk4zuzu left a comment

Choose a reason for hiding this comment

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

@rsmontero rsmontero added this to the 1.4.2 milestone Oct 21, 2024
@Thiryn Thiryn requested a review from sk4zuzu October 29, 2024 16:47
@Thiryn
Copy link
Contributor Author

Thiryn commented Oct 29, 2024

@treywelsh sorry for the formatting, you're right it should be separate, do you want me to revert those changes?
With regard to the commit history, don't you usually do a squash merge? Meaning that the history of individual commits in the PR is 'lost' anyways as its all under a single commit on master?

I don't mind reworking the history, but please confirm that it is necessary before I do so.

Cheers,
Dorian

@Thiryn Thiryn requested a review from treywelsh October 29, 2024 16:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add IP to opennebula_virtual_router_nic
4 participants