Skip to content

Commit

Permalink
[CE-411] Kubernetes host can not run fill up
Browse files Browse the repository at this point in the history
    While fill up operation will format the cluster name in
    {hostName}_{1,2,3...}, which is illegal in naming
    Kubernetes namespace, this patch added a function to
    handle this situation.

    CE-411 #done

Change-Id: Ic0cc42fc0aab789373adb1b628fa4eb674a0d497
Signed-off-by: luke <[email protected]>
  • Loading branch information
jiahaoc1993 committed Aug 26, 2018
1 parent d16f929 commit f516693
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/agent/k8s/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ def create(self, cid, mapped_ports, host, config, user_id):
consensus = self._get_cluster_info(cid, config)

operation = K8sClusterOperation(kube_config)
cluster_name = self.trim_cluster_name(cluster_name)

containers = operation.deploy_cluster(cluster_name,
ports_index,
nfsServer_ip,
Expand All @@ -73,6 +75,7 @@ def delete(self, cid, worker_api, config):
consensus = self._get_cluster_info(cid, config)

operation = K8sClusterOperation(kube_config)
cluster_name = self.trim_cluster_name(cluster_name)
operation.delete_cluster(cluster_name,
ports_index,
nfsServer_ip,
Expand Down Expand Up @@ -103,6 +106,7 @@ def get_services_urls(self, cid):
.k8s_param)

operation = K8sClusterOperation(kube_config)
cluster_name = self.trim_cluster_name(cluster_name)
services_urls = operation.get_services_urls(cluster_name)
except Exception as e:
logger.error("Failed to get Kubernetes services's urls: {}"
Expand All @@ -117,6 +121,7 @@ def start(self, name, worker_api, mapped_ports, log_type, log_level,
consensus = self._get_cluster_info(name, config)

operation = K8sClusterOperation(kube_config)
cluster_name = self.trim_cluster_name(cluster_name)
containers = operation.start_cluster(cluster_name, ports_index,
nfsServer_ip, consensus)

Expand Down Expand Up @@ -150,6 +155,7 @@ def stop(self, name, worker_api, mapped_ports, log_type, log_level,
consensus = self._get_cluster_info(name, config)

operation = K8sClusterOperation(kube_config)
cluster_name = self.trim_cluster_name(cluster_name)
operation.stop_cluster(cluster_name,
ports_index,
nfsServer_ip,
Expand Down Expand Up @@ -177,3 +183,8 @@ def restart(self, name, worker_api, mapped_ports, log_type, log_level,
else:
logger.error("Failed to Restart Kubernetes Cluster")
return None

def trim_cluster_name(self, cluster_name):
if cluster_name.find("_") != -1:
cluster_name = cluster_name.replace("_", "-")
return cluster_name.lower()

0 comments on commit f516693

Please sign in to comment.