Skip to content

Commit

Permalink
conditional cluster definition
Browse files Browse the repository at this point in the history
ocp_cluster_name=leogit

delete_ocp_cluster=false
  • Loading branch information
leiicamundi committed May 15, 2024
1 parent 9c6c590 commit 4a0c8b5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
4 changes: 4 additions & 0 deletions .github/actions/rosa-create-cluster/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,14 @@ runs:
- name: Generate kubeconfig
shell: bash
id: kube_config
# TODO: remove sleep time
run: |
export server_api=$(rosa describe cluster --output=json -c "${{ steps.apply.outputs.cluster_id }}" | jq -r '.api.url')
echo "server_api=$server_api" >> "$GITHUB_OUTPUT"
echo "Wait some time before login"
sleep 30
oc login --username "${{ inputs.admin-username }}" --password "${{ inputs.admin-password }}" --server=$server_api
kubectl config rename-context $(oc config current-context) "${{ inputs.cluster-name }}"
kubectl config use "${{ inputs.cluster-name }}"
Expand Down
29 changes: 21 additions & 8 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,24 @@ jobs:
ref: ${{ github.head_ref }}
fetch-depth: 0

- name: Get Short GitHub SHA
id: short_git_sha
# run: echo "short_git_sha=$(git rev-parse --short HEAD)" >> "$GITHUB_OUTPUT"
# TODO: revert
run: echo "short_git_sha=36224f3" >> "$GITHUB_OUTPUT"
- name: Get OCP Cluster Name and Delete Flag
id: commit_info
run: |
COMMIT_MSG=$(git log -1 --pretty=%B)
if [[ "$COMMIT_MSG" =~ ocp_cluster_name=([^\s]+) ]]; then
CLUSTER_NAME=${BASH_REMATCH[1]}
else
CLUSTER_NAME=$(git rev-parse --short HEAD)
fi
if [[ "$COMMIT_MSG" =~ delete_ocp_cluster=false ]]; then
DELETE_CLUSTER="false"
else
DELETE_CLUSTER="true"
fi
echo "cluster_name=$CLUSTER_NAME" >> "$GITHUB_OUTPUT"
echo "delete_cluster=$DELETE_CLUSTER" >> "$GITHUB_OUTPUT"
- name: Import Secrets
id: secrets
Expand Down Expand Up @@ -67,18 +80,18 @@ jobs:
uses: ./.github/actions/rosa-create-cluster
with:
rh-token: ${{ steps.secrets.outputs.RH_OPENSHIFT_TOKEN }}
cluster-name: "tf-rosa-${{ steps.short_git_sha.outputs.short_git_sha }}"
cluster-name: "${{ steps.commit_info.outputs.cluster_name }}"
admin-password: "${{ steps.secrets.outputs.CI_OPENSHIFT_MAIN_PASSWORD }}"
aws-region: ${{ env.AWS_REGION }}
namespace: "myns"
s3-backend-bucket: ${{ env.TF_S3_BUCKET }}

- name: Delete Cluster
timeout-minutes: 125
if: always()
if: always() && steps.commit_info.outputs.delete_cluster == 'true'
uses: ./.github/actions/rosa-delete-cluster
with:
rh-token: ${{ steps.secrets.outputs.RH_OPENSHIFT_TOKEN }}
cluster-name: "tf-rosa-${{ steps.short_git_sha.outputs.short_git_sha }}"
cluster-name: "${{ steps.ocp_cluster_name.outputs.cluster_name }}"
aws-region: ${{ env.AWS_REGION }}
s3-backend-bucket: ${{ env.TF_S3_BUCKET }}

0 comments on commit 4a0c8b5

Please sign in to comment.