Skip to content

Commit 9a4c69f

Browse files
committed
Kubernetes: add multi-node support
* Discover and set instance's internal_ip (PodIP) * Fix region mismatch * Add `privileged: true` support * [runner] Set RLIMIT_MEMLOCK to unlimited. Fixes issues with InfiniBand/RDMA Part-of: #3126
1 parent 85faee6 commit 9a4c69f

21 files changed

Lines changed: 115 additions & 8 deletions

File tree

runner/internal/executor/executor.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
"github.com/dstackai/dstack/runner/internal/schemas"
3030
"github.com/dstackai/dstack/runner/internal/types"
3131
"github.com/prometheus/procfs"
32+
"golang.org/x/sys/unix"
3233
)
3334

3435
// TODO: Tune these parameters for optimal experience/performance
@@ -518,6 +519,21 @@ func (ex *RunExecutor) execJob(ctx context.Context, jobLogFile io.Writer) error
518519

519520
cmd.Env = envMap.Render()
520521

522+
// Configure process resource limits
523+
// TODO: Make rlimits customizable in the run configuration. Currently, we only set max locked memory
524+
// to unlimited to fix the issue with InfiniBand/RDMA: "Cannot allocate memory".
525+
// See: https://github.com/ofiwg/libfabric/issues/6437
526+
// See: https://github.com/openucx/ucx/issues/8229
527+
// Note: we already set RLIMIT_MEMLOCK to unlimited in the shim if we've detected IB devices
528+
// (see configureHpcNetworkingIfAvailable() function), but, as it's on the shim side, it only works
529+
// with VM-based backends.
530+
rlimitMemlock := unix.Rlimit{Cur: unix.RLIM_INFINITY, Max: unix.RLIM_INFINITY}
531+
// TODO: Check if we have CAP_SYS_RESOURCE. In container environments, even root usually doesn't have
532+
// this capability.
533+
if err := unix.Setrlimit(unix.RLIMIT_MEMLOCK, &rlimitMemlock); err != nil {
534+
log.Error(ctx, "Failed to set resource limits", "err", err)
535+
}
536+
521537
log.Trace(ctx, "Starting exec", "cmd", cmd.String(), "working_dir", cmd.Dir, "env", cmd.Env)
522538

