Skip to content

Commit

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

delete_ocp_cluster=false
  • Loading branch information
leiicamundi committed May 16, 2024
1 parent aeb7745 commit 6954e59
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 24 deletions.
21 changes: 1 addition & 20 deletions .github/actions/rosa-create-cluster/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -171,23 +171,4 @@ runs:
rosa describe cluster --output=json -c "${{ steps.apply.outputs.cluster_id }}"
export server_api=$(rosa describe cluster --output=json -c "${{ steps.apply.outputs.cluster_id }}" | jq -r '.api.url')
echo "server_api=$server_api"
echo "server_api=$server_api" >> "$GITHUB_OUTPUT"
- name: Generate kubeconfig
shell: bash
id: kube_config
run: |
oc login --username ${{ inputs.admin-username }} --password ${{ inputs.admin-password }} "${{ steps.cluster_info.outputs.server_api }}"
oc whoami
kubectl config rename-context $(oc config current-context) "${{ inputs.cluster-name }}"
kubectl config use "${{ inputs.cluster-name }}"
- name: Create namespace if not exists
shell: bash
run: |
if ! oc get namespace "${{ inputs.namespace }}"; then
oc new-project "${{ inputs.namespace }}"
else
echo "Namespace '${{ inputs.namespace }}' already exists"
fi
echo "server_api=$server_api" >> "$GITHUB_OUTPUT"
30 changes: 26 additions & 4 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ env:
AWS_PROFILE: "infex"
AWS_REGION: "eu-west-2"
TF_S3_BUCKET: "camunda-tf-rosa"
OCP_ADMIN_USERNAME: "cluster-admin"
OCP_NAMESPACE: "myns"

jobs:

Expand Down Expand Up @@ -83,15 +85,35 @@ jobs:
- name: Create Cluster
timeout-minutes: 125
uses: ./.github/actions/rosa-create-cluster
id: create_cluster
with:
rh-token: ${{ steps.secrets.outputs.RH_OPENSHIFT_TOKEN }}
cluster-name: "${{ steps.commit_info.outputs.cluster_name }}"
admin-username: "cluster-admin"
admin-password: "${{ steps.secrets.outputs.CI_OPENSHIFT_MAIN_PASSWORD }}"
cluster-name: ${{ steps.commit_info.outputs.cluster_name }}
admin-username: ${{ env.OCP_ADMIN_USERNAME }}
admin-password: ${{ steps.secrets.outputs.CI_OPENSHIFT_MAIN_PASSWORD }}
aws-region: ${{ env.AWS_REGION }}
namespace: "myns"
namespace: ${{ env.OCP_NAMESPACE }}
s3-backend-bucket: ${{ env.TF_S3_BUCKET }}

- name: Generate kubeconfig
shell: bash
id: kube_config
run: |
oc login --username ${{ env.OCP_ADMIN_USERNAME }} --password ${{ steps.secrets.outputs.CI_OPENSHIFT_MAIN_PASSWORD }} "${{ steps.create_cluster.outputs.openshift-server-api }}"
oc whoami
kubectl config rename-context $(oc config current-context) "${{ steps.commit_info.outputs.cluster_name }}"
kubectl config use "${{ steps.commit_info.outputs.cluster_name }}"
- name: Create namespace if not exists
shell: bash
run: |
if ! oc get namespace "${{ env.OCP_NAMESPACE }}"; then
oc new-project "${{ env.OCP_NAMESPACE }}"
else
echo "Namespace '${{ env.OCP_NAMESPACE }}' already exists"
fi
- name: Delete Cluster
timeout-minutes: 125
if: always() && steps.commit_info.outputs.delete_cluster == 'true'
Expand Down

0 comments on commit 6954e59

Please sign in to comment.