google-github-actions / get-gke-credentials

A GitHub Action that configure authentication to a GKE cluster.
https://cloud.google.com/gke
Apache License 2.0
100 stars 41 forks source link

Does not work on Mac #276

Closed franciscocpg closed 2 months ago

franciscocpg commented 1 year ago

TL;DR

Trying to use it on Mac (runs-on: macos-latest) I'm seeing the following error, but the same workflow works on ubuntu-latest:

kubectl: command not found

Expected behavior

I expected kubectl to be installed and configured on Mac

Observed behavior

It's not installed and configured on Mac

Action YAML

It's a composite action that calls another internal action to configure GKE.

Main

on:
  pull_request:
  push:
    branches:
      - main

name: CI
jobs:
  build:
    name: Build
    runs-on: ubuntu-latest
    permissions:
      contents: read
      id-token: write

    steps:
    - name: Checkout
      uses: actions/checkout@v3

    - name: Check path names
      run: make check-path-names

    - name: Setup go
      uses: ./.github/actions/setup_go

    - name: Check dependencies
      run: make check-dependencies

    - name: Check format imports
      run: make check-format-imports

    - name: Build and lint go files
      run: make lint-all-platforms

    - name: Run integration tests on Ubuntu
      uses: ./.github/actions/integration_tests

  integration-tests-macos:
    name: Integration tests on MacOS
    runs-on: macos-latest
    needs: build
    permissions:
      contents: read
      id-token: write

    steps:
    - name: Checkout
      uses: actions/checkout@v3

    - name: Setup go
      uses: ./.github/actions/setup_go

    - name: Run integration tests
      uses: ./.github/actions/integration_tests

composite action calls an internal action

name: Setup integration tests
description: Setup and run integration tests
runs:
  using: composite
  steps:
    - name: Setup GKE
      uses: jusbrasil/gh-actions/actions/gke/setup@v0
      with:
        gcloud-configure-docker: false

    - shell: bash
      name: Debug
      run: kubectl version

    - name: Setup asdf
      uses: asdf-vm/actions/setup@v2

    - shell: bash
      name: Run integration tests
      run: make integration-tests

internal action

name: GKE Setup
description: It configures authentication to gcloud and the use of kubectl and docker.

inputs:
  gcloud-sdk-version:
    description: The version to install the gcloud sdk
    required: false
    default: "412.0.0"
  gcloud-sdk-project-id:
    description: The project id to set the gcloud sdk
    required: false
    default: jusbrasil-155317
  gcloud-workload-identity-provider:
    description: The workload identity provider to use to authenticate to google cloud
    required: false
    default: projects/939978079517/locations/global/workloadIdentityPools/github-actions/providers/github-actions-org
  gcloud-service-account:
    description: The service account to use to authenticate to google cloud
    required: false
    default: github-actions-org@jusbrasil-155317.iam.gserviceaccount.com
  gke-cluster-name:
    description: The cluster name to configure gke credentials
    required: false
    default: kube-0
  gke-location:
    description: The location to configure gke credentials
    required: false
    default: us-central1-c
  gcloud-configure-docker:
    description: If it should configure gcloud to use docker
    required: false
    default: "true"
  gcloud-docker-registries-to-configure:
    description: A comma-separated list of registries to configure the credential helper for
    required: false
    default: ""
  gcloud-inject-service-account-access-token:
    description: If it should inject the environment variable SA_ACCESS_TOKEN access token for the specified gcloud-service-account
    required: false
    default: "false"

runs:
  using: composite
  steps:
    - name: Authenticate to Google Cloud
      uses: google-github-actions/auth@v1
      with:
        workload_identity_provider: ${{ inputs.gcloud-workload-identity-provider }}
        service_account: ${{ inputs.gcloud-service-account }}

    - name: Setup Google Cloud
      uses: google-github-actions/setup-gcloud@v0
      with:
        version: ${{ inputs.gcloud-sdk-version }}
        project_id: ${{ inputs.gcloud-project-id }}

    - name: Configure GKE credentials
      uses: google-github-actions/get-gke-credentials@v1
      with:
        cluster_name: ${{ inputs.gke-cluster-name }}
        location: ${{ inputs.gke-location }}

    - name: Configure gcloud docker
      if: inputs.gcloud-configure-docker == 'true'
      shell: bash
      run: gcloud --quiet auth configure-docker ${{ inputs.gcloud-docker-registries-to-configure }}

    - name: Inject SA_ACCESS_TOKEN environment variable
      if: inputs.gcloud-inject-service-account-access-token == 'true'
      shell: bash
      run: |
        SA_ACCESS_TOKEN=$(gcloud auth print-access-token)
        echo "::add-mask::$SA_ACCESS_TOKEN"
        echo "SA_ACCESS_TOKEN=$SA_ACCESS_TOKEN" >> $GITHUB_ENV

Log output

When running on Mac I see the following error:

/Users/runner/work/_temp/132731f4-33cd-45cd-a9c3-4945aa94dad2.sh: line 1: kubectl: command not found

Additional information

No response

sethvargo commented 2 months ago

Hi @franciscocpg - this GitHub Action does not install kubectl, it only configures the environment with the files that kubectl expects. There are many ways to install kubectl (and different versions) which is outside the scope of this action.