Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,11 @@ def cleanup_pods(args):
# * OnFailure: Restart Container; Pod phase stays Running.
# * Never: Pod phase becomes Failed.
pod_restart_policy_never = "never"

print("Loading Kubernetes configuration")
if args.verbose:
print("Loading Kubernetes configuration")
kube_client = get_kube_client()
print(f"Listing pods in namespace {namespace}")
if args.verbose:
print(f"Listing pods in namespace {namespace}")
airflow_pod_labels = [
"dag_id",
"task_id",
Expand All @@ -165,7 +166,8 @@ def cleanup_pods(args):
pod_list = kube_client.list_namespaced_pod(**list_kwargs)
for pod in pod_list.items:
pod_name = pod.metadata.name
print(f"Inspecting pod {pod_name}")
if args.verbose:
print(f"Inspecting pod {pod_name}")
pod_phase = pod.status.phase.lower()
pod_reason = pod.status.reason.lower() if pod.status.reason else ""
pod_restart_policy = pod.spec.restart_policy.lower()
Expand All @@ -190,7 +192,8 @@ def cleanup_pods(args):
except ApiException as e:
print(f"Can't remove POD: {e}", file=sys.stderr)
else:
print(f"No action taken on pod {pod_name}")
if args.verbose:
print(f"No action taken on pod {pod_name}")
continue_token = pod_list.metadata._continue
if not continue_token:
break
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,12 @@ def test_cleanup_pods_command_args(self):
"my-namespace",
"--min-pending-minutes",
"60",
"--verbose",
]
args = self.arg_parser.parse_args(params)
assert args.namespace == "my-namespace"
assert args.min_pending_minutes == 60
assert args.verbose is True

def test_cleanup_pods_command_default_args(self):
"""Test cleanup-pods command with default arguments."""
Expand All @@ -97,6 +99,7 @@ def test_cleanup_pods_command_default_args(self):
# Should use default values from configuration
assert hasattr(args, "namespace")
assert args.min_pending_minutes == 30
assert args.verbose is False

def test_generate_dag_yaml_command_args(self):
"""Test generate-dag-yaml command with various arguments."""
Expand Down
Loading