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

Update Run Tasks for global config and stages #865

Merged
merged 4 commits into from
Apr 8, 2024

Conversation

glennsarti
Copy link
Contributor

@glennsarti glennsarti commented Mar 5, 2024

This PR needs the Global Run Tasks feature to be generally available, and deployed to the CI environment before CI will pass


Description

This commit also extracts the subscription update process and updated it as it
fails in the local development. Specifically, there may be 2 or more tokens
used to administer a TFC instance which have different admin scopes. This commit
now encapsulates that logic inside a SubscriptionUpdater "service" class which
can be used to build up the request to update a subscription.

This commit updates the entitlement set object to include the new
global-run-tasks feature.

The global run tasks feature updates both the Organization and Workspace
Run tasks with new attributes. Unfortunately these new attributes exposed
an issue with the JSON API pacakge, that it doesn't support complex objects
(Custom maps or non-standard types) [1]. Instead we need to unmarshall to
a more simpler object and then we adapt the simpler object to our more
correct struct.

[1] google/jsonapi#74

Testing plan

Updated integration tests exercise this behaviour.

External links

Output from tests

Including output from tests may require access to a TFE instance. Ignore this section if you have no environment to test against.

go test -v ./... --tags=integration --count=1 --run TestWorkspaceRunTasks
...
=== RUN   TestWorkspaceRunTasksCreate
=== RUN   TestWorkspaceRunTasksCreate/attach_run_task_to_workspace
=== RUN   TestWorkspaceRunTasksCreate/attach_run_task_to_workspace/ensure_run_task_is_deserialized_properly
--- PASS: TestWorkspaceRunTasksCreate (6.15s)
    --- PASS: TestWorkspaceRunTasksCreate/attach_run_task_to_workspace (0.81s)
        --- PASS: TestWorkspaceRunTasksCreate/attach_run_task_to_workspace/ensure_run_task_is_deserialized_properly (0.00s)
=== RUN   TestWorkspaceRunTasksCreateDeprecated
=== RUN   TestWorkspaceRunTasksCreateDeprecated/attach_run_task_to_workspace
=== RUN   TestWorkspaceRunTasksCreateDeprecated/attach_run_task_to_workspace/ensure_run_task_is_deserialized_properly
--- PASS: TestWorkspaceRunTasksCreateDeprecated (5.63s)
    --- PASS: TestWorkspaceRunTasksCreateDeprecated/attach_run_task_to_workspace (0.78s)
        --- PASS: TestWorkspaceRunTasksCreateDeprecated/attach_run_task_to_workspace/ensure_run_task_is_deserialized_properly (0.00s)
=== RUN   TestWorkspaceRunTasksList
=== RUN   TestWorkspaceRunTasksList/with_no_params
--- PASS: TestWorkspaceRunTasksList (7.93s)
    --- PASS: TestWorkspaceRunTasksList/with_no_params (0.40s)
=== RUN   TestWorkspaceRunTasksRead
=== RUN   TestWorkspaceRunTasksRead/by_ID
=== RUN   TestWorkspaceRunTasksRead/by_ID/ensure_run_task_is_deserialized
=== RUN   TestWorkspaceRunTasksRead/by_ID/ensure_workspace_is_deserialized
--- PASS: TestWorkspaceRunTasksRead (5.93s)
    --- PASS: TestWorkspaceRunTasksRead/by_ID (0.43s)
        --- PASS: TestWorkspaceRunTasksRead/by_ID/ensure_run_task_is_deserialized (0.00s)
        --- PASS: TestWorkspaceRunTasksRead/by_ID/ensure_workspace_is_deserialized (0.00s)
=== RUN   TestWorkspaceRunTasksUpdate
=== RUN   TestWorkspaceRunTasksUpdate/update_task
--- PASS: TestWorkspaceRunTasksUpdate (6.43s)
    --- PASS: TestWorkspaceRunTasksUpdate/update_task (0.73s)
=== RUN   TestWorkspaceRunTasksUpdateDeprecated
=== RUN   TestWorkspaceRunTasksUpdateDeprecated/update_task
--- PASS: TestWorkspaceRunTasksUpdateDeprecated (6.24s)
    --- PASS: TestWorkspaceRunTasksUpdateDeprecated/update_task (0.74s)
