Skip to content

Commit

Permalink
init ocp test
Browse files Browse the repository at this point in the history
  • Loading branch information
leiicamundi committed May 15, 2024
1 parent 7aeb549 commit 2f5cb7c
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 17 deletions.
25 changes: 11 additions & 14 deletions .github/actions/rosa-create-cluster/action.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
name: Deploy ROSA HCP Cluster

description: |
This GitHub Action automates the deployment of a ROSA (Red Hat OpenShift Service on AWS) cluster using Terraform.
This GitHub Action automates the deployment of a ROSA (Red Hat OpenShift Service on AWS) cluster using Terraform with a dedicated namespace.
This action will also install oc, awscli, rosa cli.
This action also set the current kube context on the created namespace.
inputs:
aws-access-key-id:
description: 'AWS Access Key ID'
required: true
aws-secret-access-key:
description: 'AWS Secret Access Key'
required: true
aws-profile:
description: 'AWS profile to use'
required: false
rh-token:
description: 'Red Hat Hybrid Cloud Console Token'
required: true
Expand All @@ -35,6 +28,10 @@ inputs:
description: 'Version of the ROSA CLI to use'
required: true
default: "latest"
awscli-version:
description: 'Version of the aws cli to use'
required: true
default: "latest"
oc-version:
description: 'Version of the oc cli to install'
required: true
Expand All @@ -58,7 +55,7 @@ outputs:

openshift-cluster-id:
description: 'The ID of the deployed ROSA cluster'
value: ${{ steps.cluster_id.outputs.cluster_id }}
value: ${{ steps.apply.outputs.cluster_id }}

terraform-state-url:
description: 'URL of the Terraform state file in the S3 bucket'
Expand Down Expand Up @@ -102,7 +99,7 @@ runs:
- name: Install aws-cli
shell: bash
run: |
python3 -m pip install awscli
python3 -m pip install "awscli==${{ inputs.awscli-version }}"
- name: Check if S3 bucket exists
id: create-s3-bucket
Expand Down Expand Up @@ -154,7 +151,7 @@ runs:
cd .github/actions/rosa-create-cluster/modules/rosa-hcp
terraform apply -no-color rosa.plan
export cluster_id=$(terraform output cluster_id)
export cluster_id="$(terraform output -raw cluster_id)"
echo "cluster_id=$cluster_id" >> "$GITHUB_OUTPUT"
- name: Retrieve cluster information
Expand All @@ -167,7 +164,7 @@ runs:
shell: bash
id: kube_config
run: |
export SERVER_API=$(rosa describe cluster --output=json -c "${{ steps.apply.outputs.cluster_id }}" | jq -r '.api.url')
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"
oc login --username "${{ inputs.admin-username }}" --password "${{ inputs.admin-password }}" --server=$SERVER_API
Expand Down
66 changes: 66 additions & 0 deletions .github/actions/rosa-delete-cluster/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Delete ROSA HCP Cluster

description: |
This GitHub Action automates the deletion of a ROSA (Red Hat OpenShift Service on AWS) cluster using Terraform.
This action will also uninstall oc, awscli, rosa cli.
inputs:
rh-token:
description: 'Red Hat Hybrid Cloud Console Token'
required: true
cluster-name:
description: 'Name of the ROSA cluster to delete'
required: true
aws-region:
description: 'AWS region where the ROSA cluster is deployed'
required: true
s3-backend-bucket:
description: 'Name of the S3 bucket where the Terraform state is stored'
required: true
awscli-version:
description: 'Version of the aws cli to use'
required: true
default: "latest"

runs:
using: 'composite'
steps:
- name: Checkout Repository
uses: actions/checkout@v2

- name: Install Terraform
uses: hashicorp/setup-terraform@v3

- name: Set Terraform variables
shell: bash
id: set-terraform-variables
run: |
export TFSTATE_BUCKET="${{ inputs.s3-backend-bucket }}"
export TFSTATE_REGION="${{ inputs.aws-region }}"
export TFSTATE_KEY="tfstate-${{ inputs.cluster-name }}/${{ inputs.cluster-name }}.tfstate"
echo "TFSTATE_BUCKET=${TFSTATE_BUCKET}" >> "$GITHUB_OUTPUT"
echo "TFSTATE_REGION=${TFSTATE_REGION}" >> "$GITHUB_OUTPUT"
echo "TFSTATE_KEY=${TFSTATE_KEY}" >> "$GITHUB_OUTPUT"
- name: Terraform Init
shell: bash
id: init
run: |
cd .github/actions/rosa-delete-cluster/modules/rosa-hcp
terraform init -backend-config="bucket=${{ steps.set-terraform-variables.outputs.TFSTATE_BUCKET }}" -backend-config="key=${{ steps.set-terraform-variables.outputs.TFSTATE_KEY }}" -backend-config="region=${{ steps.set-terraform-variables.outputs.TFSTATE_REGION }}"
terraform validate -no-color
- name: Terraform Plan Destroy
shell: bash
id: plan-destroy
run: |
cd .github/actions/rosa-delete-cluster/modules/rosa-hcp
terraform plan -destroy -no-color -out rosa-destroy.plan -var "cluster_name=${{ inputs.cluster-name }}"
- name: Terraform Apply Destroy
shell: bash
id: apply-destroy
run: |
cd .github/actions/rosa-delete-cluster/modules/rosa-hcp
terraform apply -destroy -no-color rosa-destroy.plan
1 change: 1 addition & 0 deletions .github/actions/rosa-delete-cluster/modules
13 changes: 10 additions & 3 deletions .github/workflows/tests-ocp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,23 @@ jobs:
aws configure set aws_secret_access_key ${{ steps.secrets.outputs.AWS_SECRET_KEY }} --profile ${{ env.AWS_PROFILE }}
aws configure set region ${{ env.AWS_REGION }} --profile ${{ env.AWS_PROFILE }}
- name: Launch test
- name: Create Cluster
timeout-minutes: 125
uses: ./.github/actions/rosa-create-cluster
with:
aws-access-key-id: ${{ steps.secrets.outputs.AWS_ACCESS_KEY }}
aws-secret-access-key: ${{ steps.secrets.outputs.AWS_SECRET_KEY }}
rh-token: ${{ steps.secrets.outputs.RH_OPENSHIFT_TOKEN }}
cluster-name: "mycluster"
admin-password: "myPassword1838!!&"
admin-username: "myadmin"
aws-region: ${{ env.AWS_REGION }}
namespace: "myns"
s3-backend-bucket: "378499mybucket"

- name: Delete Cluster
timeout-minutes: 125
uses: ./.github/actions/rosa-delete-cluster
with:
rh-token: ${{ steps.secrets.outputs.RH_OPENSHIFT_TOKEN }}
cluster-name: "mycluster"
aws-region: ${{ env.AWS_REGION }}
s3-backend-bucket: "378499mybucket"

0 comments on commit 2f5cb7c

Please sign in to comment.