Skip to content

Commit 430552b

Browse files
authored
Kubernetes: request resources according to RequirementsSpec (#3127)
Other fixes and improvements: * Handle errors in `_create_jump_pod_service_if_not_exists` * Check both Service and Pod to decide if the jump pod must be (re)created * Respect `Node.status.nodeinfo.architecture` * Add `namespace` option to the backend config Part-of: #3126
1 parent d622241 commit 430552b

File tree

11 files changed

+643
-247
lines changed

11 files changed

+643
-247
lines changed

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,9 @@ include = [
8383
"src/dstack/plugins",
8484
"src/dstack/_internal/server",
8585
"src/dstack/_internal/core/services",
86-
"src/dstack/_internal/cli/commands",
86+
"src/dstack/_internal/core/backends/kubernetes",
8787
"src/dstack/_internal/cli/services/configurators",
88+
"src/dstack/_internal/cli/commands",
8889
]
8990
ignore = [
9091
"src/dstack/_internal/server/migrations/versions",

src/dstack/_internal/core/backends/base/compute.py

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@
55
import threading
66
from abc import ABC, abstractmethod
77
from collections.abc import Iterable
8+
from enum import Enum
89
from functools import lru_cache
910
from pathlib import Path
10-
from typing import Callable, Dict, List, Literal, Optional
11+
from typing import Callable, Dict, List, Optional
1112

1213
import git
1314
import requests
1415
import yaml
1516
from cachetools import TTLCache, cachedmethod
17+
from gpuhunt import CPUArchitecture
1618

1719
from dstack._internal import settings
1820
from dstack._internal.core.backends.base.offers import filter_offers_by_requirements
@@ -65,7 +67,21 @@
6567
]
6668
)
6769

68-
GoArchType = Literal["amd64", "arm64"]
70+
71+
class GoArchType(str, Enum):
72+
"""
73+
A subset of GOARCH values
74+
"""
75+
76+
AMD64 = "amd64"
77+
ARM64 = "arm64"
78+
79+
def to_cpu_architecture(self) -> CPUArchitecture:
80+
if self == self.AMD64:
81+
return CPUArchitecture.X86
82+
if self == self.ARM64:
83+
return CPUArchitecture.ARM
84+
assert False, self
6985

7086

7187
class Compute(ABC):
@@ -704,14 +720,14 @@ def normalize_arch(arch: Optional[str] = None) -> GoArchType:
704720
If the arch is not specified, falls back to `amd64`.
705721
"""
706722
if not arch:
707-
return "amd64"
723+
return GoArchType.AMD64
708724
arch_lower = arch.lower()
709725
if "32" in arch_lower or arch_lower in ["i386", "i686"]:
710726
raise ValueError(f"32-bit architectures are not supported: {arch}")
711727
if arch_lower.startswith("x86") or arch_lower.startswith("amd"):
712-
return "amd64"
728+
return GoArchType.AMD64
713729
if arch_lower.startswith("arm") or arch_lower.startswith("aarch"):
714-
return "arm64"
730+
return GoArchType.ARM64
715731
raise ValueError(f"Unsupported architecture: {arch}")
716732

717733

@@ -727,8 +743,7 @@ def get_dstack_runner_download_url(arch: Optional[str] = None) -> str:
727743
"/{version}/binaries/dstack-runner-linux-{arch}"
728744
)
729745
version = get_dstack_runner_version()
730-
arch = normalize_arch(arch)
731-
return url_template.format(version=version, arch=arch)
746+
return url_template.format(version=version, arch=normalize_arch(arch).value)
732747

733748

734749
def get_dstack_shim_download_url(arch: Optional[str] = None) -> str:
@@ -743,8 +758,7 @@ def get_dstack_shim_download_url(arch: Optional[str] = None) -> str:
743758
"/{version}/binaries/dstack-shim-linux-{arch}"
744759
)
745760
version = get_dstack_runner_version()
746-
arch = normalize_arch(arch)
747-
return url_template.format(version=version, arch=arch)
761+
return url_template.format(version=version, arch=normalize_arch(arch).value)
748762

749763

750764
def get_setup_cloud_instance_commands(

0 commit comments

Comments
 (0)