=== RUN   TestWorkspaceRunTasksDelete
=== RUN   TestWorkspaceRunTasksDelete/with_valid_options
=== RUN   TestWorkspaceRunTasksDelete/when_the_workspace_run_task_does_not_exist
=== RUN   TestWorkspaceRunTasksDelete/when_the_workspace_does_not_exist
--- PASS: TestWorkspaceRunTasksDelete (6.63s)
    --- PASS: TestWorkspaceRunTasksDelete/with_valid_options (0.71s)
    --- PASS: TestWorkspaceRunTasksDelete/when_the_workspace_run_task_does_not_exist (0.25s)
    --- PASS: TestWorkspaceRunTasksDelete/when_the_workspace_does_not_exist (0.27s)
go test -v ./... --tags=integration --count=1 --run TestRunTasks
...
=== RUN   TestWorkspaceRunTasksCreate
=== RUN   TestWorkspaceRunTasksCreate/attach_run_task_to_workspace
=== RUN   TestWorkspaceRunTasksCreate/attach_run_task_to_workspace/ensure_run_task_is_deserialized_properly
--- PASS: TestWorkspaceRunTasksCreate (5.94s)
    --- PASS: TestWorkspaceRunTasksCreate/attach_run_task_to_workspace (0.79s)
        --- PASS: TestWorkspaceRunTasksCreate/attach_run_task_to_workspace/ensure_run_task_is_deserialized_properly (0.00s)
=== RUN   TestWorkspaceRunTasksCreateDeprecated
=== RUN   TestWorkspaceRunTasksCreateDeprecated/attach_run_task_to_workspace
=== RUN   TestWorkspaceRunTasksCreateDeprecated/attach_run_task_to_workspace/ensure_run_task_is_deserialized_properly
--- PASS: TestWorkspaceRunTasksCreateDeprecated (5.73s)
    --- PASS: TestWorkspaceRunTasksCreateDeprecated/attach_run_task_to_workspace (0.86s)
        --- PASS: TestWorkspaceRunTasksCreateDeprecated/attach_run_task_to_workspace/ensure_run_task_is_deserialized_properly (0.00s)
=== RUN   TestWorkspaceRunTasksList
=== RUN   TestWorkspaceRunTasksList/with_no_params
--- PASS: TestWorkspaceRunTasksList (7.66s)
    --- PASS: TestWorkspaceRunTasksList/with_no_params (0.41s)
=== RUN   TestWorkspaceRunTasksRead
=== RUN   TestWorkspaceRunTasksRead/by_ID
=== RUN   TestWorkspaceRunTasksRead/by_ID/ensure_run_task_is_deserialized
=== RUN   TestWorkspaceRunTasksRead/by_ID/ensure_workspace_is_deserialized
--- PASS: TestWorkspaceRunTasksRead (5.96s)
    --- PASS: TestWorkspaceRunTasksRead/by_ID (0.39s)
        --- PASS: TestWorkspaceRunTasksRead/by_ID/ensure_run_task_is_deserialized (0.00s)
        --- PASS: TestWorkspaceRunTasksRead/by_ID/ensure_workspace_is_deserialized (0.00s)
=== RUN   TestWorkspaceRunTasksUpdate
=== RUN   TestWorkspaceRunTasksUpdate/update_task
--- PASS: TestWorkspaceRunTasksUpdate (6.60s)
    --- PASS: TestWorkspaceRunTasksUpdate/update_task (0.80s)
=== RUN   TestWorkspaceRunTasksUpdateDeprecated
=== RUN   TestWorkspaceRunTasksUpdateDeprecated/update_task
--- PASS: TestWorkspaceRunTasksUpdateDeprecated (6.24s)
    --- PASS: TestWorkspaceRunTasksUpdateDeprecated/update_task (0.74s)
=== RUN   TestWorkspaceRunTasksDelete
=== RUN   TestWorkspaceRunTasksDelete/with_valid_options
=== RUN   TestWorkspaceRunTasksDelete/when_the_workspace_run_task_does_not_exist
=== RUN   TestWorkspaceRunTasksDelete/when_the_workspace_does_not_exist
--- PASS: TestWorkspaceRunTasksDelete (6.46s)
    --- PASS: TestWorkspaceRunTasksDelete/with_valid_options (0.69s)
    --- PASS: TestWorkspaceRunTasksDelete/when_the_workspace_run_task_does_not_exist (0.24s)
    --- PASS: TestWorkspaceRunTasksDelete/when_the_workspace_does_not_exist (0.24s)
