Skip to content
This repository has been archived by the owner on Jun 29, 2022. It is now read-only.

packet: improve hardware reservations support using terraform dependencies #299

Merged
merged 5 commits into from
Apr 24, 2020

Conversation

rata
Copy link
Member

@rata rata commented Apr 16, 2020

This PR supersedes #119 and adds support for hardware reservations in Packet by adding auto-generated (i.e generated automatically by lokomotive) explicit terraform dependencies.

The need to use explicit dependencies on terraform (depends_on) is explained in the code itself, but you can have a look at these two links for more info (also linked in the code):
https://github.com/terraform-providers/terraform-provider-packet/issues/176
https://github.com/terraform-providers/terraform-provider-packet/pull/208

To guarantee that nodes with specific hw reservation UUID are created first, terraform dependencies are used and computed automatically in lokomotive. In contrast, PR #119 to achieve the same, did the following: terraform apply -target=<nodes_to_create_first> and then finished with terraform apply to create the rest of the resources.

The reasoning to change and rely on terraform for dependencies is simple: terraform already handles dependencies, handling them in different places is confusing and may hit several unexpected issues (as if running terraform apply -target=<nodes_to_create_first> we don't expect some resources to be created, but due to dependencies at the terraform layer they might be created if needed).

As explained in #119, I first started with the terraform -target approach because it was already used for DNS provider manual in packet, seemed simple and supporting all possible combinations of reservation_ids and reservation_ids_default seemed difficult otherwise. While working on #119, I decided that to support all combinations was not sane, and little by little, started to reduce the different combinations accepted. Basically, it was reduced and now reservation_ids and reservation_ids_default are mutually exclusive now. With that simplification in mind, going the terraform dependencies route seems simple. This PR just goes down that route, with this simplification.

There are some TODOs in the code, for things that I want to fully understand before merging, but other than that, this is pretty much functional.

Pending things:

  • Add tests to new functions in this iteration and review other tests, just in case
  • Address "TODO" currently in the code
  • Create issue about plumbing to test terraform code (e.g. dependencies between devices, like we added here). Or should this be included here?

@rata rata requested review from johananl and surajssd as code owners April 16, 2020 20:32
@rata rata requested a review from invidian April 16, 2020 20:32
@rata rata force-pushed the rata/packet-improve-reservations-tf-dep branch 2 times, most recently from ae57e78 to 59d9d4a Compare April 16, 2020 20:38
pkg/platform/packet/packet.go Outdated Show resolved Hide resolved
pkg/platform/packet/packet.go Outdated Show resolved Hide resolved
pkg/platform/packet/packet.go Outdated Show resolved Hide resolved
pkg/platform/packet/packet.go Outdated Show resolved Hide resolved
pkg/platform/packet/packet.go Show resolved Hide resolved
@rata rata force-pushed the rata/packet-improve-reservations-tf-dep branch from 59d9d4a to a34c7a5 Compare April 20, 2020 20:39
Copy link
Member

@invidian invidian left a comment

Choose a reason for hiding this comment

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

Just some nits and typos, otherwise LGTM!

pkg/platform/packet/packet.go Outdated Show resolved Hide resolved
pkg/platform/packet/packet.go Outdated Show resolved Hide resolved
pkg/platform/packet/packet.go Outdated Show resolved Hide resolved
pkg/platform/packet/packet.go Outdated Show resolved Hide resolved
pkg/platform/packet/packet.go Outdated Show resolved Hide resolved
pkg/platform/packet/packet.go Outdated Show resolved Hide resolved
pkg/platform/packet/packet.go Outdated Show resolved Hide resolved
pkg/platform/packet/packet.go Outdated Show resolved Hide resolved
pkg/platform/packet/packet.go Outdated Show resolved Hide resolved
@rata rata force-pushed the rata/packet-improve-reservations-tf-dep branch 2 times, most recently from 9a8654f to 7492157 Compare April 21, 2020 21:00
@rata rata force-pushed the rata/packet-improve-reservations-tf-dep branch 2 times, most recently from 61a67d4 to 6d94907 Compare April 23, 2020 15:57
rata added 5 commits April 23, 2020 18:20
It makes the error clearer, as the pool name is quoted by go now.
This commit adds support for reserved instances, which are already
supported in terraform.

This patch also fixes a long standing bug where the worker pools use
reservations IDs from the controller nodes, instead of workers nodes.
Basically, it was totally broken. This was overseen when creating
template, and the lack of tests for generated templates didn't help.

Fixes: #20
This commit adds tests for the just added functions but also for
existing check*() functions.

Logic in these functions is getting complicated, so tests are added
before it's complex (or even impossible if not split correctly) to do
so.
@rata rata force-pushed the rata/packet-improve-reservations-tf-dep branch from 6d94907 to b62b5be Compare April 23, 2020 21:20
@rata rata requested a review from invidian April 23, 2020 21:20
@rata
Copy link
Member Author

rata commented Apr 23, 2020

This is ready for review again, @invidian. PTAL :)

When it is ready to merge, I will create the issue mentioned in the PR description (the missing item in the TODO list)

@rata
Copy link
Member Author

rata commented Apr 24, 2020

@invidian thanks for review and the patience while I tried different approaches! I think, however, time was well invested and the end result is quite better =)

@rata rata merged commit 3deb576 into master Apr 24, 2020
@rata rata deleted the rata/packet-improve-reservations-tf-dep branch April 24, 2020 13:07
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants