Skip to content

Conversation

fornfrey
Copy link
Contributor

@fornfrey fornfrey commented Jun 3, 2025

  • Convert k6 resource IDs from int32 to string to work correctly in the crossplane provider when generated with upjet.
  • Upgrade resource schema versions and implement the UpgradeState methods to migrate the existing states. This makes the change backward compatible.
  • Add a check for empty ID in the Read methods to prevent errors when called from crossplane Observe() method for the first time before the resource is created.
  • Add tests to verify empty plans when upgrading to the new schemas.

Copy link
Contributor

github-actions bot commented Jun 3, 2025

In order to lower resource usage and have a faster runtime, PRs will not run Cloud tests automatically.
To do so, a Grafana Labs employee must trigger the cloud acceptance tests workflow manually.

@fornfrey fornfrey force-pushed the k6-string-ids branch 7 times, most recently from 2f400f3 to d1a01f7 Compare June 5, 2025 14:08
@fornfrey fornfrey marked this pull request as ready for review June 6, 2025 10:47
@fornfrey fornfrey requested review from a team as code owners June 6, 2025 10:47
@fornfrey fornfrey requested review from the-it, Blinkuu and yorugac and removed request for a team June 6, 2025 10:47
Copy link

@yorugac yorugac left a comment

Choose a reason for hiding this comment

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

@fornfrey, thanks for this 🙌
I don't see anything obviously off (within my limited knowledge of this code base), except for Read method in project limits resource: please see my comment.

Comment on lines +44 to 46
type loadTestResourceModelV0 struct {
ID types.Int32 `tfsdk:"id"`
ProjectID types.Int32 `tfsdk:"project_id"`
Copy link

Choose a reason for hiding this comment

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

2 models are basically needed for backwards compatibility, correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@@ -151,15 +228,25 @@ func (r *projectLimitsResource) Read(ctx context.Context, req resource.ReadReque
// Set the ID to match the project_id
state.ID = state.ProjectID

intID, err := strconv.ParseInt(state.ID.ValueString(), 10, 32)
Copy link

Choose a reason for hiding this comment

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

There is no "crossplane check" for ID being empty in this resource, it seems. Why?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

project_limits does not have its own ID. Instead, we use the supplied ProjectID, which is expected to be set by the practitioner explicitly in the resource.

Copy link

Choose a reason for hiding this comment

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

🤔 so it's a characteristic of the API; I didn't realize that. OK then, thanks for clarifying.

@fornfrey fornfrey requested a review from yorugac June 6, 2025 12:07
@fornfrey fornfrey requested a review from joanlopez June 10, 2025 09:59
@joanlopez
Copy link
Contributor

joanlopez commented Jun 10, 2025

Is there any chance to test these changes with Crossplane before merging and releasing it (maybe locally, pointing to the "dev" provider)? 🤔

Regarding existing states, I guess the upgrader solution should be fine - thanks for adding the according tests 👌🏻 🙇🏻

@yorugac
Copy link

yorugac commented Jun 10, 2025

@joanlopez, AFAIS it's possible to test Crossplane provider's runtime with the branch (commit hash) of the Terraform provider. But generation of Crossplane provider requires a Terraform release.

Looking here, I think it might be possible to also test Crossplane provider's generation with the local "binary" of the Terraform provider but it must be built first, from the branch. Is it possible to quickly build that binary? I'll be happy to try that, if there's a known command for that. (just in case though, there's no guarantee that it'd work...)

@yorugac
Copy link

yorugac commented Jun 10, 2025

But generation of Crossplane provider requires a Terraform release.

Just to clarify: since we're changing types of fields in this PR, so changing structure of the objects, Crossplane's generation is also needed for a full test.

@fornfrey
Copy link
Contributor Author

fornfrey commented Jun 10, 2025

@Yoruga the binary can be built with just go build, and terraform can be configured to use it as a dev override as described here https://github.com/grafana/terraform-provider-grafana/blob/main/README.md#local-development-with-grafana

@yorugac
Copy link

yorugac commented Jun 10, 2025

OK, running go build is simple enough to create a binary 😄 Thanks @fornfrey!

So simple testing with Crossplane provider was done; some notable observations:

  1. CRUD for project is working in a rather straight-forward manner.
  2. loadtest is creating a test but not running it.
  3. loadtest can be modified and subsequent test runs are picking the change up 👍 Though as we already know, some would want to pass an archive there instead of the script.
  4. When loadtest is deleted, all the test runs associated with it are deleted.
  5. projectlimits is changing existing values when created or edited.
  6. When projectlimits is deleted, the values don't return to the default ones but remain as the last ones configured.
  7. AFAIS, projectlimits was calling PATCH even on creation and deletion, which matches up with observations from point 5 and 6.

I hope all of the above are expected at the moment.

I'll run some more tests. And there is one more thing I'd like to look into for crossplane-provider (the way to reference projects without an ID) but that one shouldn't require changes in Terraform provider. So preliminary I believe this PR did the main fix: generated Crossplane objects can be created and manipulated at a basic level 🙌

@fornfrey
Copy link
Contributor Author

@yorugac Thank you for testing this! All your observations are the expected behavior of the API.
Considering we fixed the main problem and no other issues were found, I'll merge the PR.

@fornfrey fornfrey merged commit 3385c87 into main Jun 11, 2025
30 checks passed
@fornfrey fornfrey deleted the k6-string-ids branch June 11, 2025 09:34
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