PASS

@glennsarti glennsarti self-assigned this Mar 5, 2024
@glennsarti glennsarti force-pushed the gs/add-global-run-tasks branch 5 times, most recently from fdff167 to ae83584 Compare March 8, 2024 02:51
@glennsarti glennsarti force-pushed the gs/add-global-run-tasks branch 4 times, most recently from 7faf9e7 to fe0b2e3 Compare March 20, 2024 06:22
@glennsarti glennsarti changed the title {wip} Global Run Tasks update Update Run Tasks for global config and stages Mar 20, 2024
@glennsarti glennsarti force-pushed the gs/add-global-run-tasks branch 3 times, most recently from d30fe15 to 54ab479 Compare March 27, 2024 00:35
@glennsarti glennsarti marked this pull request as ready for review March 27, 2024 00:53
@glennsarti glennsarti requested a review from a team as a code owner March 27, 2024 00:53
@glennsarti glennsarti requested a review from a team March 27, 2024 01:50
@glennsarti
Copy link
Contributor Author

Add Compliance team for review. Not that it's required, but a nice to have

@glennsarti glennsarti force-pushed the gs/add-global-run-tasks branch 3 times, most recently from 23e371d to 3e5eee6 Compare April 3, 2024 02:19
run_task.go Show resolved Hide resolved
}
// DEPRECATED : Please use the newSubscriptionUpdater instead.
func upgradeOrganizationSubscription(t *testing.T, _ *Client, organization *Organization) {
newSubscriptionUpdater(organization).WithBusinessPlan().Update(t)
Copy link
Contributor

Choose a reason for hiding this comment

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

nice!! 👍

mrinalirao
mrinalirao previously approved these changes Apr 3, 2024
Copy link
Contributor

@mrinalirao mrinalirao left a comment

Choose a reason for hiding this comment

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

A minor comment fix. LGTM otherwise! 👍

This commit also extracts the subscription update process and updated it as it
fails in the local development. Specifically, there may be 2 or more tokens
used to administer a TFC instance which have different admin scopes. This commit
now encapsulates that logic inside a SubscriptionUpdater "service" class which
can be used to build up the request to update a subscription.
This commit updates the entitlement set object to include the new
global-run-tasks feature.
The global run tasks feature updates both the Organization and Workspace
Run tasks with new attributes. Unfortunately these new attributes exposed
an issue with the JSON API pacakge, that it doesn't support complex objects
(Custom maps or non-standard types) [1]. Instead we need to unmarshall to
a more simpler object and then we adapt the simpler object to our more
correct struct.

[1] google/jsonapi#74
Copy link
Collaborator

@brandonc brandonc left a comment

Choose a reason for hiding this comment

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

Very nicely done to expose the interface you want and hide the problematic object case. I also appreciate the subscription update cleanup

Category string `jsonapi:"attr,category"`
HMACKey *string `jsonapi:"attr,hmac-key,omitempty"`
Enabled bool `jsonapi:"attr,enabled"`
RawGlobal map[string]interface{} `jsonapi:"attr,global-configuration,omitempty"`
Copy link
Collaborator

Choose a reason for hiding this comment

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

TIL that jsonapi doesn't automatically decode json annotated attribute object types. It's certainly in spec to have an object within an attribute. I will take a closer look after I finish this review.

Copy link
Contributor Author

@glennsarti glennsarti Apr 7, 2024

Choose a reason for hiding this comment

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

Unfortunately, jsonapi is effectively a dead project :-( It had a "No Maintenance Intended" badge added 4 years ago and the PR/Issues list is wasteland. We'd have to fork it if we wanted to fix any issues with it.

DERP ME ... we are using a fork

@glennsarti glennsarti merged commit 5e21f37 into main Apr 8, 2024
10 checks passed
@glennsarti glennsarti deleted the gs/add-global-run-tasks branch April 8, 2024 00:33
Copy link

github-actions bot commented Apr 8, 2024

Reminder to the contributor that merged this PR: if your changes have added important functionality or fixed a relevant bug, open a follow-up PR to update CHANGELOG.md with a note on your changes.

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