Skip to content

Commit

Permalink
finish testing add/delete/displaying node list
Browse files Browse the repository at this point in the history
  • Loading branch information
hzeng21 committed Oct 9, 2023
1 parent 94f01e4 commit 32a9962
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
15 changes: 9 additions & 6 deletions acto/kubernetes_engine/minikube.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,17 @@
class Minikube(base.KubernetesEngine):

def __init__(
self, acto_namespace: int, posthooks: List[base.KubernetesEnginePostHookType] = None,):
self, acto_namespace: int, posthooks: List[base.KubernetesEnginePostHookType] = None, num_nodes = 1, version = ""):
self.config_path = os.path.join(CONST.CLUSTER_CONFIG_FOLDER, f'MINIKUBE-{acto_namespace}.yaml')
self.num_nodes = num_nodes
self._k8s_version = version
if posthooks is not None:
self.posthooks = posthooks

def configure_cluster(self, num_nodes: int, version: str):
'''Create config file for kind'''
pass
self.num_nodes = num_nodes
self._k8s_version = version

def get_context_name(self, cluster_name: str) -> str:
'''Returns the kubecontext based onthe cluster name
Expand Down Expand Up @@ -52,10 +55,10 @@ def create_cluster(self, name: str, kubeconfig: str):
else:
raise Exception('Missing kubeconfig for kind create')

num_nodes = 3
cmd.extend(['--nodes', str(num_nodes)])
cmd.extend(['--nodes', str(self.num_nodes)])

cmd.extend(['--kubernetes-version', "v1.27.3"])
if self._k8s_version != "":
cmd.extend(['--kubernetes-version', str(self._k8s_version)])

p = subprocess.run(cmd, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
while p.returncode != 0:
Expand Down Expand Up @@ -118,7 +121,7 @@ def get_node_list(self, name: str):
cmd.extend(['--profile', name])
p = subprocess.run(cmd, capture_output=True, text=True)

if p.stdout == None or p.stdout == '':
if p.stdout == None or p.stdout == '' or "not found" in p.stdout:
# no nodes can be found, returning an empty array
logging.critical(f"No node for cluster {name} can be found")
raise RuntimeError
Expand Down
22 changes: 17 additions & 5 deletions acto/kubernetes_engine/test_minikube.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,21 @@
from . import minikube as minikube

def test_minikube_create():
cluster = minikube.Minikube(acto_namespace = 0)
# cluster.create_cluster("test1", "/users/hzeng21/.kube/config2")
node_list = cluster.get_node_list("test1")
assert len(node_list) != 3
num_nodes = 3
name = "test1"
cluster = minikube.Minikube(acto_namespace = 0, num_nodes=num_nodes, version="v1.27.4")
cluster.create_cluster(name, "/users/hzeng21/.kube/config2")
node_list = cluster.get_node_list(name)
assert len(node_list) == num_nodes


def test_minikube_delete():
num_nodes = 3
name = "test2"
cluster = minikube.Minikube(acto_namespace = 0, num_nodes=num_nodes, version="v1.27.4")
cluster.create_cluster(name, "/users/hzeng21/.kube/config2")
cluster.delete_cluster(name, "/users/hzeng21/.kube/config2")
# should raise a runtime error
cluster.get_node_list(name)



0 comments on commit 32a9962

Please sign in to comment.