You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2020/11/03 13:49:25 UTC

[GitHub] [airflow] mik-laj commented on a change in pull request #11802: Add Kubernetes cleanup-pods CLI command for Helm Chart

mik-laj commented on a change in pull request #11802:
URL: https://github.com/apache/airflow/pull/11802#discussion_r516355721



##########
File path: chart/templates/cleanup/cleanup-cronjob.yaml
##########
@@ -61,7 +61,7 @@ spec:
               image: {{ template "default_airflow_image" . }}
               imagePullPolicy: {{ .Values.images.airflow.pullPolicy }}
               # Don't use entry point here, we don't need to wait on pg-bouncer etc being available.
-              command: ["airflow-cleanup-pods", "--namespace={{ .Release.Namespace }}"]
+              args: ["kubernetes", "cleanup-pods", "--namespace={{ .Release.Namespace }}"]

Review comment:
       One comment left: https://github.com/apache/airflow/pull/11802#issuecomment-715665276

##########
File path: airflow/cli/commands/kubernetes_command.py
##########
@@ -61,3 +63,64 @@ def generate_pod_yaml(args):
             sanitized_pod = api_client.sanitize_for_serialization(pod)
             output.write(yaml.dump(sanitized_pod))
     print(f"YAML output can be found at {yaml_output_path}/airflow_yaml_output/")
+
+
+@cli_utils.action_logging
+def cleanup_pods(args):
+    """Clean up k8s pods in evicted/failed/succeeded states"""
+    namespace = args.namespace
+
+    # https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/
+    # All Containers in the Pod have terminated in success, and will not be restarted.
+    pod_succeeded = 'succeeded'
+
+    # All Containers in the Pod have terminated, and at least one Container has terminated in failure.
+    # That is, the Container either exited with non-zero status or was terminated by the system.
+    pod_failed = 'failed'
+
+    # https://kubernetes.io/docs/tasks/administer-cluster/out-of-resource/
+    pod_reason_evicted = 'evicted'
+    # If pod is failed and restartPolicy is:
+    # * Always: Restart Container; Pod phase stays Running.
+    # * OnFailure: Restart Container; Pod phase stays Running.
+    # * Never: Pod phase becomes Failed.
+    pod_restart_policy_never = 'never'
+
+    print('Loading Kubernetes configuration')
+    config.load_incluster_config()

Review comment:
       I thought about using this function. 
   https://github.com/apache/airflow/blob/b6ab0b591459e7efbd4a45e268de499b9c175bdf/airflow/kubernetes/kube_client.py#L95




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org