Skip to content

Add missing gke-gcloud-auth-plugin component for Google Cloud SDK#167

Merged
paolomainardi merged 4 commits into
masterfrom
copilot/fix-166
Sep 2, 2025
Merged

Add missing gke-gcloud-auth-plugin component for Google Cloud SDK#167
paolomainardi merged 4 commits into
masterfrom
copilot/fix-166

Conversation

Copilot AI commented Sep 2, 2025

Copy link
Copy Markdown
Contributor

User description

This PR resolves the issue where the gke-gcloud-auth-plugin component was missing after fresh Sparkdock provisioning, preventing proper GKE authentication.

Changes Made

Ansible Integration

  • Added automated installation of gke-gcloud-auth-plugin component after Google Cloud SDK cask installation
  • Configured proper environment sourcing for both Intel and ARM Mac architectures
  • Added idempotent .zshrc configuration using Ansible's lineinfile module to include Google Cloud SDK paths and shell completion

SparkJust Task

  • Implemented system-gcloud-reconfigure task in the 'system' group for manual reconfiguration
  • Handles complete Google Cloud SDK installation and component setup
  • Includes verification steps to ensure successful installation
  • Follows project shell script standards with proper error handling

Documentation

  • Added Google Cloud SDK configuration section to README.md
  • Provided clear usage instructions for both automatic and manual configuration
  • Included verification commands for users

Usage

After provisioning, users can verify the plugin is installed:

gke-gcloud-auth-plugin --version

For manual reconfiguration:

sjust system-gcloud-reconfigure

The implementation ensures that both fresh installations and existing setups can properly authenticate with GKE clusters without manual intervention.

