Skip to content

Commit

Permalink
Merge pull request #21 from deepakpunia-suse/run-e2e-test-with-rke1
Browse files Browse the repository at this point in the history
Automated Rancher Setup, Chart Installation, and E2E Testing Workflow
  • Loading branch information
deepakpunia-suse authored Nov 18, 2024
2 parents a7a843d + 04225e5 commit f566937
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 4 deletions.
114 changes: 114 additions & 0 deletions .github/workflows/docker_run.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
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
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
![Lint Code Status](https://github.com/rancher/observability-e2e/actions/workflows/verify-changes.yaml/badge.svg)

# Observability E2E Tests

[![Lint Code Status](https://github.com/rancher/observability-e2e/actions/workflows/verify-changes.yaml/badge.svg?branch=main)](https://github.com/rancher/observability-e2e/actions/workflows/verify-changes.yaml)

[![E2E Docker Run Status](https://github.com/rancher/observability-e2e/actions/workflows/docker_run.yaml/badge.svg?branch=main)](https://github.com/rancher/observability-e2e/actions/workflows/docker_run.yaml)

This repository contains end-to-end (E2E) tests for monitoring installations in Rancher. Follow the steps below to set up and run the tests.

## Prerequisites
Expand Down
11 changes: 9 additions & 2 deletions tests/helper/charts/ranchermonitoring.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ func InstallRancherMonitoringChart(client *rancher.Client, installOptions *Insta
return err
}

// Ensure the server URL has a scheme
serverURL := serverSetting.Value
if !strings.HasPrefix(serverURL, "http://") && !strings.HasPrefix(serverURL, "https://") {
// Assume HTTPS if no scheme is present
serverURL = "https://" + serverURL
}

// Retrieve the default registry setting.
registrySetting, err := client.Management.Setting.ByID(defaultRegistrySettingID)
if err != nil {
Expand Down Expand Up @@ -76,7 +83,7 @@ func InstallRancherMonitoringChart(client *rancher.Client, installOptions *Insta
installOptions.Version,
installOptions.Cluster.ID,
installOptions.Cluster.Name,
serverSetting.Value,
serverURL,
rancherChartsName,
installOptions.ProjectID,
registrySetting.Value,
Expand All @@ -87,7 +94,7 @@ func InstallRancherMonitoringChart(client *rancher.Client, installOptions *Insta
installOptions.Version,
installOptions.Cluster.ID,
installOptions.Cluster.Name,
serverSetting.Value,
serverURL,
rancherChartsName,
installOptions.ProjectID,
registrySetting.Value,
Expand Down

0 comments on commit f566937

Please sign in to comment.