Skip to content

Commit

Permalink
feat(ci): Login to Kubernetes clusters via Rancher
Browse files Browse the repository at this point in the history
  • Loading branch information
samcm committed Jan 22, 2024
1 parent 55eb8b6 commit 131a891
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/_shared-run-kubernetes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ jobs:
echo "${{ secrets.KUBECONFIG }}" > $HOME/.kube/config
export KUBECONFIG=$HOME/.kube/config
chmod 600 $HOME/.kube/config
kubectl config set-context --current --namespace=${{ inputs.kubeCluster }}
kubectl config set-context --current
- name: Setup Kurtosis
shell: bash
run: |
Expand Down
45 changes: 39 additions & 6 deletions .github/workflows/_shared-run.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ on:
description: "The test configuration in json format."
required: true
secrets:
KUBECONFIG:
description: 'Kubernetes config'
required: false

RANCHER_TOKEN:
description: "The rancher token to login to the rancher server."
RANCHER_URL:
description: "The rancher url to login to the rancher server."
jobs:
get_test:
name: "Parse test configuration"
Expand Down Expand Up @@ -74,6 +74,37 @@ jobs:
echo "$assertoor_tests" | yq -P
echo "assertoor_tests=$(echo "$assertoor_tests")" >> $GITHUB_OUTPUT
generate_kubeconfig:
name: "Generate kubeconfig"
runs-on: ubuntu-latest
if: ${{ needs.get_test.outputs.backend == 'kubernetes' }}
steps:
- name: "Install rancher CLI"
shell: bash
run: |
curl -L https://github.com/rancher/cli/releases/download/v2.8.0/rancher-darwin-amd64-v2.8.0.tar.gz | tar xvz
mv ./rancher-v2.8.0/rancher /usr/local/bin/rancher
- name: Login to rancher
shell: bash
run: |
rancher login --token "${{ secrets.RANCHER_TOKEN }}" "${{ secrets.RANCHER_URL }}"
- name: Login to kubernetes cluster
shell: bash
run: |
rancher kubectl config use-context "$${{ needs.get_test.outputs.kubernetes_cluster }}"
- name: Check kubernetes cluster
shell: bash
run: |
set -e
rancher kubectl get pods > /dev/null
- name: Generate kubeconfig
id: kubeconfig
shell: bash
run: |
rancher kubectl config view --raw > kubeconfig
echo "$KUBECONFIG" > kubeconfig
echo "::set-output name=kubeconfig::$(cat kubeconfig)"
run_with_docker:
needs: get_test
if: ${{ needs.get_test.outputs.backend == 'docker' }}
Expand All @@ -92,7 +123,9 @@ jobs:
assertoor_tests: ${{ needs.get_test.outputs.assertoor_tests }}

run_with_kubernetes:
needs: get_test
needs:
- get_test
- generate_kubeconfig
if: ${{ needs.get_test.outputs.backend == 'kubernetes' }}
strategy:
fail-fast: false
Expand All @@ -110,6 +143,6 @@ jobs:
clients: ${{ needs.get_test.outputs.clients }}
assertoor_tests: ${{ needs.get_test.outputs.assertoor_tests }}
secrets:
KUBECONFIG: ${{ secrets.KUBECONFIG }}
KUBECONFIG: ${{ needs.generate_kubeconfig.outputs.kubeconfig }}


0 comments on commit 131a891

Please sign in to comment.