Skip to content

Commit

Permalink
multiple namespaces+empty podlabels
Browse files Browse the repository at this point in the history
  • Loading branch information
sandeephans committed Jun 20, 2024
1 parent 82cecb6 commit 2efcf8b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions utils/chaos_ai/docker/swagger_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']:
Expand Down
15 changes: 15 additions & 0 deletions utils/chaos_ai/src/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2efcf8b

Please sign in to comment.