Skip to content

Commit 85faee6

Browse files
[Backward incompatible] Rename properties in Kubernetes backend config (#3137)
* networking -> proxy_jump * ssh_host -> hostname * ssh_port -> port In addition, `dstack-` prefix has been added to jump pod and service names for consistency with jobs pods and services. Closes: #3136 Co-authored-by: peterschmidt85 <andrey.cheptsov@gmail.com>
1 parent daa3d03 commit 85faee6

File tree

5 files changed

+30
-30
lines changed

5 files changed

+30
-30
lines changed

docs/docs/concepts/backends.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,27 +1049,27 @@ In case of a self-managed cluster, also specify the IP address of any node in th
10491049
- type: kubernetes
10501050
kubeconfig:
10511051
filename: ~/.kube/config
1052-
networking:
1053-
ssh_host: localhost # The external IP address of any node
1054-
ssh_port: 32000 # Any port accessible outside of the cluster
1052+
proxy_jump:
1053+
hostname: localhost # The external IP address of any node
1054+
port: 32000 # Any port accessible outside of the cluster
10551055
```
10561056

10571057
</div>
10581058

1059-
The port specified to `ssh_port` must be accessible outside of the cluster.
1059+
The port specified to `port` must be accessible outside of the cluster.
10601060

10611061
??? info "Kind"
10621062
If you are using [Kind](https://kind.sigs.k8s.io/), make sure to make
1063-
to set up `ssh_port` via `extraPortMappings` for proxying SSH traffic:
1063+
to set up `port` via `extraPortMappings` for proxying SSH traffic:
10641064

10651065
```yaml
10661066
kind: Cluster
10671067
apiVersion: kind.x-k8s.io/v1alpha4
10681068
nodes:
10691069
- role: control-plane
10701070
extraPortMappings:
1071-
- containerPort: 32000 # Must be same as `ssh_port`
1072-
hostPort: 32000 # Must be same as `ssh_port`
1071+
- containerPort: 32000 # Must be same as `port`
1072+
hostPort: 32000 # Must be same as `port`
10731073
```
10741074
10751075
Go ahead and create the cluster like this:
@@ -1092,13 +1092,13 @@ In case of a self-managed cluster, also specify the IP address of any node in th
10921092
- type: kubernetes
10931093
kubeconfig:
10941094
filename: ~/.kube/config
1095-
networking:
1096-
ssh_port: 32000 # Any port accessible outside of the cluster
1095+
proxy_jump:
1096+
port: 32000 # Any port accessible outside of the cluster
10971097
```
10981098

10991099
</div>
11001100

1101-
The port specified to `ssh_port` must be accessible outside of the cluster.
1101+
The port specified to `port` must be accessible outside of the cluster.
11021102

11031103
??? info "EKS"
11041104
For example, if you are using EKS, make sure to add it via an ingress rule

docs/docs/reference/server/config.yml.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,9 +293,9 @@ to configure [backends](../../concepts/backends.md) and other [server-level sett
293293
cat my-service-account-file.json | jq -c | jq -R
294294
```
295295

296-
###### `projects[n].backends[type=kubernetes].networking` { #kubernetes-networking data-toc-label="networking" }
296+
###### `projects[n].backends[type=kubernetes].proxy_jump` { #kubernetes-proxy_jump data-toc-label="proxy_jump" }
297297

298-
#SCHEMA# dstack._internal.core.backends.kubernetes.models.KubernetesNetworkingConfig
298+
#SCHEMA# dstack._internal.core.backends.kubernetes.models.KubernetesProxyJumpConfig
299299
overrides:
300300
show_root_heading: false
301301

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from dstack._internal.core.backends.base.offers import filter_offers_by_requirements
2121
from dstack._internal.core.backends.kubernetes.models import (
2222
KubernetesConfig,
23-
KubernetesNetworkingConfig,
23+
KubernetesProxyJumpConfig,
2424
)
2525
from dstack._internal.core.backends.kubernetes.utils import (
2626
call_api_method,
@@ -69,10 +69,10 @@ class KubernetesCompute(
6969
def __init__(self, config: KubernetesConfig):
7070
super().__init__()
7171
self.config = config.copy()
72-
networking_config = self.config.networking
73-
if networking_config is None:
74-
networking_config = KubernetesNetworkingConfig()
75-
self.networking_config = networking_config
72+
proxy_jump = self.config.proxy_jump
73+
if proxy_jump is None:
74+
proxy_jump = KubernetesProxyJumpConfig()
75+
self.proxy_jump = proxy_jump
7676
self.api = get_api_from_config_data(config.kubeconfig.data)
7777

7878
def get_offers_by_requirements(
@@ -143,7 +143,7 @@ def run_job(
143143
# as an ssh proxy jump to connect to all other services in Kubernetes.
144144
# Setup jump pod in a separate thread to avoid long-running run_job.
145145
# In case the thread fails, the job will be failed and resubmitted.
146-
jump_pod_hostname = self.networking_config.ssh_host
146+
jump_pod_hostname = self.proxy_jump.hostname
147147
if jump_pod_hostname is None:
148148
jump_pod_hostname = get_cluster_public_ip(self.api)
149149
if jump_pod_hostname is None:
@@ -156,7 +156,7 @@ def run_job(
156156
namespace=self.config.namespace,
157157
project_name=run.project_name,
158158
ssh_public_keys=[project_ssh_public_key.strip(), run.run_spec.ssh_key_pub.strip()],
159-
jump_pod_port=self.networking_config.ssh_port,
159+
jump_pod_port=self.proxy_jump.port,
160160
)
161161
if not created:
162162
threading.Thread(
@@ -820,11 +820,11 @@ def _run_ssh_command(hostname: str, port: int, ssh_private_key: str, command: st
820820

821821

822822
def _get_jump_pod_name(project_name: str) -> str:
823-
return f"{project_name}-ssh-jump-pod"
823+
return f"dstack-{project_name}-ssh-jump-pod"
824824

825825

826826
def _get_jump_pod_service_name(project_name: str) -> str:
827-
return f"{project_name}-ssh-jump-pod-service"
827+
return f"dstack-{project_name}-ssh-jump-pod-service"
828828

829829

830830
def _get_pod_service_name(pod_name: str) -> str:

src/dstack/_internal/core/backends/kubernetes/models.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
DEFAULT_NAMESPACE = "default"
99

1010

11-
class KubernetesNetworkingConfig(CoreModel):
12-
ssh_host: Annotated[
13-
Optional[str], Field(description="The external IP address of any node")
11+
class KubernetesProxyJumpConfig(CoreModel):
12+
hostname: Annotated[
13+
Optional[str], Field(description="The external IP address or hostname of any node")
1414
] = None
15-
ssh_port: Annotated[
15+
port: Annotated[
1616
Optional[int], Field(description="Any port accessible outside of the cluster")
1717
] = None
1818

@@ -24,8 +24,8 @@ class KubeconfigConfig(CoreModel):
2424

2525
class KubernetesBackendConfig(CoreModel):
2626
type: Annotated[Literal["kubernetes"], Field(description="The type of backend")] = "kubernetes"
27-
networking: Annotated[
28-
Optional[KubernetesNetworkingConfig], Field(description="The networking configuration")
27+
proxy_jump: Annotated[
28+
Optional[KubernetesProxyJumpConfig], Field(description="The SSH proxy jump configuration")
2929
] = None
3030
namespace: Annotated[
3131
str, Field(description="The namespace for resources managed by `dstack`")

src/tests/_internal/core/backends/kubernetes/test_configurator.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from dstack._internal.core.backends.kubernetes.models import (
99
KubeconfigConfig,
1010
KubernetesBackendConfigWithCreds,
11-
KubernetesNetworkingConfig,
11+
KubernetesProxyJumpConfig,
1212
)
1313
from dstack._internal.core.errors import BackendInvalidCredentialsError
1414

@@ -17,7 +17,7 @@ class TestKubernetesConfigurator:
1717
def test_validate_config_valid(self):
1818
config = KubernetesBackendConfigWithCreds(
1919
kubeconfig=KubeconfigConfig(data="valid", filename="-"),
20-
networking=KubernetesNetworkingConfig(ssh_host=None, ssh_port=None),
20+
proxy_jump=KubernetesProxyJumpConfig(hostname=None, port=None),
2121
)
2222
with patch(
2323
"dstack._internal.core.backends.kubernetes.utils.get_api_from_config_data"
@@ -30,7 +30,7 @@ def test_validate_config_valid(self):
3030
def test_validate_config_invalid_config(self):
3131
config = KubernetesBackendConfigWithCreds(
3232
kubeconfig=KubeconfigConfig(data="invalid", filename="-"),
33-
networking=KubernetesNetworkingConfig(ssh_host=None, ssh_port=None),
33+
proxy_jump=KubernetesProxyJumpConfig(hostname=None, port=None),
3434
)
3535
with (
3636
patch(

0 commit comments

Comments
 (0)