name: Kind

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

env:
  KIND_VERSION: v0.9.0
  KIND_CONFIG: .github/kind-config.yaml
  TIMEOUT: 2m
  LOG_TIME: 30m

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

      - name: Build cilium CLI binary
        run: make

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

      - name: Create kind cluster
        uses: helm/kind-action@v1.0.0
        with:
          version: ${{ env.KIND_VERSION }}
          config: ${{ env.KIND_CONFIG }}

      - name: Install Cilium
        run: |
          cilium install --config monitor-aggregation=none

          kubectl wait -n kube-system --for=condition=Ready --all pod --timeout=5m
          # To make sure that cilium CRD is available (default timeout is 5m)
          # https://github.com/cilium/cilium/blob/master/operator/crd.go#L34
          kubectl wait --for condition=Established crd/ciliumnetworkpolicies.cilium.io --timeout=5m

      - name: Enable Relay
        run: |
          cilium hubble enable

          kubectl wait -n kube-system --for=condition=Ready --all pod --timeout=5m

      - 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

      - name: Uninstall cilium
        run: |
          cilium uninstall --wait

      - name: Install Cilium with Encryption
        run: |
          cilium install --encryption

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

      - name: Connectivity test
        run: |
          cilium connectivity test

      - 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

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