|
| 1 | +name: "Copilot - AKS Access" |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + resource_group: |
| 7 | + description: 'Azure Resource Group' |
| 8 | + required: true |
| 9 | + default: 'rg-anyscale-demo' |
| 10 | + cluster_name: |
| 11 | + description: 'AKS Cluster Name' |
| 12 | + required: true |
| 13 | + default: 'aks-eastus2' |
| 14 | + issues: |
| 15 | + types: [labeled] |
| 16 | + |
| 17 | +env: |
| 18 | + ARM_CLIENT_ID: ${{ secrets.ARM_CLIENT_ID }} |
| 19 | + ARM_SUBSCRIPTION_ID: ${{ secrets.ARM_SUBSCRIPTION_ID }} |
| 20 | + ARM_TENANT_ID: ${{ secrets.ARM_TENANT_ID }} |
| 21 | + ARM_USE_OIDC: true |
| 22 | + |
| 23 | +permissions: |
| 24 | + id-token: write |
| 25 | + contents: read |
| 26 | + issues: write |
| 27 | + |
| 28 | +jobs: |
| 29 | + copilot-setup-steps: |
| 30 | + runs-on: ubuntu-latest |
| 31 | + environment: copilot |
| 32 | + # Only run on label events if the label starts with 'cluster/' |
| 33 | + if: github.event_name == 'workflow_dispatch' || startsWith(github.event.label.name, 'cluster/') |
| 34 | + |
| 35 | + # Job-level permissions override workflow-level, so you must include id-token here |
| 36 | + permissions: |
| 37 | + contents: write |
| 38 | + id-token: write # Required for Azure federated identity |
| 39 | + |
| 40 | + steps: |
| 41 | + - name: Checkout code |
| 42 | + uses: actions/checkout@v5 |
| 43 | + |
| 44 | + - name: Parse cluster info from label or inputs |
| 45 | + id: cluster-info |
| 46 | + run: | |
| 47 | + if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then |
| 48 | + # Use workflow inputs |
| 49 | + echo "RESOURCE_GROUP=${{ github.event.inputs.resource_group }}" >> $GITHUB_OUTPUT |
| 50 | + echo "CLUSTER_NAME=${{ github.event.inputs.cluster_name }}" >> $GITHUB_OUTPUT |
| 51 | + echo "Using workflow inputs: RG=${{ github.event.inputs.resource_group }}, Cluster=${{ github.event.inputs.cluster_name }}" |
| 52 | + else |
| 53 | + # Parse from label: cluster/<resource-group>/<cluster-name> |
| 54 | + LABEL="${{ github.event.label.name }}" |
| 55 | + echo "Parsing label: $LABEL" |
| 56 | + |
| 57 | + # Extract resource group and cluster name from label |
| 58 | + # Expected format: cluster/<resource-group>/<cluster-name> |
| 59 | + RESOURCE_GROUP=$(echo "$LABEL" | cut -d'/' -f2) |
| 60 | + CLUSTER_NAME=$(echo "$LABEL" | cut -d'/' -f3) |
| 61 | + |
| 62 | + if [ -z "$RESOURCE_GROUP" ] || [ -z "$CLUSTER_NAME" ]; then |
| 63 | + echo "ERROR: Invalid label format. Expected: cluster/<resource-group>/<cluster-name>" |
| 64 | + echo "Got: $LABEL" |
| 65 | + exit 1 |
| 66 | + fi |
| 67 | + |
| 68 | + echo "RESOURCE_GROUP=$RESOURCE_GROUP" >> $GITHUB_OUTPUT |
| 69 | + echo "CLUSTER_NAME=$CLUSTER_NAME" >> $GITHUB_OUTPUT |
| 70 | + echo "Parsed from label: RG=$RESOURCE_GROUP, Cluster=$CLUSTER_NAME" |
| 71 | + fi |
| 72 | +
|
| 73 | + - name: Azure CLI Login |
| 74 | + uses: azure/login@v2 |
| 75 | + with: |
| 76 | + client-id: ${{ secrets.ARM_CLIENT_ID }} |
| 77 | + tenant-id: ${{ secrets.ARM_TENANT_ID }} |
| 78 | + subscription-id: ${{ secrets.ARM_SUBSCRIPTION_ID }} |
| 79 | + |
| 80 | + - name: Verify Azure Login |
| 81 | + run: | |
| 82 | + echo "Verifying Azure authentication..." |
| 83 | + az account show |
| 84 | + |
| 85 | + - name: Get AKS Credentials |
| 86 | + run: | |
| 87 | + echo "Fetching kubeconfig for cluster ${{ steps.cluster-info.outputs.CLUSTER_NAME }}..." |
| 88 | + az aks get-credentials \ |
| 89 | + --resource-group ${{ steps.cluster-info.outputs.RESOURCE_GROUP }} \ |
| 90 | + --name ${{ steps.cluster-info.outputs.CLUSTER_NAME }} \ |
| 91 | + --overwrite-existing |
| 92 | + echo "Kubeconfig fetched successfully!" |
| 93 | + - name: Check cluster |
| 94 | + run: | |
| 95 | + az aks agent "Is my cluster healthy?" --resource-group ${{ steps.cluster-info.outputs.RESOURCE_GROUP }} --name ${{ steps.cluster-info.outputs.CLUSTER_NAME }} --namespace aks-mcp --no-interactive |
0 commit comments