523539
ptm, err := startCommand(cmd)

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
ComputeWithMultinodeSupport,
2525
ComputeWithPlacementGroupSupport,
2626
ComputeWithPrivateGatewaySupport,
27+
ComputeWithPrivilegedSupport,
2728
ComputeWithReservationSupport,
2829
ComputeWithVolumeSupport,
2930
generate_unique_gateway_instance_name,
@@ -90,6 +91,7 @@ def _ec2client_cache_methodkey(self, ec2_client, *args, **kwargs):
9091
class AWSCompute(
9192
ComputeWithAllOffersCached,
9293
ComputeWithCreateInstanceSupport,
94+
ComputeWithPrivilegedSupport,
9395
ComputeWithMultinodeSupport,
9496
ComputeWithReservationSupport,
9597
ComputeWithPlacementGroupSupport,

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
ComputeWithCreateInstanceSupport,
4444
ComputeWithGatewaySupport,
4545
ComputeWithMultinodeSupport,
46+
ComputeWithPrivilegedSupport,
4647
generate_unique_gateway_instance_name,
4748
generate_unique_instance_name,
4849
get_gateway_user_data,
@@ -78,6 +79,7 @@
7879
class AzureCompute(
7980
ComputeWithAllOffersCached,
8081
ComputeWithCreateInstanceSupport,
82+
ComputeWithPrivilegedSupport,
8183
ComputeWithMultinodeSupport,
8284
ComputeWithGatewaySupport,
8385
Compute,

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,14 @@ def _restrict_instance_offer_az_to_volumes_az(
320320
]
321321

322322

323+
class ComputeWithPrivilegedSupport:
324+
"""
325+
Must be subclassed to support runs with `privileged: true`.
326+
"""
327+
328+
pass
329+
330+
323331
class ComputeWithMultinodeSupport:
324332
"""
325333
Must be subclassed to support multinode tasks and cluster fleets.

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
Compute,
55
ComputeWithAllOffersCached,
66
ComputeWithCreateInstanceSupport,
7+
ComputeWithPrivilegedSupport,
78
get_shim_commands,
89
)
910
from dstack._internal.core.backends.base.offers import get_catalog_offers
@@ -27,6 +28,7 @@
2728
class CloudRiftCompute(
2829
ComputeWithAllOffersCached,
2930
ComputeWithCreateInstanceSupport,
31+
ComputeWithPrivilegedSupport,
3032
Compute,
3133
):
3234
def __init__(self, config: CloudRiftConfig):

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from dstack._internal.core.backends.base.compute import (
77
ComputeWithCreateInstanceSupport,
88
ComputeWithFilteredOffersCached,
9+
ComputeWithPrivilegedSupport,
910
generate_unique_instance_name,
1011
get_shim_commands,
1112
)
@@ -32,6 +33,7 @@
3233
class CudoCompute(
3334
ComputeWithFilteredOffersCached,
3435
ComputeWithCreateInstanceSupport,
36+
ComputeWithPrivilegedSupport,
3537
Compute,
3638
):
3739
def __init__(self, config: CudoConfig):

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from dstack._internal.core.backends.base.compute import (
99
ComputeWithAllOffersCached,
1010
ComputeWithCreateInstanceSupport,
11+
ComputeWithPrivilegedSupport,
1112
generate_unique_instance_name,
1213
get_shim_commands,
1314
)
@@ -39,6 +40,7 @@
3940
class DataCrunchCompute(
4041
ComputeWithAllOffersCached,
4142
ComputeWithCreateInstanceSupport,
43+
ComputeWithPrivilegedSupport,
4244
Compute,
4345
):
4446
def __init__(self, config: DataCrunchConfig):

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from dstack._internal.core.backends.base.compute import (
88
ComputeWithAllOffersCached,
99
ComputeWithCreateInstanceSupport,
10+
ComputeWithPrivilegedSupport,
1011
generate_unique_instance_name,
1112
get_user_data,
1213
)
@@ -40,6 +41,7 @@
4041
class BaseDigitalOceanCompute(
4142
ComputeWithAllOffersCached,
4243
ComputeWithCreateInstanceSupport,
44+
ComputeWithPrivilegedSupport,
4345
Compute,
4446
):
4547
def __init__(self, config: BaseDigitalOceanConfig, api_url: str, type: BackendType):

src/dstack/_internal/core/backends/features.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
ComputeWithMultinodeSupport,
55
ComputeWithPlacementGroupSupport,
66
ComputeWithPrivateGatewaySupport,
7+
ComputeWithPrivilegedSupport,
78
ComputeWithReservationSupport,
89
ComputeWithVolumeSupport,
910
)
@@ -38,6 +39,10 @@ def _get_backends_with_compute_feature(
3839
configurator_classes=_configurator_classes,
3940
compute_feature_class=ComputeWithCreateInstanceSupport,
4041
)
42+
BACKENDS_WITH_PRIVILEGED_SUPPORT = _get_backends_with_compute_feature(
43+
configurator_classes=_configurator_classes,
44+
compute_feature_class=ComputeWithPrivilegedSupport,
45+
)
4146
BACKENDS_WITH_MULTINODE_SUPPORT = [BackendType.REMOTE] + _get_backends_with_compute_feature(
4247
configurator_classes=_configurator_classes,
4348
compute_feature_class=ComputeWithMultinodeSupport,

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
ComputeWithMultinodeSupport,
2424
ComputeWithPlacementGroupSupport,
2525
ComputeWithPrivateGatewaySupport,
26+
ComputeWithPrivilegedSupport,
2627
ComputeWithVolumeSupport,
2728
generate_unique_gateway_instance_name,
2829
generate_unique_instance_name,
@@ -90,6 +91,7 @@ class GCPVolumeDiskBackendData(CoreModel):
9091
class GCPCompute(
9192
ComputeWithAllOffersCached,
9293
ComputeWithCreateInstanceSupport,
94+
ComputeWithPrivilegedSupport,
9395
ComputeWithMultinodeSupport,
9496
ComputeWithPlacementGroupSupport,
9597
ComputeWithGatewaySupport,

0 commit comments

Comments
 (0)