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

[DPE-3343] spark8t support for incluster use #60

Merged
merged 2 commits into from
Jan 26, 2024
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
10 changes: 4 additions & 6 deletions spark8t/cli/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,10 @@ def add_deploy_arguments(parser: ArgumentParser) -> ArgumentParser:


def get_kube_interface(args: Namespace) -> AbstractKubeInterface:
return (
LightKube(args.kubeconfig or defaults.kube_config, defaults)
if args.backend == "lightkube"
else KubeInterface(
args.kubeconfig or defaults.kube_config, context_name=args.context
)
_class = LightKube if args.backend == "lightkube" else KubeInterface

return _class(
args.kubeconfig or defaults.kube_config, defaults, context_name=args.context
)


Expand Down
4 changes: 3 additions & 1 deletion spark8t/cli/service_account_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ def main(args: Namespace, logger: Logger):

logger.debug(f"Using K8s context: {context}")

registry = K8sServiceAccountRegistry(kube_interface.with_context(context))
registry = K8sServiceAccountRegistry(
kube_interface.with_context(context) if context else kube_interface
)

if args.action == Actions.CREATE:
service_account = build_service_account_from_args(args, registry)
Expand Down
16 changes: 12 additions & 4 deletions spark8t/domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import re
from dataclasses import dataclass
from enum import Enum
from typing import Any, Callable, Dict, List, Optional, Tuple
from typing import Any, Callable, Dict, List, Optional, Tuple, Union

from spark8t.utils import WithLogging, union

Expand Down Expand Up @@ -211,6 +211,13 @@ def spark_home(self):
def spark_confs(self):
return self.environ.get("SPARK_CONFS", os.path.join(self.spark_home, "conf"))

@property
def kubernetes_api(self):
return (
f"https://{self.environ['KUBERNETES_SERVICE_HOST']}:"
+ f"{self.environ['KUBERNETES_SERVICE_PORT']}"
)

@property
def spark_user_data(self):
return self.environ["SPARK_USER_DATA"]
Expand All @@ -221,9 +228,10 @@ def kubectl_cmd(self) -> str:
return self.environ.get("SPARK_KUBECTL", "kubectl")

@property
def kube_config(self) -> str:
"""Return default kubeconfig to use if not explicitly provided."""
return self.environ["KUBECONFIG"]
def kube_config(self) -> Union[None, str]:
"""Return default kubeconfig to use if provided in env variable."""
filename = self.environ.get("KUBECONFIG", None)
return filename if filename else None

@property
def static_conf_file(self) -> str:
Expand Down
Loading