diff --git a/utils/chaos_ai/docker/swagger_api.py b/utils/chaos_ai/docker/swagger_api.py index 6933132d..762e27c8 100644 --- a/utils/chaos_ai/docker/swagger_api.py +++ b/utils/chaos_ai/docker/swagger_api.py @@ -55,6 +55,8 @@ def startchaos(self, kubeconfigfile, file_id, params): params['iterations'] = config_params['iterations'] params['maxfaults'] = config_params['maxfaults'] # faults = [f + ':' + p for f in params['faults'].split(',') for p in params['podlabels'].split(',')] + if params['podlabels'] is None or params['podlabels'] == '': + params['podlabels'] = ','.join(utils.get_pods(kubeconfigfile)) faults = [] for f in params['faults'].split(','): if f in ['pod-delete']: diff --git a/utils/chaos_ai/src/utils.py b/utils/chaos_ai/src/utils.py index 23229796..2ee5c41d 100644 --- a/utils/chaos_ai/src/utils.py +++ b/utils/chaos_ai/src/utils.py @@ -73,6 +73,21 @@ def get_pod_labels(namespace: str, kubeconfig_path: str = None): return pods +def get_pods(kubeconfig_path: str = None): + pods = [] + try: + # Load the kubeconfig file + if kubeconfig_path: + config.load_kube_config(config_file=kubeconfig_path) + else: + config.load_kube_config() # Load default kubeconfig file + v1 = client.CoreV1Api() + pods = v1.list_pod_for_all_namespaces() + + except Exception as e: + print(f"An unexpected error occurred: {e}") + return pods + # Example usage namespace = 'default' kubeconfig_path = '/path/to/your/kubeconfig' # Provide the path to your kubeconfig file, or set to None to use the default