Skip to content

Commit

Permalink
implement minikube class for cluster create/delete/modify/display (#268)
Browse files Browse the repository at this point in the history
* Add mount option to Minikube engine class

* Add enable csi drivers to Minikube engine class

* Set csi driver to default for Minikube

* Prepare system state interface and collection (#313)

* Prepare system state interface and collection

Signed-off-by: Tyler Gu <[email protected]>

* Fix system state test

Signed-off-by: Tyler Gu <[email protected]>

* Fix temporary file creation in test

Signed-off-by: Tyler Gu <[email protected]>

---------

Signed-off-by: Tyler Gu <[email protected]>

* Intermediate progress

Signed-off-by: Tyler Gu <[email protected]>

* Feat: CLI for getting total number of schema nodes from CRD (#316)

Signed-off-by: Tyler Gu <[email protected]>

* Update bug numbers

Signed-off-by: Tyler Gu <[email protected]>

* Update counter.yml

* Reformat kubernetes engine and test codes

* Refactoring code due to the deletion of configure_cluster() in kind class(not pass pylint)

* Change docstrings

---------

Signed-off-by: Tyler Gu <[email protected]>
Co-authored-by: hzeng21 <hzeng21@localhost>
Co-authored-by: hzeng21 <[email protected]>
Co-authored-by: Jiawei "Tyler" Gu <[email protected]>
Co-authored-by: Tyler Gu <[email protected]>
Co-authored-by: hzeng21 <hzeng21@node0.hzeng21-188914.cs523-uiuc-sp24-pg0.clemson.cloudlab.us>
  • Loading branch information
6 people authored Feb 2, 2024
1 parent ece0f83 commit 85bafc4
Show file tree
Hide file tree
Showing 8 changed files with 469 additions and 149 deletions.
10 changes: 5 additions & 5 deletions acto/engine.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""The main engine of Acto. It is responsible for running the test cases and
collecting the results."""

import importlib
import json
import os
Expand Down Expand Up @@ -784,6 +785,8 @@ def __init__(
cluster = kind.Kind(
acto_namespace=acto_namespace,
feature_gates=operator_config.kubernetes_engine.feature_gates,
num_nodes=operator_config.num_nodes,
version=operator_config.kubernetes_version,
)
else:
logger.warning(
Expand All @@ -793,6 +796,8 @@ def __init__(
cluster = kind.Kind(
acto_namespace=acto_namespace,
feature_gates=operator_config.kubernetes_engine.feature_gates,
num_nodes=operator_config.num_nodes,
version=operator_config.kubernetes_version,
)

self.cluster = cluster
Expand All @@ -810,11 +815,6 @@ def __init__(
self.runner_type = Runner
self.checker_type = CheckerSet

# generate configuration files for the cluster runtime
self.cluster.configure_cluster(
operator_config.num_nodes, self.operator_config.kubernetes_version
)

self.__learn(
context_file=context_file,
helper_crd=helper_crd,
Expand Down
87 changes: 56 additions & 31 deletions acto/kubernetes_engine/base.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import subprocess
import time
from abc import ABC, abstractmethod
from typing import Callable, Dict, List
from typing import Callable, Optional

import kubernetes

Expand All @@ -12,77 +12,102 @@


class KubernetesEngine(ABC):
"""Interface for KubernetesEngine"""

@abstractmethod
def __init__(self, acto_namespace: int,
posthooks: List[KubernetesEnginePostHookType] = None,
feature_gates: Dict[str, bool] = None) -> None: ...
'''Constructor for KubernetesEngine
Args:
acto_namespace: the namespace of the acto
posthooks: a list of posthooks to be executed after the cluster is created
feature_gates: a list of feature gates to be enabled
'''
def __init__(
self,
acto_namespace: int,
posthooks: Optional[list[KubernetesEnginePostHookType]] = None,
feature_gates: Optional[dict[str, bool]] = None,
num_nodes=1,
version="",
) -> None:
"""Constructor for KubernetesEngine
@abstractmethod
def configure_cluster(self, num_nodes: int, version: str):
pass
Args:
acto_namespace: the namespace of the acto
posthooks: a list of posthooks to be executed after the cluster is created
feature_gates: a list of feature gates to be enabled
"""

@abstractmethod
def get_context_name(self, cluster_name: str) -> str:
pass
"""Returns the kubecontext based onthe cluster name"""

@abstractmethod
def create_cluster(self, name: str, kubeconfig: str):
pass
"""Use subprocess to create cluster
Args:
name: name of the cluster
config: path of the config file for cluster
version: k8s version
"""

@abstractmethod
def load_images(self, images_archive_path: str, name: str):
pass
"""Load image into the cluster
Args:
1. Path of the archive image
2.Name of the cluster
"""

@abstractmethod
def delete_cluster(self, name: str, kubeconfig: str, ):
pass
def delete_cluster(
self,
name: str,
kubeconfig: str,
):
"""Delete a cluster
Args:
name: name of the cluster
kubeconfig: path of the config file for cluster
"""

def restart_cluster(self, name: str, kubeconfig: str):
"""Restart the cluster
Args:
name: name of the kind cluster
kubeconfig: path of the config file for cluster
"""
logger = get_thread_logger(with_prefix=False)

retry_count = 3

while (retry_count > 0):
while retry_count > 0:
try:
self.delete_cluster(name, kubeconfig)
time.sleep(1)
self.create_cluster(name, kubeconfig)
time.sleep(1)
logger.info('Created cluster')
except Exception as e:
logger.info("Created cluster")
except RuntimeError as e:
logger.warning(
"%s happened when restarting cluster, retrying...", e)
"%s happened when restarting cluster, retrying...", e
)
retry_count -= 1
if retry_count == 0:
raise e
continue
break

def get_node_list(self, name: str):
'''Fetch the name of worker nodes inside a cluster
"""Fetch the name of worker nodes inside a cluster
Args:
1. name: name of the cluster name
'''
logger = get_thread_logger(with_prefix=False)
"""
_ = get_thread_logger(with_prefix=False)

cmd = ['docker', 'ps', '--format', '{{.Names}}', '-f']
cmd = ["docker", "ps", "--format", "{{.Names}}", "-f"]

if name == None:
if name is None:
cmd.append(f"name={CONST.CLUSTER_NAME}")
else:
cmd.append(f"name={name}")

p = subprocess.run(cmd, capture_output=True, text=True)
p = subprocess.run(cmd, capture_output=True, text=True, check=True)

if p.stdout == None or p.stdout == '':
if p.stdout is None or p.stdout == "":
# no nodes can be found, returning an empty array
return []
return p.stdout.strip().split('\n')
return p.stdout.strip().split("\n")
Loading

0 comments on commit 85bafc4

Please sign in to comment.