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

[K8s][Ray Operator] Ignore resource requests when detected container resources. #26234

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions python/ray/autoscaler/_private/_kubernetes/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,9 @@ def get_autodetected_resources(container_data):


def get_resource(container_resources, resource_name):
request = _get_resource(container_resources, resource_name, field_name="requests")
limit = _get_resource(container_resources, resource_name, field_name="limits")
resource = min(request, limit)
# float("inf") value means the resource wasn't detected in either
# requests or limits
return 0 if resource == float("inf") else int(resource)
# float("inf") means there's no limit set
return 0 if limit == float("inf") else int(limit)


def _get_resource(container_resources, resource_name, field_name):
Expand Down
20 changes: 20 additions & 0 deletions python/ray/tests/test_autoscaler_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import mock
from ray._private.test_utils import load_test_config, recursive_fnmatch
from ray._private import ray_constants
from ray.autoscaler._private._azure.config import (
_configure_key_pair as _azure_configure_key_pair,
)
Expand All @@ -28,6 +29,7 @@
validate_config,
)
from ray.autoscaler.tags import NODE_TYPE_LEGACY_HEAD, NODE_TYPE_LEGACY_WORKER
from ray.autoscaler._private._kubernetes.config import get_autodetected_resources

RAY_PATH = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
CONFIG_PATHS = recursive_fnmatch(os.path.join(RAY_PATH, "autoscaler"), "*.yaml")
Expand Down Expand Up @@ -720,6 +722,24 @@ def testFaultyResourceValidation(self):
with pytest.raises(jsonschema.exceptions.ValidationError):
validate_config(config)

@pytest.mark.skipif(sys.platform.startswith("win"), reason="Fails on Windows.")
def test_k8s_get_autodetected_resources(self):
"""Verify container requests are ignored when detected resource limits for the
Ray Operator.
"""
sample_container = {
"resources": {
"limits": {"memory": "1G", "cpu": "2"},
"requests": {"memory": "512M", "cpu": "2"},
}
}
out = get_autodetected_resources(sample_container)
expected_memory = int(
2 ** 30 * (1 - ray_constants.DEFAULT_OBJECT_STORE_MEMORY_PROPORTION)
)
expected_out = {"CPU": 2, "memory": expected_memory, "GPU": 0}
assert out == expected_out


if __name__ == "__main__":
import sys
Expand Down