Created
February 28, 2022 13:09
-
-
Save muzi502/9b26c6854c509c42ecd7f7004436ca23 to your computer and use it in GitHub Desktop.
Archive workflow logs by kubectl command
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apiVersion: argoproj.io/v1alpha1 | |
kind: Workflow | |
metadata: | |
generateName: archive-log-test- | |
namespace: default | |
spec: | |
templates: | |
- name: archive-log-test | |
steps: | |
- - name: list-default-running-pods | |
template: kubectl | |
arguments: | |
parameters: | |
- name: namespace | |
value: default | |
- - name: list-kube-system-running-pods | |
template: kubectl | |
arguments: | |
parameters: | |
- name: namespace | |
value: kube-system | |
- name: kubectl | |
inputs: | |
parameters: | |
- name: namespace | |
container: | |
name: "kubectl" | |
image: lachlanevenson/k8s-kubectl:v1.23.2 | |
command: | |
- sh | |
- -c | |
- | | |
kubectl get pods --field-selector=status.phase=Running -n {{inputs.parameters.namespace}} | |
- name: exit-handler | |
container: | |
name: "kubectl" | |
image: lachlanevenson/k8s-kubectl:v1.23.2 | |
command: | |
- sh | |
- -c | |
- | | |
kubectl get pods -l workflows.argoproj.io/workflow=${POD_NAME%-*} \ | |
--sort-by=".metadata.creationTimestamp" -o name | grep -v ${POD_NAME} \ | |
| xargs -I {} -t kubectl logs {} -c main >> ${LOG_PATH}/${POD_NAME%-*}.log | |
env: | |
- name: POD_NAME | |
valueFrom: | |
fieldRef: | |
fieldPath: metadata.name | |
- name: LOG_PATH | |
value: /var/log/workflow | |
resources: {} | |
volumeMounts: | |
- name: nfs-datastore | |
mountPath: /var/log/workflow | |
retryStrategy: | |
limit: "5" | |
retryPolicy: OnFailure | |
entrypoint: archive-log-test | |
serviceAccountName: default | |
volumes: | |
- name: nfs-datastore | |
nfs: | |
server: NFS_SERVER | |
path: /data/workflow/log | |
onExit: exit-handler |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment