Skip to content

Commit

Permalink
fix: handle cases when running inside a kubernetes cluster (#17)
Browse files Browse the repository at this point in the history
The current setup for the plugin assumes that we have a kubeconfig file
used to connect to the cluster. However, this is not the case if the
code submitting the job is itself running in a pod in the cluster, as we
will need to use the default service account provided by the cluster.
This modifies the init to catch any errors when loading a kubeconfig
file and use the incluster configuration instead

The issue in the python kubernetes client here describes the problem:
kubernetes-client/python#1005
  • Loading branch information
bilalshaikh42 committed Aug 14, 2024
1 parent 127bedf commit a031314
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion snakemake_executor_plugin_kubernetes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@ class ExecutorSettings(ExecutorSettingsBase):
# Implementation of your executor
class Executor(RemoteExecutor):
def __post_init__(self):
kubernetes.config.load_kube_config()
try:
kubernetes.config.load_kube_config()
except kubernetes.config.config_exception.ConfigException:
kubernetes.config.load_incluster_config()

self.k8s_cpu_scalar = self.workflow.executor_settings.cpu_scalar
self.k8s_service_account_name = (
Expand Down

0 comments on commit a031314

Please sign in to comment.