Skip to content

hack/util.sh: auto-detect macOS host IP instead of interactive prompt#7267

Open
Krishiv-Mahajan wants to merge 3 commits intokarmada-io:masterfrom
Krishiv-Mahajan:interactive_ip_prompt
Open

hack/util.sh: auto-detect macOS host IP instead of interactive prompt#7267
Krishiv-Mahajan wants to merge 3 commits intokarmada-io:masterfrom
Krishiv-Mahajan:interactive_ip_prompt

Conversation

@Krishiv-Mahajan
Copy link
Copy Markdown
Contributor

@Krishiv-Mahajan Krishiv-Mahajan commented Mar 8, 2026

What type of PR is this?
/kind bug

What this PR does / why we need it:
The util::get_macos_ipaddress function in hack/util.sh unconditionally calls read to wait for user input, even when a valid IP was already auto-detected. This causes hack/local-up-karmada.sh to hang indefinitely in any non-interactive environment (CI pipelines, GitHub Actions, background scripts).

Additionally, the detection was hardcoded to en0 (WiFi only), which silently fails for developers on USB Ethernet, Thunderbolt, or VPN — resulting in an empty HOST_IPADDRESS and member clusters unable to reach the control plane.

This PR replaces the interactive prompt with a layered auto-detection approach:
If MAC_NIC_IPADDRESS is already set (e.g. by CI), use it directly
Detect the active interface via route get default instead of hardcoding en0
If the default route interface has no IP (VPN tunnel), scan en0–en3
Fall back to 127.0.0.1 with a clear warning if all detection fails

Which issue(s) this PR fixes:
Fixes #7257
Part of #7269

Special notes for your reviewer:
Tested end-to-end on macOS 14.3 (Apple Silicon) — ./hack/local-up-karmada.sh completed without any user input and all three member clusters reached Ready status. Linux and WSL2 code paths are unaffected (change is inside the existing darwin guard).

Does this PR introduce a user-facing change?:
hack/util.sh: Fixed util::get_macos_ipaddress hanging for user input on macOS by replacing the interactive prompt with layered auto-detection from the active network interface, enabling non-interactive and CI usage.

Signed-off-by: Krishiv-Mahajan <mahajankrishiv10@gmail.com>
@karmada-bot karmada-bot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. kind/feature Categorizes issue or PR as related to a new feature. labels Mar 8, 2026
@karmada-bot
Copy link
Copy Markdown
Contributor

Welcome @Krishiv-Mahajan! It looks like this is your first PR to karmada-io/karmada 🎉

@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the hack/util.sh script by overhauling the macOS IP address detection mechanism. The primary goal is to eliminate the need for interactive user input during Karmada setup on macOS, thereby enabling seamless execution in automated environments like CI/CD pipelines. The changes introduce a more intelligent and layered approach to identifying the host IP, ensuring greater compatibility across various network configurations and improving the overall reliability of the setup process.

Highlights

  • Non-interactive macOS IP detection: The util::get_macos_ipaddress function no longer requires user input, resolving issues where hack/local-up-karmada.sh would hang indefinitely in non-interactive environments like CI pipelines.
  • Enhanced IP address auto-detection: The detection logic now prioritizes a pre-set MAC_NIC_IPADDRESS environment variable, then identifies the active network interface via the routing table, and falls back to scanning common physical interfaces (en0-en3) if the default route has no IP.
  • Improved network interface compatibility: The previous hardcoded reliance on en0 has been removed, allowing correct IP detection for users on USB Ethernet, Thunderbolt, or VPN connections.
  • Robust fallback mechanism: If all auto-detection methods fail to find a routable IP, the function now defaults to 127.0.0.1 and provides a clear warning to the user.
Changelog
  • hack/util.sh
    • Corrected a typo in a comment for the util::wait_pod_ready function.
    • Replaced the interactive prompt-based macOS IP address detection with an automated, multi-stage detection logic within util::get_macos_ipaddress.
    • Updated the MAC_NIC_IPADDRESS initialization to support pre-setting the variable.
    • Introduced logic to detect the active interface via route get default.
    • Added a fallback loop to scan en0 through en3 if the default interface lacks an IP.
    • Implemented a final fallback to 127.0.0.1 with a warning if no routable IP is found.
Activity
  • No human activity (comments, reviews, approvals) has been recorded for this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@karmada-bot karmada-bot requested review from lfbear and mrlihanbo March 8, 2026 05:53
@karmada-bot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign lfbear for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@karmada-bot karmada-bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Mar 8, 2026
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request significantly improves the user experience for macOS users by replacing an interactive prompt for the host IP address with a robust, layered auto-detection mechanism in hack/util.sh. The new logic correctly handles various network configurations, including the use of an existing environment variable, detection of the active network interface, and sensible fallbacks. This change makes the scripts non-interactive, which is a great enhancement for CI/CD pipelines and automated setups. The implementation is clean and well-commented. The only minor issue found was a typo in a comment, which has been noted for correction.

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Mar 8, 2026

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 42.00%. Comparing base (105c6ef) to head (57cb736).
⚠️ Report is 18 commits behind head on master.
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #7267      +/-   ##
==========================================
+ Coverage   41.99%   42.00%   +0.01%     
==========================================
  Files         874      874              
  Lines       53542    53539       -3     
==========================================
+ Hits        22483    22490       +7     
+ Misses      29372    29364       -8     
+ Partials     1687     1685       -2     
Flag Coverage Δ
unittests 42.00% <ø> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Signed-off-by: Krishiv-Mahajan <mahajankrishiv10@gmail.com>
@Krishiv-Mahajan Krishiv-Mahajan force-pushed the interactive_ip_prompt branch from f8d1139 to 619dbc4 Compare March 8, 2026 10:41
@Krishiv-Mahajan Krishiv-Mahajan marked this pull request as ready for review March 9, 2026 12:09
Copilot AI review requested due to automatic review settings March 9, 2026 12:09
@karmada-bot karmada-bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Mar 9, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates the macOS host IP discovery in hack/util.sh to avoid interactive prompts and better handle non-en0 interfaces, preventing hack/local-up-karmada.sh from hanging in non-interactive environments.

Changes:

  • Remove interactive read prompt from util::get_macos_ipaddress and use layered auto-detection instead.
  • Detect the default-route interface IP (via route get default) and fall back to scanning en0en3.
  • Add a last-resort fallback behavior when no IP can be detected.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

- Make iface variable local to prevent scope pollution
- Fail fast with clear instructions instead of silent 127.0.0.1 fallback

Fixes silent cluster join failures on macOS due to non-routable loopback IP.

Signed-off-by: Krishiv-Mahajan <mahajankrishiv10@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/feature Categorizes issue or PR as related to a new feature. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Enhancement] Automate macOS IP detection in local-up script

4 participants