This plugin could reduce unnecessary Argo workflows. For example, there are mutiple commits against a pull request in a short time. In most cases, only the last time of the workflow running is necessary. This plugin will stop all the workflows which have the same parameters and come from same WorkflowTemplate.
First, enable the plugin feature of Argo workflows:
kubectl patch deployment \ workflow-controller \ --namespace argo \ --type='json' \ -p='[{"op": "add", "path": "/spec/template/spec/containers/0/env/0", "value": { "name": "ARGO_EXECUTOR_PLUGINS", "value": "true", }}]'then, install this plugin as a ConfigMap:
cat <<EOF | kubectl apply -f - --- apiVersion: v1 kind: ServiceAccount metadata: name: argo-atomic-plugin-executor-plugin namespace: default --- apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole metadata: name: argo-plugin-addition-role rules: - apiGroups: - argoproj.io resources: - workflowtasksets - workflowtasksets/status verbs: - get - watch - patch --- apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding metadata: name: argo-plugin-atomic-addition-binding roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole name: argo-plugin-addition-role subjects: - kind: ServiceAccount name: argo-atomic-plugin-executor-plugin namespace: default - kind: ServiceAccount name: argo namespace: argo - kind: ServiceAccount name: default namespace: default --- apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding metadata: name: argo-plugin-atomic-binding roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole name: argo-server-cluster-role subjects: - kind: ServiceAccount name: argo-atomic-plugin-executor-plugin namespace: default - kind: ServiceAccount name: argo namespace: argo - kind: ServiceAccount name: default namespace: default --- apiVersion: v1 data: sidecar.automountServiceAccountToken: "true" sidecar.container: | image: ghcr.io/linuxsuren/argo-workflow-atomic-plugin:master command: - argo-wf-atomic name: argo-atomic-plugin ports: - containerPort: 3002 resources: limits: cpu: 500m memory: 128Mi requests: cpu: 250m memory: 64Mi securityContext: allowPrivilegeEscalation: true runAsNonRoot: true runAsUser: 65534 kind: ConfigMap metadata: labels: workflows.argoproj.io/configmap-type: ExecutorPlugin name: argo-atomic-plugin namespace: argo EOFFirst, create a WorkflowTemplate:
cat <<EOF | kubectl apply -f - apiVersion: argoproj.io/v1alpha1 kind: WorkflowTemplate metadata: name: plugin-atomic namespace: default spec: entrypoint: main templates: - name: main dag: tasks: - name: sleep template: sleep - name: atomic template: atomic - script: image: ghcr.io/linuxsuren/hd:v0.0.70 command: [sh] source: sleep 90 name: sleep - name: atomic plugin: argo-atomic-plugin: {} EOFthen, trigger it from UI or the following command:
cat <<EOF | kubectl create -f - apiVersion: argoproj.io/v1alpha1 kind: Workflow metadata: generateName: plugin-atomic namespace: default labels: workflows.argoproj.io/workflow-template: plugin-atomic spec: workflowTemplateRef: name: plugin-atomic EOF