<#3229 Add ability to specify default resource req...
# flyte-github
c
#3229 Add ability to specify default resource requests/limits for tasks via
pyflyte run
and
pyflyte register
Pull request opened by redartera ## Why are the changes needed? When registering tasks with Flyte, users often need flexibility to specify resource requirements at registration time without modifying code. This is particularly useful in scenarios where: 1. Users want to test workflows with varied resource configurations 2. Teams need to quickly adjust resources for existing tasks without code changes during rapid development phases. Currently, the only options are to specify resources explicitly in task definitions or rely on cluster-level defaults, which lacks flexibility for selective overrides. ## What changes were proposed in this pull request? This PR introduces the ability to specify default resource requests and limits for tasks that don't have resources explicitly defined. The implementation: 1. Adds a
default_resources
parameter to
SerializationSettings
that, if set, applies to tasks with unspecified resources 2. Implements CLI options
--resource-requests
and
--resource-limits
for both
pyflyte run
and
pyflyte register
commands 3. Adds a resource specification parser (
resource_callback
) that handles comma-separated key-value pairs 4. Ensures tasks with explicitly defined resources are not overridden 5. Updates the serialization pipeline to apply default resources during task registration Example CLI usage: # Specify resource requests only pyflyte run --remote --resource-requests 'cpu=1,mem=2Gi,gpu=1' workflow.py my_workflow # Specify both requests and limits pyflyte register --resource-requests 'cpu=500m,mem=1Gi' --resource-limits 'cpu=1,mem=2Gi' package # Register with resource overrides pyflyte register --resource-requests 'cpu=1300m,mem=1100Mi' --image myimage --project myproject --domain development workflow.py ## How was this patch tested? Added comprehensive unit and integration tests: 1. Tests for the resource specification parser in
tests/flytekit/unit/interaction/test_click_types.py
2. Integration tests in
tests/flytekit/integration/remote/test_remote.py
for both: •
pyflyte register
with resource overrides •
pyflyte run --remote
with resource overrides 3. Tests verify that the registered tasks have the correct resource specifications applied 4. Tests ensure proper error handling for invalid resource specifications (wrong separators, invalid keys, duplicate keys) The integration tests verify end-to-end functionality by: • Registering workflows with resource overrides • Fetching the created tasks from the remote • Validating that the task templates contain the expected resource specifications ## Check all the applicable boxes • I updated the documentation accordingly. • All new and existing tests passed. • All commits are signed-off. https://bito.ai#summarystart| ### Summary by Bito This pull request enhances the Flyte framework by allowing users to specify default resource requests and limits for tasks during registration and execution. It introduces new CLI options for
pyflyte run
and
pyflyte register
, along with improved help text for clarity. Comprehensive tests ensure the new functionality operates correctly and handles errors effectively. flyteorg/flytekit