-
Notifications
You must be signed in to change notification settings - Fork 53
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
base: master
Are you sure you want to change the base?
Conversation
Will update docs and changelog if this gets accepted |
8611212
to
16684e0
Compare
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. 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
just putting this back as draft until I fix the tests entirely |
A couple things have changed:
|
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. |
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 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"), |
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.
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 |
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.
tiny typo: ONE
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.
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. 🤔
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 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 |
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.
unless I miss something it seems that this whole code part in helpers_vr.go is useless ?
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.
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 { |
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.
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
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.
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
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.
@treywelsh sorry for the formatting, you're right it should be separate, do you want me to revert those changes? I don't mind reworking the history, but please confirm that it is necessary before I do so. Cheers, |
Community Note
Description
References
closes #564
New or Affected Resource(s)
Checklist
References
go fmt
)