apiVersion: chaos-mesh.org/v1alpha1
kind: Workflow
metadata:
  name: chaos-experiment-20241002-042120
spec:
  entry: the-entry
  templates:
    #-------------------------------
    # entry point of whole workflow
    #-------------------------------
    - name: the-entry
      templateType: Serial
      deadline: 4m
      children:
        - pre-validation-phase
        - fault-injection-phase
        - post-validation-phase

    #-------------------------------------
    # Entry point of pre-validation-phase
    #-------------------------------------
    - name: pre-validation-phase
      templateType: Serial
      deadline: 1m20s
      children:
        - pre-validation-overlapped-workflows
    
    - name: pre-validation-suspend-workflow
      templateType: Serial
      deadline: 50s
      children:
        - pre-validation-suspend
        - pre-unittest-servicetrafficrouting

    - name: pre-validation-suspend
      templateType: Suspend
      deadline: 10s

    - name: pre-validation-overlapped-workflows
      templateType: Parallel
      deadline: 50s
      children:
        - pre-unittest-podrunning
        - pre-validation-suspend-workflow

    # Definitions of children of pre-validation-phase
    - name: pre-unittest-podrunning
      templateType: Task
      deadline: 40s
      task:
        container:
          name: pre-unittest-podrunning-container
          image: chaos-eater/k8sapi:1.0
          imagePullPolicy: IfNotPresent
          command: ["/bin/bash", "-c"]
          args: ["python /chaos-eater/sandbox/cycle_20241002_041546/unittest_PodRunning_mod0.py --duration 10"]
          volumeMounts:
            - name: pvc-volume
              mountPath: /chaos-eater
        volumes:
          - name: pvc-volume
            persistentVolumeClaim:
              claimName: pvc

    - name: pre-unittest-servicetrafficrouting
      templateType: Task
      deadline: 40s
      task:
        container:
          name: pre-unittest-servicetrafficrouting-container
          image: grafana/k6:latest
          command: ["k6", "run", "--duration", "10s", "--quiet", "/chaos-eater/sandbox/cycle_20241002_041546/hypothesis/steady_states/unittest_ServiceTrafficRouting_mod0.js"]    
          volumeMounts:
            - name: pvc-volume
              mountPath: /chaos-eater
        volumes:
          - name: pvc-volume
            persistentVolumeClaim:
              claimName: pvc
    
    #--------------------------------------
    # Entry point of fault-injection-phase
    #--------------------------------------
    - name: fault-injection-phase
      templateType: Serial
      deadline: 1m30s
      children:
        - fault-injection-overlapped-workflows

    - name: fault-injection-parallel-workflow
      templateType: Parallel
      deadline: 1m
      children:
        - fault-unittest-podrunning
        - fault-unittest-servicetrafficrouting
        - fault-networkchaos

    - name: fault-injection-suspend-workflow
      templateType: Serial
      deadline: 20s
      children:
        - fault-injection-suspend
        - fault-stresschaos

    - name: fault-injection-suspend
      templateType: Suspend
      deadline: 10s

    - name: fault-injection-suspend-workflow2
      templateType: Serial
      deadline: 30s
      children:
        - fault-injection-suspend2
        - fault-podchaos

    - name: fault-injection-suspend2
      templateType: Suspend
      deadline: 20s

    - name: fault-injection-overlapped-workflows
      templateType: Parallel
      deadline: 1m
      children:
        - fault-injection-parallel-workflow
        - fault-injection-suspend-workflow
        - fault-injection-suspend-workflow2

    # Definitions of children of pre-validation-phase
    # unit tests
    - name: fault-unittest-podrunning
      templateType: Task
      deadline: 1m
      task:
        container:
          name: fault-unittest-podrunning-container
          image: chaos-eater/k8sapi:1.0
          imagePullPolicy: IfNotPresent
          command: ["/bin/bash", "-c"]
          args: ["python /chaos-eater/sandbox/cycle_20241002_041546/unittest_PodRunning_mod0.py --duration 30"]
          volumeMounts:
            - name: pvc-volume
              mountPath: /chaos-eater
        volumes:
          - name: pvc-volume
            persistentVolumeClaim:
              claimName: pvc

    - name: fault-unittest-servicetrafficrouting
      templateType: Task
      deadline: 1m
      task:
        container:
          name: fault-unittest-servicetrafficrouting-container
          image: grafana/k6:latest
          command: ["k6", "run", "--duration", "30s", "--quiet", "/chaos-eater/sandbox/cycle_20241002_041546/hypothesis/steady_states/unittest_ServiceTrafficRouting_mod0.js"]    
          volumeMounts:
            - name: pvc-volume
              mountPath: /chaos-eater
        volumes:
          - name: pvc-volume
            persistentVolumeClaim:
              claimName: pvc

    # fault_injections
    - name: fault-networkchaos
      templateType: NetworkChaos
      deadline: 10s
      networkChaos:
        action: delay
        delay:
          jitter: 10ms
          latency: 100ms
        device: eth0
        direction: to
        mode: all
        selector:
          labelSelectors:
            app: example
          namespaces:
            - default
        target:
          mode: all
          selector:
            labelSelectors:
              app: example
            namespaces:
              - default


    - name: fault-stresschaos
      templateType: StressChaos
      deadline: 10s
      stressChaos:
        containerNames:
          - example-container
        mode: one
        selector:
          labelSelectors:
            app: example
          namespaces:
            - default
        stressors:
          cpu:
            load: 100
            workers: 1


    - name: fault-podchaos
      templateType: PodChaos
      deadline: 10s
      podChaos:
        action: pod-kill
        mode: one
        selector:
          labelSelectors:
            app: example
          namespaces:
            - default

    
    #--------------------------------------
    # Entry point of post-validation phase
    #--------------------------------------
    - name: post-validation-phase
      templateType: Serial
      deadline: 1m10s
      children:
        - post-validation-overlapped-workflows

    - name: post-validation-suspend-workflow
      templateType: Serial
      deadline: 40s
      children:
        - post-validation-suspend
        - post-unittest-servicetrafficrouting

    - name: post-validation-suspend
      templateType: Suspend
      deadline: 5s

    - name: post-validation-overlapped-workflows
      templateType: Parallel
      deadline: 40s
      children:
        - post-unittest-podrunning
        - post-validation-suspend-workflow

    # Definitions of children of pre-validation-phase
    - name: post-unittest-podrunning
      templateType: Task
      deadline: 35s
      task:
        container:
          name: post-unittest-podrunning-container
          image: chaos-eater/k8sapi:1.0
          imagePullPolicy: IfNotPresent
          command: ["/bin/bash", "-c"]
          args: ["python /chaos-eater/sandbox/cycle_20241002_041546/unittest_PodRunning_mod0.py --duration 5"]
          volumeMounts:
            - name: pvc-volume
              mountPath: /chaos-eater
        volumes:
          - name: pvc-volume
            persistentVolumeClaim:
              claimName: pvc

    - name: post-unittest-servicetrafficrouting
      templateType: Task
      deadline: 35s
      task:
        container:
          name: post-unittest-servicetrafficrouting-container
          image: grafana/k6:latest
          command: ["k6", "run", "--duration", "5s", "--quiet", "/chaos-eater/sandbox/cycle_20241002_041546/hypothesis/steady_states/unittest_ServiceTrafficRouting_mod0.js"]    
          volumeMounts:
            - name: pvc-volume
              mountPath: /chaos-eater
        volumes:
          - name: pvc-volume
            persistentVolumeClaim:
              claimName: pvc