name: EKS (ENI)

on:
  pull_request: {}
  push:
    branches:
      - master
  schedule:
    - cron:  '10 */6 * * *'

env:
  clusterName: cilium-cli-ci-eks-eni-${{ github.run_number }}
  region: us-east-2

jobs:
  installation-and-connectivitiy:
    runs-on: ubuntu-latest
    timeout-minutes: 30
    steps:
      - name: Checkout
        uses: actions/checkout@v2

      - name: Build cilium CLI binary
        run: make

      - name: Install cilium CLI binary
        run: sudo make install

      - name: Install eksctl
        run: |
          curl --silent --location "https://github.com/weaveworks/eksctl/releases/latest/download/eksctl_$(uname -s)_amd64.tar.gz" | tar xz -C /tmp
          mv /tmp/eksctl .
          chmod +x eksctl

      - name: Configure AWS credentials
        uses: aws-actions/configure-aws-credentials@v1
        with:
          aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
          aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
          aws-region: ${{ env.region }}

      - name: Create EKS cluster
        run: |
          ./eksctl create cluster --name ${{ env.clusterName }} --without-nodegroup

      - name: Install cilium
        run: |
          cilium install --cluster-name ${{ env.clusterName }} --wait=false --config monitor-aggregation=None

      - name: Add nodegroup
        run: |
          ./eksctl create nodegroup --cluster ${{ env.clusterName }} --nodes 2 --node-private-networking --spot --managed

      - name: Enable Relay
        run: |
          cilium hubble enable

      - name: Status
        run: |
          cilium status --wait

      - name: Relay Port Forward
        run: |
          kubectl port-forward -n kube-system deployment/hubble-relay 4245:4245&
          sleep 5s

      - name: Connectivity Test
        run: |
          cilium connectivity test --test '!pod-to-local-nodeport'

      - name: Cleanup
        if: ${{ always() }}
        run: |
          cilium status
          kubectl get pods --all-namespaces -o wide
          curl -sLO https://github.com/cilium/cilium-sysdump/releases/latest/download/cilium-sysdump.zip
          python cilium-sysdump.zip --output cilium-sysdump-out
          ./eksctl delete cluster --name ${{ env.clusterName }}

      - name: Upload Artifacts
        if: ${{ always() }}
        uses: actions/upload-artifact@v2
        with:
          name: cilium-sysdump-out.zip
          path: cilium-sysdump-out.zip
          retention-days: 5
