---
.packet:
  extends: .testcases
  variables:
    ANSIBLE_TIMEOUT: "120"
    CI_PLATFORM: packet
    SSH_USER: kubespray
  tags:
    - ffci
  needs:
    - pipeline-image
    - ci-not-authorized

# CI template for PRs
.packet_pr:
  stage: deploy-part1
  rules:
    - if: $PR_LABELS =~ /.*ci-short.*/
      when: manual
      allow_failure: true
    - if: $CI_COMMIT_BRANCH =~ /^pr-.*$/
      when: on_success
    - when: manual
      allow_failure: true
  extends: .packet

  ## Uncomment this to have multiple stages
  # needs:
  #   - packet_ubuntu20-calico-all-in-one

.packet_pr_short:
  stage: deploy-part1
  extends: .packet
  rules:
    - if: $CI_COMMIT_BRANCH =~ /^pr-.*$/
      when: on_success
    - when: manual
      allow_failure: true

.packet_pr_manual:
  extends: .packet_pr
  stage: deploy-extended
  rules:
    - if: $PR_LABELS =~ /.*ci-full.*/
      when: on_success
    # Else run as manual
    - when: manual
      allow_failure: true

.packet_pr_extended:
  extends: .packet_pr
  stage: deploy-extended
  rules:
    - if: $PR_LABELS =~ /.*(ci-extended|ci-full).*/
      when: on_success
    - when: manual
      allow_failure: true

# CI template for periodic CI jobs
# Enabled when PERIODIC_CI_ENABLED var is set
.packet_periodic:
  only:
    variables:
      - $PERIODIC_CI_ENABLED
  allow_failure: true
  extends: .packet

packet_cleanup_old:
  stage: deploy-part1
  extends: .packet_periodic
  script:
    - cd tests
    - make cleanup-packet
  after_script: []

# The ubuntu20-calico-all-in-one jobs are meant as early stages to prevent running the full CI if something is horribly broken
packet_ubuntu20-calico-all-in-one:
  stage: deploy-part1
  extends: .packet_pr_short
  variables:
    RESET_CHECK: "true"

# ### PR JOBS PART2

packet_ubuntu20-crio:
  extends: .packet_pr_manual

packet_ubuntu22-calico-all-in-one:
  extends: .packet_pr

packet_ubuntu22-calico-all-in-one-upgrade:
  extends: .packet_pr
  variables:
    UPGRADE_TEST: graceful

packet_ubuntu24-calico-etcd-datastore:
  extends: .packet_pr

packet_almalinux8-crio:
  extends: .packet_pr

packet_almalinux8-kube-ovn:
  extends: .packet_pr

packet_debian11-calico:
  extends: .packet_pr

packet_debian11-macvlan:
  extends: .packet_pr

packet_debian12-cilium:
  extends: .packet_pr

packet_rockylinux8-calico:
  extends: .packet_pr

packet_rockylinux9-cilium:
  extends: .packet_pr
  variables:
    RESET_CHECK: "true"

packet_amazon-linux-2-all-in-one:
  extends: .packet_pr

packet_opensuse-docker-cilium:
  extends: .packet_pr

packet_ubuntu20-cilium-sep:
  extends: .packet_pr

## Extended
packet_debian11-docker:
  extends: .packet_pr_extended

packet_debian12-docker:
  extends: .packet_pr_extended

packet_debian12-calico:
  extends: .packet_pr_extended

packet_almalinux8-calico-remove-node:
  extends: .packet_pr_extended
  variables:
    REMOVE_NODE_CHECK: "true"
    REMOVE_NODE_NAME: "instance-3"

packet_rockylinux9-calico:
  extends: .packet_pr_extended

packet_almalinux8-calico:
  extends: .packet_pr_extended

packet_almalinux8-docker:
  extends: .packet_pr_extended

packet_ubuntu20-calico-all-in-one-hardening:
  extends: .packet_pr_extended

packet_ubuntu24-calico-all-in-one:
  extends: .packet_pr_extended

packet_ubuntu20-calico-etcd-kubeadm:
  extends: .packet_pr_extended

packet_ubuntu24-all-in-one-docker:
  extends: .packet_pr_extended

packet_ubuntu22-all-in-one-docker:
  extends: .packet_pr_extended

# ### MANUAL JOBS
packet_ubuntu20-flannel-ha:
  extends: .packet_pr_manual

packet_ubuntu20-all-in-one-docker:
  extends: .packet_pr_manual

packet_ubuntu20-flannel-ha-once:
  extends: .packet_pr_manual

packet_fedora39-calico-swap-selinux:
  extends: .packet_pr_manual

packet_almalinux8-calico-ha-ebpf:
  extends: .packet_pr_manual

packet_almalinux8-calico-nodelocaldns-secondary:
  extends: .packet_pr_manual

packet_debian11-custom-cni:
  extends: .packet_pr_manual

packet_debian11-kubelet-csr-approver:
  extends: .packet_pr_manual

packet_debian12-custom-cni-helm:
  extends: .packet_pr_manual

packet_ubuntu20-calico-ha-wireguard:
  extends: .packet_pr_manual

# PERIODIC
packet_fedora40-docker-calico:
  stage: deploy-extended
  extends: .packet_periodic
  variables:
    RESET_CHECK: "true"

packet_fedora39-calico-selinux:
  stage: deploy-extended
  extends: .packet_periodic

packet_ubuntu20-calico-etcd-kubeadm-upgrade-ha:
  stage: deploy-extended
  extends: .packet_periodic
  variables:
    UPGRADE_TEST: basic


packet_debian11-calico-upgrade-once:
  stage: deploy-extended
  extends: .packet_periodic
  variables:
    UPGRADE_TEST: graceful

packet_ubuntu20-calico-ha-recover:
  stage: deploy-extended
  extends: .packet_periodic
  variables:
    RECOVER_CONTROL_PLANE_TEST: "true"
    RECOVER_CONTROL_PLANE_TEST_GROUPS: "etcd[2:]:kube_control_plane[1:]"

packet_ubuntu20-calico-ha-recover-noquorum:
  stage: deploy-extended
  extends: .packet_periodic
  variables:
    RECOVER_CONTROL_PLANE_TEST: "true"
    RECOVER_CONTROL_PLANE_TEST_GROUPS: "etcd[1:]:kube_control_plane[1:]"

packet_debian11-calico-upgrade:
  stage: deploy-extended
  extends: .packet_periodic
  variables:
    UPGRADE_TEST: graceful

packet_debian12-cilium-svc-proxy:
  stage: deploy-extended
  extends: .packet_periodic
