Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support remote management of cluster #5

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 0 additions & 22 deletions aiopslab/observer/prometheus/prometheus-pv.yml

This file was deleted.

11 changes: 11 additions & 0 deletions aiopslab/observer/prometheus/prometheus-pvc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: prometheus-pvc
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
storageClassName: openebs-hostpath
4 changes: 2 additions & 2 deletions aiopslab/observer/prometheus/prometheus/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ server:
## set, choosing the default provisioner. (gp2 on AWS, standard on
## GKE, AWS & OpenStack)
## yinfang
storageClass: "local-storage"
storageClass: "openebs-hostpath"

## Prometheus server data Persistent Volume Binding Mode
## If defined, volumeBindingMode: <volumeBindingMode>
Expand All @@ -483,7 +483,7 @@ server:
## Persistent Volume Name
## Useful if Persistent Volumes have been provisioned in advance and you want to use a specific one
## yinfang
volumeName: "prometheus-pv"
#volumeName: "prometheus-pv" # Changed in order to use PVC

emptyDir:
## Prometheus server emptyDir volume size limit
Expand Down
13 changes: 13 additions & 0 deletions aiopslab/orchestrator/orchestrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"""Orchestrator class that interfaces with the agent and the environment."""

from aiopslab.service.helm import Helm
from aiopslab.service.kubectl import KubeCtl
from aiopslab.session import Session
from aiopslab.orchestrator.problems.registry import ProblemRegistry
from aiopslab.orchestrator.parser import ResponseParser
Expand All @@ -23,6 +24,7 @@ def __init__(self):
self.sprint = SessionPrint()
self.execution_start_time = None
self.execution_end_time = None
self.kubectl = KubeCtl()

def init_problem(self, problem_id: str):
"""Initialize a problem instance for the agent to solve.
Expand All @@ -42,6 +44,17 @@ def init_problem(self, problem_id: str):
self.session.set_problem(prob, pid=problem_id)
self.session.set_agent(self.agent_name)

print('Setting up OpenEBS...')
self.kubectl.exec_command(
f"kubectl apply -f https://openebs.github.io/charts/openebs-operator.yaml"
)
self.kubectl.exec_command(
"kubectl patch storageclass openebs-hostpath -p '{\"metadata\": {\"annotations\":{\"storageclass.kubernetes.io/is-default-class\":\"true\"}}}'"
)
# Wait for openebs to be ready
self.kubectl.wait_for_state('openebs', 'Running')
print('OpenEBS setup completed.')

# Setup and deploy Prometheus
self.prometheus = Prometheus()
self.prometheus.deploy()
Expand Down
7 changes: 1 addition & 6 deletions aiopslab/service/helm.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,7 @@ def install(**args):
)
dependency_output, dependency_error = dependency_process.communicate()

if version:
command = f"helm install {release_name} {chart_path} -n {namespace} --version {version}"
else:
command = f"helm install {release_name} {chart_path} -n {namespace}"

command = f"helm install {release_name} {chart_path} -n {namespace}"
command = f"helm install {release_name} {chart_path} -n {namespace} --create-namespace"
process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE)
output, error = process.communicate()

Expand Down
2 changes: 1 addition & 1 deletion aiopslab/service/metadata/prometheus.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
"chart_path": "observer/prometheus/prometheus/",
"namespace": "observe"
},
"PersistentVolumeConfig": "observer/prometheus/prometheus-pv.yml"
"PersistentVolumeClaimConfig": "observer/prometheus/prometheus-pvc.yml"
}
18 changes: 9 additions & 9 deletions aiopslab/service/telemetry/prometheus.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def __init__(self):
self.name = None
self.namespace = None
self.helm_configs = {}
self.pv_config_file = None
self.pvc_config_file = None

self.load_service_json()

Expand All @@ -39,8 +39,8 @@ def load_service_json(self):
chart_path = self.helm_configs["chart_path"]
self.helm_configs["chart_path"] = str(BASE_DIR / chart_path)

self.pv_config_file = os.path.join(
BASE_DIR, metadata.get("PersistentVolumeConfig")
self.pvc_config_file = os.path.join(
BASE_DIR, metadata.get("PersistentVolumeClaimConfig")
)

def get_service_json(self) -> dict:
Expand Down Expand Up @@ -73,8 +73,8 @@ def deploy(self):
self._delete_pv()
Helm.uninstall(**self.helm_configs)

if self.pv_config_file:
pv_name = self._get_pv_name_from_file(self.pv_config_file)
if self.pvc_config_file:
pv_name = self._get_pv_name_from_file(self.pvc_config_file)
if not self._pv_exists(pv_name):
self._apply_pv()

Expand All @@ -87,19 +87,19 @@ def teardown(self):
"""Teardown the metric collector deployment."""
Helm.uninstall(**self.helm_configs)

if self.pv_config_file:
if self.pvc_config_file:
self._delete_pv()

def _apply_pv(self):
"""Apply the PersistentVolume configuration."""
print(f"Applying PersistentVolume from {self.pv_config_file}")
print(f"Applying PersistentVolume from {self.pvc_config_file}")
KubeCtl().exec_command(
f"kubectl apply -f {self.pv_config_file} -n {self.namespace}"
f"kubectl apply -f {self.pvc_config_file} -n {self.namespace}"
)

def _delete_pv(self):
"""Delete the PersistentVolume and associated PersistentVolumeClaim."""
pv_name = self._get_pv_name_from_file(self.pv_config_file)
pv_name = self._get_pv_name_from_file(self.pvc_config_file)
result = KubeCtl().exec_command(f"kubectl get pv {pv_name} --ignore-not-found")

if result:
Expand Down