apiVersion: api/v1
kind: Plan
name: cdc-tiup-cluster
schedule: "@daily"
tags: ["cdc"]
testbed:
  generateName: cdc-testbed-
  reclaimPolicy:
    gcStrategy:
      onFailure:
        artifact:
          monitor: true
          log: true
        reserveEnv:
          durationOnWorkingHour: '{{meta.parameters.onFailureReserveDurationOnWorkingHour}}'
        notification:
          feishu: https://open.feishu.cn/open-apis/bot/v2/hook/4f6c6406-c963-4d52-8641-cca17aa734e9
  items:
  - name: tiup
    type: WORKLOAD_NODE # 测试资源类型: WORKLOAD_NODE
    spec:
      container:
        name: node
        image: hub.pingcap.net/qa/base-image
        imagePullPolicy: IfNotPresent
        resources:
          requests:
            # NOTE: 目前对 tiup 的支持是将 pod 当做虚拟机使用，如果节点占用内存接近 request.memory 时，可能会导致 pod 被 oom killed，导致测试集群无法恢复(因为 tiup 用的 ssh key，systemd service 等被删除)
            # Workaround 是: 1. 对于中控机节点，适当调大 requests.memory 值 (中控机上跑了 haproxy，会有一定的资源占用)
            # 2. 对于 component 节点，配置 requests.memory 的同时也配置 tiup 拓扑里的 resource_control, 保证每个节点的 request.memory > resource_control.memory_limit (此时内存占用过高时，component 进程会被 systemd killed 而不会影响到 pod)
            # resource_control 的配置方式见： https://github.com/pingcap/tiup/blob/01843be5957ee189ff8cad0bb8cf2f0669cf3ddc/embed/examples/cluster/topology.example.yaml?_pjax=%23js-repo-pjax-container%2C%20div%5Bitemtype%3D%22http%3A%2F%2Fschema.org%2FSoftwareSourceCode%22%5D%20main%2C%20%5Bdata-pjax-container%5D#L19-L28
            memory: 32Gi
            cpu: 8000m
        securityContext:
          capabilities:
            add: [ "SYS_ADMIN", "SYS_PTRACE", "NET_ADMIN" ]
  - name: downstream
    type: MYSQL_NODE
    spec:
      image: docker.io/mysql:8
      port: 3306
      env:
        MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
        MYSQL_ROOT_HOST: "%"
      resources:
        requests:
          memory: 4Gi
          cpu: 1000m
          storage: 10Gi
      volumeMount:
        mountPath: "/var/lib/mysql" # mountPath of "storage" request
  - name: workload
    type: WORKLOAD_NODE
    spec:
      container:
        name: go-tpc
        image: "{{meta.parameters.gotpc_image}}"
        command:
        - tail
        - "-f"
        - /dev/null
        resources:
          requests:
            memory: 4Gi
            cpu: 4000m
        volumeMount:
          mountPath: "/var/lib/mysql"
steps:
- name: cdc-tiup-cluster-upgrade-sync
  caseName: cdc_tiup_cluster_upgrade_sync
  arguments:
  - name: tiup
    value: "{{testbed.tiup}}"
  - name: downstream
    value: "{{testbed.downstream}}"
  - name: workload
    value: "{{testbed.workload}}"
  - name: tiupClusterVersion
    value: "{{meta.parameters.tiup_target_version}}"
