-
Notifications
You must be signed in to change notification settings - Fork 217
test: provision Cloud namespace per CI run #1731
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
Merged
+150
−7
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
974e1f0
test: provision Cloud namespace per CI run
tconley1428 dabe97c
fix: use current Cloud API for namespace lifecycle
tconley1428 bd2ef22
fix: use latest Cloud API version in CI
tconley1428 6602c92
test: skip Cloud-incompatible feature tests
tconley1428 bab665e
Merge branch 'main' into test/cloud-ci-namespaces
tconley1428 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| """Create and delete an isolated Temporal Cloud namespace for CI.""" | ||
|
|
||
| import asyncio | ||
| import os | ||
| import sys | ||
| import time | ||
| from pathlib import Path | ||
|
|
||
| from temporalio.api.cloud.cloudservice.v1 import ( | ||
| CreateNamespaceRequest, | ||
| DeleteNamespaceRequest, | ||
| GetAsyncOperationRequest, | ||
| GetNamespaceRequest, | ||
| ) | ||
| from temporalio.api.cloud.namespace.v1 import MtlsAuthSpec, NamespaceSpec | ||
| from temporalio.api.cloud.operation.v1 import AsyncOperation | ||
| from temporalio.client import CloudOperationsClient | ||
|
|
||
|
|
||
| async def wait_for_operation( | ||
| client: CloudOperationsClient, operation: AsyncOperation | ||
| ) -> None: | ||
| deadline = time.monotonic() + 10 * 60 | ||
| while True: | ||
| operation = ( | ||
| await client.cloud_service.get_async_operation( | ||
| GetAsyncOperationRequest(async_operation_id=operation.id) | ||
| ) | ||
| ).async_operation | ||
| if operation.state == AsyncOperation.STATE_FULFILLED: | ||
| return | ||
| if operation.state in { | ||
| AsyncOperation.STATE_FAILED, | ||
| AsyncOperation.STATE_CANCELLED, | ||
| AsyncOperation.STATE_REJECTED, | ||
| }: | ||
| raise RuntimeError( | ||
| "Cloud operation " | ||
| f"{operation.id} {AsyncOperation.State.Name(operation.state).lower()}: " | ||
| f"{operation.failure_reason}" | ||
| ) | ||
| if time.monotonic() >= deadline: | ||
| raise TimeoutError(f"Timed out waiting for Cloud operation {operation.id}") | ||
| delay = max( | ||
| operation.check_duration.seconds | ||
| + operation.check_duration.nanos / 1_000_000_000, | ||
| 1, | ||
| ) | ||
| await asyncio.sleep(min(delay, deadline - time.monotonic())) | ||
|
tconley1428 marked this conversation as resolved.
|
||
|
|
||
|
|
||
| async def create() -> None: | ||
| client = await cloud_client() | ||
| namespace_name = "sdk-python-ci-{}-{}".format( | ||
| os.environ["GITHUB_RUN_ID"], os.environ["GITHUB_RUN_ATTEMPT"] | ||
| ) | ||
| result = await client.cloud_service.create_namespace( | ||
| CreateNamespaceRequest( | ||
| spec=NamespaceSpec( | ||
| name=namespace_name, | ||
| regions=["aws-ca-central-1"], | ||
| retention_days=1, | ||
| mtls_auth=MtlsAuthSpec( | ||
| accepted_client_ca=Path( | ||
| os.environ["TEMPORAL_CLOUD_CLIENT_CA_PATH"] | ||
| ).read_bytes(), | ||
| enabled=True, | ||
| ), | ||
| ) | ||
| ) | ||
| ) | ||
| # Make cleanup possible even if provisioning fails after Cloud accepts the request. | ||
| with open(os.environ["GITHUB_OUTPUT"], "a") as output: | ||
| output.write(f"namespace={result.namespace}\n") | ||
| await wait_for_operation(client, result.async_operation) | ||
|
|
||
|
|
||
| async def delete(namespace: str) -> None: | ||
| client = await cloud_client() | ||
| existing = await client.cloud_service.get_namespace( | ||
| GetNamespaceRequest(namespace=namespace) | ||
| ) | ||
| result = await client.cloud_service.delete_namespace( | ||
| DeleteNamespaceRequest( | ||
| namespace=namespace, | ||
| resource_version=existing.namespace.resource_version, | ||
| ) | ||
| ) | ||
| await wait_for_operation(client, result.async_operation) | ||
|
|
||
|
|
||
| async def cloud_client() -> CloudOperationsClient: | ||
| return await CloudOperationsClient.connect( | ||
| api_key=os.environ["TEMPORAL_CLIENT_CLOUD_API_KEY"], | ||
| version=os.environ["TEMPORAL_CLIENT_CLOUD_API_VERSION"], | ||
| ) | ||
|
|
||
|
|
||
| async def main() -> None: | ||
| match sys.argv[1:]: | ||
| case ["create"]: | ||
| await create() | ||
| case ["delete", namespace]: | ||
| await delete(namespace) | ||
| case _: | ||
| raise ValueError("Usage: cloud_namespace.py create|delete <namespace>") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| asyncio.run(main()) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.