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

Add KuberenetesWorker.submit for ad-hoc submission to a Kubernetes work pool #17218

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

desertaxle
Copy link
Member

@desertaxle desertaxle commented Feb 20, 2025

This PR adds an experimental .submit method to the KubernetesWorker class to allow a flow to be submitted to a Kubernetes cluster. The updates to the work pool API haven't been made yet, so the steps for bundle upload and execution are loaded via an environment variable.

Here's an example:

import asyncio
import json
import os

from prefect_kubernetes import KubernetesWorker

from prefect import flow

UPLOAD_STEP = {
    "prefect_aws.experimental.bundles.upload": {
        "requires": "prefect-aws==0.5.5",
        "bucket": "storage-blocks-test-bucket",
        "aws_credentials_block_name": "my-creds",
    }
}

EXECUTE_STEP = {
    "prefect_aws.experimental.bundles.execute": {
        "requires": "prefect-aws==0.5.5",
        "bucket": "storage-blocks-test-bucket",
        "aws_credentials_block_name": "my-creds",
    }
}


@flow(log_prints=True, result_storage="s3-bucket/results-bucket")
def my_flow():
    print("Returning greeting...")
    return "Hello, world!"


async def main():
    async with KubernetesWorker(work_pool_name="olympic") as worker:
        future = await worker.submit(flow=my_flow)

    print(future.result()) # prints "Hello, world!"


if __name__ == "__main__":
    os.environ["PREFECT__BUNDLE_UPLOAD_STEP"] = json.dumps(UPLOAD_STEP)
    os.environ["PREFECT__BUNDLE_EXECUTE_STEP"] = json.dumps(EXECUTE_STEP)
    asyncio.run(main())

Related to #17194

Copy link

codspeed-hq bot commented Feb 20, 2025

CodSpeed Performance Report

Merging #17218 will not alter performance

Comparing k8s-worker-submit (d01c250) with main (fdc2b8a)

Summary

✅ 2 untouched benchmarks

@desertaxle desertaxle changed the base branch from main to flow-run-watcher February 21, 2025 19:23
Base automatically changed from flow-run-watcher to main February 21, 2025 21:16
@desertaxle desertaxle marked this pull request as ready for review February 21, 2025 21:57
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.

1 participant