File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -70,9 +70,9 @@ def get_logs(namespace: str, service: str) -> str:
7070 except Exception as e :
7171 return "Error: Your service/namespace does not exist. Use kubectl to check."
7272
73- logs = "\n " .join (logs .split ("\n " ))
7473 logs = greedy_compress_lines (logs )
7574 print (logs )
75+
7676 return logs
7777
7878 @staticmethod
Original file line number Diff line number Diff line change 44"""Interface for helm operations"""
55
66import subprocess
7- import time
87
98from aiopslab .service .kubectl import KubeCtl
109
@@ -190,6 +189,36 @@ def add_repo(name: str, url: str):
190189 else :
191190 print (f"Helm repo { name } added successfully: { output .decode ('utf-8' )} " )
192191
192+ @staticmethod
193+ def status (release_name : str , namespace : str ) -> str :
194+ """Get the status of a Helm release.
195+
196+ Args:
197+ release_name (str): Name of the release.
198+ namespace (str): Namespace of the release.
199+
200+ Returns:
201+ str: Status output from Helm.
202+
203+ Raises:
204+ ValueError: If either parameter is missing.
205+ Exception: If the helm status command fails.
206+ """
207+
208+ if not release_name or not namespace :
209+ raise ValueError ("Both release_name and namespace must be provided" )
210+
211+ command = f"helm status { release_name } -n { namespace } "
212+ process = subprocess .Popen (
213+ command , shell = True , stdout = subprocess .PIPE , stderr = subprocess .PIPE
214+ )
215+ output , error = process .communicate ()
216+
217+ if process .returncode != 0 :
218+ # helm status failed
219+ raise RuntimeError (f"Failed to get status for release { release_name } : { error .decode ('utf-8' )} " )
220+
221+ return output .decode ("utf-8" ).strip ()
193222
194223# Example usage
195224if __name__ == "__main__" :
Original file line number Diff line number Diff line change 44import os
55import json
66import yaml
7- import time
7+ import logging
88from subprocess import CalledProcessError
99from aiopslab .service .helm import Helm
1010from aiopslab .service .kubectl import KubeCtl
@@ -121,18 +121,19 @@ def _pvc_exists(self, pvc_name: str) -> bool:
121121 if "No resources found" in result or "Error" in result :
122122 return False
123123 except CalledProcessError as e :
124+ logging .exception (f"Unexpected error while checking if the PersistentVolumeClaim exists: { e } " )
124125 return False
125126 return True
126127
127128 def _is_prometheus_running (self ) -> bool :
128- """Check if Prometheus is already running in the cluster."""
129- command = (
130- f"kubectl get pods -n { self .namespace } -l app.kubernetes.io/name=prometheus"
131- )
129+ """Check if Prometheus Helm release is deployed."""
132130 try :
133- result = KubeCtl ().exec_command (command )
134- if "Running" in result :
135- return True
136- except CalledProcessError :
131+ status_output = Helm .status (** self .helm_configs )
132+ for line in status_output .splitlines ():
133+ if line .strip ().startswith ("STATUS:" ):
134+ status_value = line .split (":" , 1 )[1 ].strip ().lower ()
135+ return status_value == "deployed"
136+ return False
137+ except Exception as e :
138+ logging .exception (f"Unexpected error while checking Prometheus status: { e } " )
137139 return False
138- return False
Original file line number Diff line number Diff line change 1515from clients .utils .llm import GPTClient
1616from dotenv import load_dotenv
1717
18- from parse_result import DOCS_SHELL_ONLY
18+ from clients . utils . templates import DOCS_SHELL_ONLY
1919
2020# Load environment variables from the .env file
2121load_dotenv ()
You can’t perform that action at this time.
0 commit comments