Skip to content

Commit

Permalink
Add --memory, --cpu, --cpu-limit, and --disk options to paasta local-…
Browse files Browse the repository at this point in the history
…run to allow overriding of settings from yelpsoa-configs.
  • Loading branch information
EvanKrall committed Apr 4, 2024
1 parent 1579952 commit b9a187b
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
55 changes: 55 additions & 0 deletions paasta_tools/cli/cmds/local_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
from paasta_tools.utils import NoDockerImageError
from paasta_tools.utils import PaastaColors
from paasta_tools.utils import PaastaNotConfiguredError
from paasta_tools.utils import PATH_TO_SYSTEM_PAASTA_CONFIG_DIR
from paasta_tools.utils import SystemPaastaConfig
from paasta_tools.utils import Timeout
from paasta_tools.utils import TimeoutError
Expand Down Expand Up @@ -386,6 +387,51 @@ def add_subparser(subparsers):
required=False,
default=None,
)
list_parser.add_argument(
"--memory",
"--mem",
help=(
"Specify a memory limit (in megabytes) for the container."
" If not specified, the memory limit is pulled from yelpsoa-configs for your --instance/--cluster."
),
required=False,
default=None,
type=float,
)
list_parser.add_argument(
"--cpus",
help=(
"Specify a CPU limit (in cores) for the container."
" If not specified, the cpu limit is pulled from yelpsoa-configs for your --instance/--cluster."
" cpu_burst_add/--cpu-burst-add is added to this limit, to match the behavior of real clusters."
),
required=False,
default=None,
type=float,
)
list_parser.add_argument(
"--cpu-burst-add",
help=(
"Override cpu_burst_add for the container."
" If not specified, cpu_burst_add is pulled from yelpsoa-configs for your --instance/--cluster."
" This value is added to your cpus/--cpus limit to determine the CPU limit for the container."
),
required=False,
default=None,
type=float,
)
list_parser.add_argument(
"--disk",
help=(
"Override disk limit for the container."
" If not specified, the disk limit is pulled from yelpsoa-configs for your --instance/--cluster."
f" (Disk limits are only enforced if enforce_disk_quota is set in {PATH_TO_SYSTEM_PAASTA_CONFIG_DIR})"
),
required=False,
default=None,
type=float,
)

list_parser.add_argument(
"-i",
"--instance",
Expand Down Expand Up @@ -1174,6 +1220,15 @@ def configure_and_run_docker_container(
)
return 1

if args.memory:
instance_config.config_dict["mem"] = args.memory
if args.cpus:
instance_config.config_dict["cpus"] = args.cpus
if args.cpu_burst_add:
instance_config.config_dict["cpu_burst_add"] = args.cpu_burst_add
if args.disk:
instance_config.config_dict["disk"] = args.disk

if docker_sha is not None:
instance_config.branch_dict = {
"git_sha": docker_sha,
Expand Down
2 changes: 2 additions & 0 deletions tests/cli/test_cmds_local_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,7 @@ def test_configure_and_run_pulls_image_when_asked(
fake_instance_config.get_docker_registry.return_value = "fake_registry"
fake_instance_config.get_docker_image.return_value = "fake_image"
fake_instance_config.get_docker_url.return_value = "fake_registry/fake_image"
fake_instance_config.config_dict = {}
mock_get_instance_config.return_value = fake_instance_config
fake_service = "fake_service"
args = mock.MagicMock()
Expand Down Expand Up @@ -633,6 +634,7 @@ def test_configure_and_run_docker_container_defaults_to_interactive_instance(
args.use_okta_role = False

mock_config = mock.create_autospec(AdhocJobConfig)
mock_config.config_dict = {}
mock_get_default_interactive_config.return_value = mock_config
return_code = configure_and_run_docker_container(
docker_client=mock_docker_client,
Expand Down

0 comments on commit b9a187b

Please sign in to comment.