Fixes #166.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • esm.ubuntu.com
    • Triggering command: /usr/lib/apt/methods/https (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.


PR Type

Enhancement


Description

  • Add automated gke-gcloud-auth-plugin installation during provisioning

  • Implement manual reconfiguration task for Google Cloud SDK

  • Configure shell environment with proper PATH and completion

  • Add comprehensive documentation for Google Cloud SDK setup


Changes walkthrough 📝

Relevant files
Documentation
README.md
Document Google Cloud SDK configuration                                   

README.md

  • Add Google Cloud SDK configuration section with usage instructions
  • Document system-gcloud-reconfigure command and verification steps
  • Include manual reconfiguration and plugin verification examples
  • +23/-0   
    Enhancement
    base.yml
    Automate Google Cloud SDK plugin installation                       

    ansible/macos/macos/base.yml

  • Add automated installation of gke-gcloud-auth-plugin component
  • Configure Google Cloud SDK environment sourcing for Intel/ARM Macs
  • Add idempotent .zshrc configuration with PATH and completion setup
  • Include verification steps for successful plugin installation
  • +43/-0   
    00-default.just
    Add manual Google Cloud SDK reconfiguration task                 

    sjust/recipes/00-default.just

  • Implement system-gcloud-reconfigure task for manual Google Cloud SDK
    setup
  • Add complete installation, configuration, and verification workflow
  • Include proper error handling and shell environment configuration
  • Add .zshrc updates for PATH and completion integration
  • +65/-0   

    Need help?
  • Type /help how to ... in the comments thread for any questions about PR-Agent usage.
  • Check out the documentation for more information.
  • Copilot AI and others added 2 commits September 2, 2025 16:45
    Co-authored-by: paolomainardi <8747+paolomainardi@users.noreply.github.com>
    Co-authored-by: paolomainardi <8747+paolomainardi@users.noreply.github.com>
    Copilot AI changed the title [WIP] Missing gke gcloud auth plugin Add missing gke-gcloud-auth-plugin component for Google Cloud SDK Sep 2, 2025
    Copilot AI requested a review from paolomainardi September 2, 2025 16:48

    @paolomainardi paolomainardi left a comment

    Copy link
    Copy Markdown
    Member

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    👍

    @paolomainardi paolomainardi marked this pull request as ready for review September 2, 2025 16:52
    Copilot AI review requested due to automatic review settings September 2, 2025 16:52
    @paolomainardi

    Copy link
    Copy Markdown
    Member

    /describe

    @paolomainardi

    Copy link
    Copy Markdown
    Member

    /review

    @paolomainardi

    Copy link
    Copy Markdown
    Member

    /improve

    @sparkfabrik-ai-bot

    sparkfabrik-ai-bot Bot commented Sep 2, 2025

    Copy link
    Copy Markdown

    PR Code Suggestions ✨

    Latest suggestions up to c6b009e
    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Impact
    General
    Add error handling for installation

    Add error handling for the Homebrew installation command. If the installation fails,
    the script should exit with an error message rather than continuing with potentially
    broken state.

    sjust/recipes/00-default.just [153-156]

     # Install gcloud-cli via Homebrew if not already installed
     if ! brew list --cask google-cloud-sdk >/dev/null 2>&1; then
         echo "Installing Google Cloud SDK via Homebrew..."
    -    brew install --cask google-cloud-sdk
    +    if ! brew install --cask google-cloud-sdk; then
    +        echo "❌ Failed to install Google Cloud SDK via Homebrew"
    +        exit 1
    +    fi
     fi
    Suggestion importance[1-10]: 7

    __

    Why: Good suggestion to add error handling for the brew install command. This prevents the script from continuing with a potentially broken state if the installation fails.

    Medium
    Add failure condition for component installation

    Add error handling for the gcloud component installation. The task should fail if
    the component installation fails, providing clear feedback about the failure.

    ansible/macos/macos/base.yml [119-126]

     - name: Install gke-gcloud-auth-plugin component
       shell: |
         source {{ homebrew_prefix }}/share/google-cloud-sdk/path.zsh.inc
         gcloud components install gke-gcloud-auth-plugin --quiet
       register: gcloud_component_install
       changed_when: gcloud_component_install.rc == 0
    +  failed_when: gcloud_component_install.rc != 0
       when: gcloud_installed.rc == 0
       become: false
    Suggestion importance[1-10]: 6

    __

    Why: Valid improvement to add explicit failure handling for the gcloud components install command. This makes the Ansible task more robust by properly failing when the component installation fails.

    Low
    Improve duplicate detection for configuration lines

    The grep check only looks for one pattern but appends multiple lines. This could
    result in partial duplicates if only some lines exist. Check for all critical
    patterns or use a more robust detection method.

    sjust/recipes/00-default.just [193-201]

     # Check if Google Cloud SDK lines are already in zshrc
    -if ! grep -q "google-cloud-sdk/path.zsh.inc" "${ZSHRC_FILE}"; then
    +if ! grep -q "google-cloud-sdk/path.zsh.inc" "${ZSHRC_FILE}" || ! grep -q "google-cloud-sdk/completion.zsh.inc" "${ZSHRC_FILE}"; then
         {
             echo ""
             echo "# The next line updates PATH for the Google Cloud SDK."
             echo "if [ -f '${HOMEBREW_PREFIX}/share/google-cloud-sdk/path.zsh.inc' ]; then . '${HOMEBREW_PREFIX}/share/google-cloud-sdk/path.zsh.inc'; fi"
             echo ""
             echo "# The next line enables shell command completion for gcloud."
             echo "if [ -f '${HOMEBREW_PREFIX}/share/google-cloud-sdk/completion.zsh.inc' ]; then . '${HOMEBREW_PREFIX}/share/google-cloud-sdk/completion.zsh.inc'; fi"
         } >> "${ZSHRC_FILE}"
    Suggestion importance[1-10]: 5

    __

    Why: The suggestion correctly identifies that checking only one pattern could lead to partial duplicates. However, the improved logic could still append duplicate lines if only one of the patterns exists.

    Low

    Previous suggestions

    Suggestions up to commit c6b009e
    CategorySuggestion                                                                                                                                    Impact
    General
    Use blockinfile for cleaner configuration

    Adding empty lines and duplicate comments can create messy .zshrc files on repeated
    runs. Use a block insertion approach to maintain cleaner configuration.

    ansible/macos/macos/base.yml [137-150]

     - name: Add Google Cloud SDK to user's zshrc
    -  lineinfile:
    +  blockinfile:
         path: "{{ ansible_env.HOME }}/.zshrc"
    -    line: "{{ item }}"
    +    marker: "# {mark} ANSIBLE MANAGED BLOCK - Google Cloud SDK"
    +    block: |
    +      # The next line updates PATH for the Google Cloud SDK.
    +      if [ -f '{{ homebrew_prefix }}/share/google-cloud-sdk/path.zsh.inc' ]; then . '{{ homebrew_prefix }}/share/google-cloud-sdk/path.zsh.inc'; fi
    +      
    +      # The next line enables shell command completion for gcloud.
    +      if [ -f '{{ homebrew_prefix }}/share/google-cloud-sdk/completion.zsh.inc' ]; then . '{{ homebrew_prefix }}/share/google-cloud-sdk/completion.zsh.inc'; fi
         create: yes
         backup: yes
    -  loop:
    -    - "# The next line updates PATH for the Google Cloud SDK."
    -    - "if [ -f '{{ homebrew_prefix }}/share/google-cloud-sdk/path.zsh.inc' ]; then . '{{ homebrew_prefix }}/share/google-cloud-sdk/path.zsh.inc'; fi"
    -    - ""
    -    - "# The next line enables shell command completion for gcloud."
    -    - "if [ -f '{{ homebrew_prefix }}/share/google-cloud-sdk/completion.zsh.inc' ]; then . '{{ homebrew_prefix }}/share/google-cloud-sdk/completion.zsh.inc'; fi"
    Suggestion importance[1-10]: 8

    __

    Why: Excellent suggestion to use blockinfile instead of lineinfile with a loop. This prevents duplicate entries and messy .zshrc files on repeated runs, significantly improving the task's idempotency and maintainability.

    Medium
    Check component installation status first

    The task should check if the component is already installed before attempting
    installation. This prevents unnecessary reinstallation and improves idempotency.

    ansible/macos/macos/base.yml [119-126]

     - name: Install gke-gcloud-auth-plugin component
       shell: |
         source {{ homebrew_prefix }}/share/google-cloud-sdk/path.zsh.inc
    -    gcloud components install gke-gcloud-auth-plugin --quiet
    +    if ! gcloud components list --filter="id:gke-gcloud-auth-plugin AND state:Installed" --format="value(id)" | grep -q "gke-gcloud-auth-plugin"; then
    +      gcloud components install gke-gcloud-auth-plugin --quiet
    +    fi
       register: gcloud_component_install
       changed_when: gcloud_component_install.rc == 0
       when: gcloud_installed.rc == 0
       become: false
    Suggestion importance[1-10]: 7

    __

    Why: Good suggestion to improve idempotency by checking if gke-gcloud-auth-plugin is already installed before attempting installation. This prevents unnecessary operations and follows Ansible best practices.

    Medium

    Copilot AI left a comment

    Copy link
    Copy Markdown
    Contributor

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    Pull Request Overview

    This PR adds automated installation and configuration of the gke-gcloud-auth-plugin component for Google Cloud SDK to resolve GKE authentication issues after fresh Sparkdock provisioning.

    • Adds Ansible automation to install the GKE auth plugin component when Google Cloud SDK is provisioned
    • Implements a manual reconfiguration task via SparkJust for troubleshooting scenarios
    • Updates documentation with Google Cloud SDK configuration instructions

    Reviewed Changes

    Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

    File Description
    ansible/macos/macos/base.yml Adds Ansible block to automatically install gke-gcloud-auth-plugin component and configure .zshrc when google-cloud-sdk cask is installed
    sjust/recipes/00-default.just Implements system-gcloud-reconfigure task for manual Google Cloud SDK setup and component installation
    README.md Documents Google Cloud SDK configuration capabilities and usage instructions

    Comment on lines +138 to +148
    lineinfile:
    path: "{{ ansible_env.HOME }}/.zshrc"
    line: "{{ item }}"
    create: yes
    backup: yes
    loop:
    - "# The next line updates PATH for the Google Cloud SDK."
    - "if [ -f '{{ homebrew_prefix }}/share/google-cloud-sdk/path.zsh.inc' ]; then . '{{ homebrew_prefix }}/share/google-cloud-sdk/path.zsh.inc'; fi"
    - ""
    - "# The next line enables shell command completion for gcloud."
    - "if [ -f '{{ homebrew_prefix }}/share/google-cloud-sdk/completion.zsh.inc' ]; then . '{{ homebrew_prefix }}/share/google-cloud-sdk/completion.zsh.inc'; fi"

    Copilot AI Sep 2, 2025

    Copy link

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    Using lineinfile with a loop to add multiple related lines can result in non-idempotent behavior and scattered placement if the file is modified externally. Consider using blockinfile instead to manage these Google Cloud SDK configuration lines as a single block, which ensures they remain together and can be updated atomically.

    Suggested change
    lineinfile:
    path: "{{ ansible_env.HOME }}/.zshrc"
    line: "{{ item }}"
    create: yes
    backup: yes
    loop:
    - "# The next line updates PATH for the Google Cloud SDK."
    - "if [ -f '{{ homebrew_prefix }}/share/google-cloud-sdk/path.zsh.inc' ]; then . '{{ homebrew_prefix }}/share/google-cloud-sdk/path.zsh.inc'; fi"
    - ""
    - "# The next line enables shell command completion for gcloud."
    - "if [ -f '{{ homebrew_prefix }}/share/google-cloud-sdk/completion.zsh.inc' ]; then . '{{ homebrew_prefix }}/share/google-cloud-sdk/completion.zsh.inc'; fi"
    blockinfile:
    path: "{{ ansible_env.HOME }}/.zshrc"
    create: yes
    backup: yes
    marker: "# {mark} ANSIBLE MANAGED BLOCK: Google Cloud SDK"
    block: |
    # The next line updates PATH for the Google Cloud SDK.
    if [ -f '{{ homebrew_prefix }}/share/google-cloud-sdk/path.zsh.inc' ]; then . '{{ homebrew_prefix }}/share/google-cloud-sdk/path.zsh.inc'; fi
    # The next line enables shell command completion for gcloud.
    if [ -f '{{ homebrew_prefix }}/share/google-cloud-sdk/completion.zsh.inc' ]; then . '{{ homebrew_prefix }}/share/google-cloud-sdk/completion.zsh.inc'; fi

    Copilot uses AI. Check for mistakes.
    Comment on lines +192 to +205
    # Check if Google Cloud SDK lines are already in zshrc
    if ! grep -q "google-cloud-sdk/path.zsh.inc" "${ZSHRC_FILE}"; then
    {
    echo ""
    echo "# The next line updates PATH for the Google Cloud SDK."
    echo "if [ -f '${HOMEBREW_PREFIX}/share/google-cloud-sdk/path.zsh.inc' ]; then . '${HOMEBREW_PREFIX}/share/google-cloud-sdk/path.zsh.inc'; fi"
    echo ""
    echo "# The next line enables shell command completion for gcloud."
    echo "if [ -f '${HOMEBREW_PREFIX}/share/google-cloud-sdk/completion.zsh.inc' ]; then . '${HOMEBREW_PREFIX}/share/google-cloud-sdk/completion.zsh.inc'; fi"
    } >> "${ZSHRC_FILE}"
    echo "✅ Added Google Cloud SDK configuration to ${ZSHRC_FILE}"
    else
    echo "✅ Google Cloud SDK configuration already present in ${ZSHRC_FILE}"
    fi

    Copilot AI Sep 2, 2025

    Copy link

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    This code includes an unnecessary else branch that only provides informational output. According to the project shell script standards, when checking if things exist, avoid using else branches unless necessary. Remove the else block and keep only the if condition for adding the configuration.

    Copilot generated this review using guidance from repository custom instructions.
    @sparkfabrik-ai-bot

    Copy link
    Copy Markdown

    PR Description updated to latest commit (c6b009e)

    @sparkfabrik-ai-bot

    sparkfabrik-ai-bot Bot commented Sep 2, 2025

    Copy link
    Copy Markdown

    PR Reviewer Guide 🔍

    (Review updated until commit c6b009e)

    Here are some key observations to aid the review process:

    🎫 Ticket compliance analysis ✅

    166 - Fully compliant

    Compliant requirements:

    • Install the missing gke-gcloud-auth-plugin component
    • Ensure the plugin is available after fresh provisioning
    • Avoid manual installation requirement
    ⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Error Handling

    The Ansible task installs the gke-gcloud-auth-plugin component but doesn't handle potential failures gracefully. If the component installation fails, the task will continue without proper error reporting.

    - name: Install gke-gcloud-auth-plugin component
      shell: |
        source {{ homebrew_prefix }}/share/google-cloud-sdk/path.zsh.inc
        gcloud components install gke-gcloud-auth-plugin --quiet
      register: gcloud_component_install
      changed_when: gcloud_component_install.rc == 0
      when: gcloud_installed.rc == 0
      become: false
    Race Condition

    The shell script checks if Google Cloud SDK configuration already exists in zshrc using grep, but then appends without atomic operations. This could lead to duplicate entries if the script is interrupted or run concurrently.

    if ! grep -q "google-cloud-sdk/path.zsh.inc" "${ZSHRC_FILE}"; then
        {
            echo ""
            echo "# The next line updates PATH for the Google Cloud SDK."
            echo "if [ -f '${HOMEBREW_PREFIX}/share/google-cloud-sdk/path.zsh.inc' ]; then . '${HOMEBREW_PREFIX}/share/google-cloud-sdk/path.zsh.inc'; fi"
            echo ""
            echo "# The next line enables shell command completion for gcloud."
            echo "if [ -f '${HOMEBREW_PREFIX}/share/google-cloud-sdk/completion.zsh.inc' ]; then . '${HOMEBREW_PREFIX}/share/google-cloud-sdk/completion.zsh.inc'; fi"
        } >> "${ZSHRC_FILE}"
        echo "✅ Added Google Cloud SDK configuration to ${ZSHRC_FILE}"
    else
        echo "✅ Google Cloud SDK configuration already present in ${ZSHRC_FILE}"
    fi

    @sparkfabrik-ai-bot

    Copy link
    Copy Markdown

    Persistent review updated to latest commit c6b009e

    @paolomainardi paolomainardi merged commit f9a1206 into master Sep 2, 2025
    1 of 3 checks passed
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Projects

    None yet

    Development

    Successfully merging this pull request may close these issues.

    Missing gke gcloud auth plugin

    3 participants