Skip to content

Commit

Permalink
Support users to only input the kubeconfig path for connecting the k8…
Browse files Browse the repository at this point in the history
…s cluster (#2799)

## What do these changes do?

- Support users to only input the kubeconfig path for connecting the k8s
cluster
- Get the current kubeconfig for vineyardctl.

## Related issue number

Fixes #2796

Signed-off-by: Ye Cao <caoye.cao@alibaba-inc.com>
  • Loading branch information
dashanji committed Jun 2, 2023
1 parent 33e3007 commit f1b216c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
22 changes: 22 additions & 0 deletions coordinator/gscoordinator/kubernetes_launcher.py
Expand Up @@ -207,6 +207,12 @@ def __init__(

self._vineyard_pod_name_list = []

# set the kube config file
self._k8s_config_file = self.get_current_kubeconfig()
config = kwargs.pop("k8s_client_config", {})
if "config_file" in config:
self._k8s_config_file = config["config_file"]

if self._vineyard_deployment is not None:
self._deploy_vineyard_deployment_if_not_exist()
# check the if the vineyard deployment is ready again
Expand Down Expand Up @@ -302,6 +308,19 @@ def type(self):
def vineyard_deployment_exists(self):
return self._vineyard_deployment is not None

def get_current_kubeconfig(self):
"""Gets the current kubeconfig file path.
Returns:
str: The path to the current kubeconfig file.
"""

kubeconfig_path = os.environ.get("KUBECONFIG")
if kubeconfig_path is None:
kubeconfig_path = "~/.kube/config"

return kubeconfig_path

# the argument `with_analytical_` means whether to add the analytical engine
# container to the engine statefulset, and the other three arguments are similar.
def _build_engine_cluster(
Expand Down Expand Up @@ -862,6 +881,7 @@ def _inject_vineyard_as_sidecar(self, workload):
# https://github.com/v6d-io/v6d/tree/main/k8s/cmd#vineyardctl-inject

new_workload_json = vineyard.deploy.vineyardctl.inject(
kubeconfig=self._k8s_config_file,
resource=workload_json,
sidecar_volume_mountpath="/tmp/vineyard_workspace",
name=sts_name + "-vineyard",
Expand Down Expand Up @@ -1055,6 +1075,7 @@ def _add_pod_affinity_for_vineyard_deployment(self, workload):
self._api_client.sanitize_for_serialization(workload)
)
new_workload_json = vineyard.deploy.vineyardctl.schedule.workload(
kubeconfig=self._k8s_config_file,
resource=workload_json,
vineyardd_name=self._vineyard_deployment,
vineyardd_namespace=self._namespace,
Expand Down Expand Up @@ -1257,6 +1278,7 @@ def _deploy_vineyard_deployment(self):

owner_reference_json = self._get_owner_reference_as_json()
vineyard.deploy.vineyardctl.deploy.vineyard_deployment(
kubeconfig=self._k8s_config_file,
name=self._vineyard_deployment,
namespace=self._namespace,
vineyard_replicas=self._num_workers,
Expand Down
5 changes: 5 additions & 0 deletions python/graphscope/client/session.py
Expand Up @@ -1013,6 +1013,11 @@ def _connect(self):
# try to connect to exist coordinator
self._coordinator_endpoint = self._config_params["addr"]
elif self._cluster_type == types_pb2.K8S:
# if users only provide kube_config file path
if isinstance(self._config_params["k8s_client_config"], str):
self._config_params["k8s_client_config"] = {
"config_file": self._config_params["k8s_client_config"]
}
if isinstance(
self._config_params["k8s_client_config"],
kube_client.api_client.ApiClient,
Expand Down

0 comments on commit f1b216c

Please sign in to comment.