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

refactor: move Metal VLAN resource and data source to equinix-sdk-go #541

Closed
wants to merge 4 commits into from

Conversation

ctreatma
Copy link
Contributor

@ctreatma ctreatma commented Jan 25, 2024

This refactors the VLAN resource and data source to use equinix-sdk-go instead of packngo. As part of this refactoring I've moved the VLAN resource and data source to an isolated package.

PR is in draft for now because there are a number of spec issues that need to be addressed and I want to get a feel for how manageable it is to move resources & change the SDK in one PR.

Part of #402
Part of #106

"vlan_id": vlan.GetId(),
"project_id": vlan.AssignedTo.GetId(), // vlan assigned_to is an href; should be project?
"vxlan": vlan.GetVxlan(),
"facility": vlan.FacilityCode, // facility is deprecated, vlan is metro-scoped; remove this attr?
Copy link
Contributor Author

Choose a reason for hiding this comment

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

In metal-cli we opted to remove facility from VLAN subcommands because facility is deprecated and VLANs are at the metro level anyway; however I think removing it entirely could be a bigger impact in terraform so we might want to maintain support for it for now?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Based on API responses I saw in Chrome developer tools, both facility and facility_code are null anyway, so maybe this is a non-issue? Perhaps for now we just explicitly set it to null everywhere in code and deprecate the attribute in the resource & data source schemas so we can remove it later?

} else if err != nil {
// missing vlans are deleted
return nil
}

// all device ports must be unassigned before delete
for _, i := range vlan.Instances {
for _, p := range i.NetworkPorts {
for _, p := range i.NetworkPorts { // instances is specced as a list of href; should be devices?
for _, a := range p.AttachedVirtualNetworks {
// a.ID is not set despite including instaces.network_ports.virtual_networks
// TODO(displague) packngo should offer GetID() that uses ID or Href
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hey look @displague, this TODO sounds familiar.

vlan, resp, err := client.ProjectVirtualNetworks.Get(id, &packngo.GetOptions{Includes: []string{"instances", "instances.network_ports.virtual_networks", "internet_gateway"}})
if equinix_errors.IgnoreResponseErrors(equinix_errors.HttpForbidden, equinix_errors.HttpNotFound)(resp, err) != nil {
return equinix_errors.FriendlyError(err)
vlan, resp, err := client.VLANsApi.GetVirtualNetwork(ctx, id).Include([]string{"instances", "instances.network_ports.virtual_networks", "internet_gateway"}).Execute()
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's possible a different include would fix the issue here (at least partially; may need spec changes so the SDK can correctly identify types)

Suggested change
vlan, resp, err := client.VLANsApi.GetVirtualNetwork(ctx, id).Include([]string{"instances", "instances.network_ports.virtual_networks", "internet_gateway"}).Execute()
vlan, resp, err := client.VLANsApi.GetVirtualNetwork(ctx, id).Include([]string{"instances", "virtual_networks", "internet_gateway"}).Execute()

Comment on lines +86 to +87
meta.(*config.Config).AddModuleToMetalGoUserAgent(d)
client := meta.(*config.Config).Metalgo
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I always trip myself up on updating these two lines. If config.Config had GetMetalClient(d *schema.ResourceData), GetFabricClient(d *schema.ResourceData), etc. functions we could handle the User-Agent modification there so it doesn't have to be replicated in every CRUD function in every resource & data source.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

every resource & data source

Turns out we're only modifying the User-Agent in data sources. Why is that?

@@ -62,6 +62,7 @@ func getFromEnvDefault(varName string, defaultValue string) string {
return defaultValue
}

// TODO: seems like this is sweeper config and broadly used; why is it non-standard?
func GetConfigForNonStandardMetalTest() (*config.Config, error) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Doesn't necessarily need to happen in this PR, but IMO this should be GetConfigForSweeper and should fully replicate the behavior of the analogous sharedConfigForRegion in the equinix package

@codecov-commenter
Copy link

Codecov Report

Attention: 46 lines in your changes are missing coverage. Please review.

Comparison is base (9877239) 44.71% compared to head (bdf1566) 58.95%.

Files Patch % Lines
internal/resources/metal/vlan/resource.go 66.66% 33 Missing and 8 partials ⚠️
internal/resources/metal/vlan/datasource.go 80.76% 5 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@             Coverage Diff             @@
##             main     #541       +/-   ##
===========================================
+ Coverage   44.71%   58.95%   +14.24%     
===========================================
  Files          99      100        +1     
  Lines       19890    19890               
===========================================
+ Hits         8893    11727     +2834     
+ Misses      10963     7867     -3096     
- Partials       34      296      +262     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@displague
Copy link
Member

Will need rebasing after #578

@ctreatma
Copy link
Contributor Author

Closing this for now; it can be reopened or reimplemented later if needed.

@ctreatma ctreatma closed this Mar 19, 2024
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.

3 participants