Skip to content

Rancher Setup, Chart Installation & E2E Tests #81

Rancher Setup, Chart Installation & E2E Tests

Rancher Setup, Chart Installation & E2E Tests #81

Workflow file for this run

name: Rancher Setup, Chart Installation & E2E Tests
on:
push:
workflow_dispatch:
schedule:
- cron: '* */8 * * *'
jobs:
setup_rancher:
name: Setup Rancher - Tag - ${{ matrix.tag }}
runs-on: ubuntu-latest
strategy:
matrix:
tag: ['v2.8-head', 'v2.9-head', 'v2.10-head', 'head'] # Rancher version tags
fail-fast: false
steps:
- name: Generate random password
id: password_gen
run: echo "PASSWORD=$(openssl rand -base64 16)" >> $GITHUB_ENV
- name: Start Rancher container
run: |
docker run -d -it --name rancher \
-e "CATTLE_BOOTSTRAP_PASSWORD=${{ env.PASSWORD }}" --restart unless-stopped \
-p 80:80 -p 443:443 -p 6443:6443 \
--privileged "rancher/rancher:${{ matrix.tag }}"
- name: Wait for Rancher to initialize
run: sleep 3m #Rancher's startup time
- name: Generate Rancher API token
id: get_token
run: |
for i in {1..3}; do
LOGIN_RESPONSE=$(curl --silent -X POST -H 'Content-Type: application/json' -d '{"username":"admin","password":"'${{ env.PASSWORD }}'"}' https://localhost/v3-public/localProviders/local?action=login --insecure)
TOKEN=$(echo $LOGIN_RESPONSE | jq -r .token)
if [ -z "$NODE_STATUS" ]; then
echo "RANCHER_TOKEN=$TOKEN" >> $GITHUB_ENV
else
echo "Retrying in 20 seconds..."
sleep 20
fi
done
- name: Check Rancher node status
run: |
for i in {1..15}; do
NODE_STATUS=$(curl -k --silent -H "Authorization: Bearer ${{ env.RANCHER_TOKEN }}" https://localhost/v3/nodes | jq -r '.data[] | .state' | grep -v "active" || true)
if [ -z "$NODE_STATUS" ]; then
echo "All nodes are active and running!"
break
else
echo "Some nodes are not yet active. Retrying in 20 seconds..."
sleep 20
fi
done
- name: Rancher permanent token for e2e tests
id: get_permanent_token
run: |
PERMANENT_TOKEN_RESPONSE=$(curl --silent -X POST -H 'Content-Type: application/json' -H "Authorization: Bearer ${{ env.RANCHER_TOKEN }}" -d '{"type":"token","description":"e2e-tests"}' https://localhost/v3/token --insecure)
PERMANENT_TOKEN=$(echo $PERMANENT_TOKEN_RESPONSE | jq -r .token)
if [ "$PERMANENT_TOKEN" == "null" ] || [ -z "$PERMANENT_TOKEN" ]; then
echo "Failed to obtain permanent token. Exiting."
exit 1
fi
echo "RANCHER_PERMANENT_TOKEN=$PERMANENT_TOKEN" >> $GITHUB_ENV
- name: Setup Rancher Config File in Home Directory
run: |
cat << EOF > ~/cattle-config.yaml
rancher:
host: localhost
adminToken: ${{ env.RANCHER_PERMANENT_TOKEN }}
insecure: True
clusterName: local
cleanup: true
EOF
- name: Export CATTLE_TEST_CONFIG environment variable
run: echo "CATTLE_TEST_CONFIG=$HOME/cattle-config.yaml" >> $GITHUB_ENV
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version-file: './go.mod'
- name: Create artifacts directory
run: mkdir -p ~/artifacts
- name: Installation Charts
run: |
TEST_LABEL_FILTER=installation go test -timeout 20m github.com/rancher/observability-e2e/tests/e2e -v -count=1 -ginkgo.v | tee ~/artifacts/test-output-installation-${{ matrix.tag }}.txt
- name: Run E2E Tests
run: |
TEST_LABEL_FILTER=E2E go test -timeout 30m github.com/rancher/observability-e2e/tests/e2e -v -count=1 -ginkgo.v | tee ~/artifacts/test-output-e2e-${{ matrix.tag }}.txt
- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
name: test-artifacts
path: ~/artifacts
- name: Cleanup all containers
if: always()
run: |
echo "Cleaning up all containers..."
docker ps -q | xargs -r docker rm -f