<#3189 Reuse get SSH connection method in Slurm fu...
# flyte-github
c
#3189 Reuse get SSH connection method in Slurm function agent Pull request opened by JiangJiaWei1103 ## Tracking issue flyteorg/flyte#5634 ## Why are the changes needed? Reusing a shared method for obtaining an SSH connection object prevents code duplication and ensures consistency between
SlurmShellAgent
and
SlurmFunctionAgent
. ## What changes were proposed in this pull request? Reuse
get_ssh_conn
method in
SlurmFunctionAgent
. ## How was this patch tested? This patch is tested by running the following example: import os from flytekit import task, workflow from flytekitplugins.slurm import SlurmFunction @task( task_config=SlurmFunction( ssh_config={ "host": "aws2", "username": "ubuntu", }, sbatch_conf={ "partition": "debug", "job-name": "job3", "output": "/home/ubuntu/fn_task.log" }, script="""#!/bin/bash -i echo [TEST SLURM FN TASK 1] Run the first user-defined task function... # Setup env vars export MY_ENV_VAR=123 # Source the virtual env . /home/ubuntu/.cache/pypoetry/virtualenvs/demo-4A8TrTN7-py3.12/bin/activate # Run the user-defined task function {task.fn} """ ) ) def plus_one(x: int) -> int: print(os.getenv("MY_ENV_VAR")) return x + 1 @task( task_config=SlurmFunction( ssh_config={ "host": "aws2", "username": "ubuntu", }, script="""#!/bin/bash -i echo [TEST SLURM FN TASK 2] Run the second user-defined task function... . /home/ubuntu/.cache/pypoetry/virtualenvs/demo-4A8TrTN7-py3.12/bin/activate {task.fn} """ ) ) def greet(year: int) -> str: return f"Hello {year}!!!" @workflow def wf(x: int) -> str: x = plus_one(x=x) msg = greet(year=x) return msg if name == "__main__": from flytekit.clis.sdk_in_container import pyflyte from click.testing import CliRunner runner = CliRunner() path = os.path.realpath(file) print(f">>> LOCAL EXEC <<<") result = runner.invoke(pyflyte.main, ["run", "--raw-output-data-prefix", "s3://my-flyte-slurm-agent", path, "wf", "--x", 2024]) print(result.output) ### Setup process For agent local test, the setup process is summarized as follows:
Copy code
git clone https://github.com/flyteorg/flytekit.git
gh pr checkout 3189
make setup && pip install -e .
cd plugins/flytekit-slurm && pip install -e .
### Screenshots • Local machine (Flyte client) [Screenshot 2025-03-13 at 9 37 36 PM](https://private-user-images.githubusercontent.com/36886416/422365985-ccd86e19-adab-4460-a3d3-6f6e2ecebaec.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NDI0ODM4MzUsIm5iZiI6MTc0MjQ4MzUzNSwicGF0aCI6Ii8zNjg4NjQxNi80MjIzNjU5ODUtY2NkODZlMTktYWRhYi00NDYwLWEzZDMtNmY2ZTJlY2ViYWVjLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAzMjAlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMzIwVDE1MTIxNVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWFlMGQwOTc0YTE1YTAzOGJmMmI5MjhjMjUwYzkzNzQzODMwYWJjYzg4YzljYTlmZWI0NDUxMTFlMTFhZDkwZDQmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.XKRHdSTwPCWhTDWYommdvHLR3qVZhrClkvXbmpURRCc) • The first task on the Slurm cluster [Screenshot 2025-03-13 at 9 38 16 PM](https://private-user-images.githubusercontent.com/36886416/422366256-34c98013-ccd4-436c-a77d-a14a2ab727bc.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NDI0ODM4MzUsIm5iZiI6MTc0MjQ4MzUzNSwicGF0aCI6Ii8zNjg4NjQxNi80MjIzNjYyNTYtMzRjOTgwMTMtY2NkNC00MzZjLWE3N2QtYTE0YTJhYjcyN2JjLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAzMjAlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMzIwVDE1MTIxNVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTg1NDM3YmI1OWNhODQ4Mjg0MWRlMzVlMjU5NzI2MjczZWM2ZmU3Nzc3NjcyZWUwZjlmNjQ4ODhhYWM5NDIwOGImWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.q9OJ91Fno3NtF5bWANPsfKM3bzPscsyO5lk0jPJ368o) • The second task on the Slurm cluster [Screenshot 2025-03-13 at 9 39 23 PM](https://private-user-images.githubusercontent.com/36886416/422366716-43ac8253-d176-4dfb-8707-c10cebaceb52.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NDI0ODM4MzUsIm5iZiI6MTc0MjQ4MzUzNSwicGF0aCI6Ii8zNjg4NjQxNi80MjIzNjY3MTYtNDNhYzgyNTMtZDE3Ni00ZGZiLTg3MDctYzEwY2ViYWNlYjUyLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAzMjAlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMzIwVDE1MTIxNVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTU1NTE3ODViY2U3ZmZiZGZjYjM4MDMwYjY4ODdkOThlNDVhYmQ0MjM0YzAxMDRmMTQ3MWUwM2E5MjhiZWU2YTgmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.Mnp-SIK4y1uGZtgxgtq8GX_Y5M0JQYjrDGOEfqZiaAo) ## Check all the applicable boxes • I updated the documentation accordingly. • All new and existing tests passed. • All commits are signed-off. ## Related PRs • #3150 • #3159 ## Docs link N/A ### Summary by Bito This PR refactors the codebase from an agent-based to a connector-based architecture, focusing on SSH connection handling in the Slurm function agent by leveraging shared methods. It eliminates custom connection logic and redundant classes, improves error handling, enhances modularity, and introduces a geopandas plugin for GeoDataFra… flyteorg/flytekit