Skip to content

Commit 99a1a42

Browse files
authored
Add SPARGLIM_SERVER_CUSTOM_CONFIG for custom config spark (#15)
* Add SPARGLIM_SERVER_CUSTOM_CONFIG for custom config spark * Fix custom config
1 parent 0358fa8 commit 99a1a42

File tree

4 files changed

+18
-4
lines changed

4 files changed

+18
-4
lines changed

dev/sparglim-server/k8s/deployment.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,6 @@ spec:
3333
valueFrom:
3434
fieldRef:
3535
fieldPath: metadata.name
36+
- name: SPARGLIM_SERVER_CUSTOM_CONFIG
37+
# json string for custom config, see https://spark.apache.org/docs/latest/configuration.html
38+
value: "{}"

examples/sparglim-server/k8s/deployment.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,6 @@ spec:
3333
valueFrom:
3434
fieldRef:
3535
fieldPath: metadata.name
36+
- name: SPARGLIM_SERVER_CUSTOM_CONFIG
37+
# json string for custom config, see https://spark.apache.org/docs/latest/configuration.html
38+
value: "{}"

sparglim/server/cli.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Copyright (c) 2023 Wh1isper
22
# Licensed under the BSD 3-Clause License
3+
import json
34
import os
45
import signal
56

@@ -12,9 +13,12 @@
1213
@click.command()
1314
@click.option("--mode", default=None)
1415
@click.option("--root_dir", default="./")
15-
def start(mode, root_dir):
16+
@click.option("--custom_config", default=None)
17+
def start(mode, root_dir, custom_config):
18+
if custom_config is not None:
19+
custom_config = json.loads(custom_config)
1620
if mode:
17-
Daemon(mode=mode, root_dir=root_dir).start_and_daemon()
21+
Daemon(mode=mode, root_dir=root_dir, custom_config=custom_config).start_and_daemon()
1822
else:
1923
Daemon(root_dir=root_dir).start_and_daemon()
2024

sparglim/server/daemon.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Copyright (c) 2023 Wh1isper
22
# Licensed under the BSD 3-Clause License
3+
import json
34
import os
45
import signal
56
import subprocess
@@ -9,7 +10,7 @@
910
from datetime import datetime
1011
from functools import wraps
1112
from pathlib import Path
12-
from typing import List, Optional
13+
from typing import Any, Dict, List, Optional
1314

1415
import psutil
1516

@@ -31,6 +32,7 @@ class Daemon:
3132
# Stop the daemon when the KeyboardInterrupt is raised
3233
# This will not start duplicate connect server, unless using different root_dir and port
3334
ENV_MASTER_MODE = "SPARGLIM_SERVER_MODE"
35+
ENV_CUSTOM_CONFIG = "SPARGLIM_SERVER_CUSTOM_CONFIG"
3436
DEFAULT_MODE = "local"
3537
SPARK_IDENT_STRING = "sparglim-connect-server" # SPARK_IDENT_STRING
3638

@@ -40,8 +42,10 @@ def __init__(
4042
root_dir: str = "./",
4143
*,
4244
k8s_config_path: Optional[str] = None,
45+
custom_config: Optional[Dict[str, Any]] = None,
4346
):
4447
self.mode = mode or os.getenv(self.ENV_MASTER_MODE, self.DEFAULT_MODE)
48+
self.custom_config = custom_config or json.loads(os.getenv(self.ENV_CUSTOM_CONFIG, "{}"))
4549

4650
self.root_dir = Path(root_dir)
4751

@@ -68,7 +72,7 @@ def __init__(
6872
f"org.apache.spark:spark-connect_{SCALA_VERSION}:{SPARK_VERSION}"
6973
)
7074
self.builder = SparkEnvConfiger().config_connect_server(
71-
self.mode, k8s_config_path=k8s_config_path
75+
self.mode, custom_config=self.custom_config, k8s_config_path=k8s_config_path
7276
)
7377

7478
self._tailer: Optional[Tailer] = None

0 commit comments

Comments
 (0)