Skip to content

feat(hack): add flag extraction script for Karmada components#7136

Open
sarthakkjha wants to merge 2 commits intokarmada-io:masterfrom
sarthakkjha:flag-extraction-script
Open

feat(hack): add flag extraction script for Karmada components#7136
sarthakkjha wants to merge 2 commits intokarmada-io:masterfrom
sarthakkjha:flag-extraction-script

Conversation

@sarthakkjha
Copy link

What type of PR is this?

/kind feature

What this PR does / why we need it:

This PR adds hack/extract-flags.sh, a shell script that extracts command-line flags
from Karmada component binaries and outputs structured JSON.

Karmada components accept flags from multiple sources, including Karmada code,
Kubernetes dependencies, and controller-runtime. During dependency upgrades,
flags can be silently added, removed, or modified, potentially breaking user
configurations.

This script provides an initial foundation for:

  • Automated flag documentation
  • CI-based flag change detection across versions
  • Flag inventory tracking for Karmada releases

Which issue(s) this PR fixes:

Part of the LFX mentorship project:
"Create comprehensive documentation and tooling to track and document all flags
for Karmada's maintained components"

Special notes for your reviewer:

  • Script uses only standard shell utilities (bash, grep, sed, date)
  • Works on both Linux and macOS
  • Handles missing binaries gracefully with clear error messages
  • JSON output validated using python -m json.tool

Test run (macOS):

make all
./hack/extract-flags.sh --binary-dir=_output/bin/darwin/arm64 --output=flags.json

Output:

karmada-controller-manager: 74 flags
karmada-scheduler: 51 flags
Output written to: flags.json

Does this PR introduce a user-facing change?:

NONE

Signed-off-by: Sarthak Jha <sarthak@Sarthaks-MacBook-Air.local>
@karmada-bot karmada-bot added the kind/feature Categorizes issue or PR as related to a new feature. label Jan 26, 2026
@karmada-bot
Copy link
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 liangyuanpeng 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
Copy link
Contributor

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

@gemini-code-assist
Copy link

Summary of Changes

Hello @sarthakkjha, 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 delivers a new shell script designed to improve the maintainability and reliability of Karmada components by systematically extracting and documenting their command-line flags. It addresses the challenge of managing flag evolution across various dependencies, providing a robust mechanism for tracking and verifying component configurations.

Highlights

  • New Script for Flag Extraction: Introduces hack/extract-flags.sh, a new shell script designed to automatically extract command-line flags from Karmada component binaries and output them in a structured JSON format.
  • Enhanced Configuration Stability: This tool helps prevent silent flag changes during dependency upgrades from breaking user configurations by enabling automated detection and tracking of flag evolution.
  • Foundation for Tooling: Lays the groundwork for automated flag documentation, CI-based flag change detection across versions, and comprehensive flag inventory tracking for Karmada releases, fulfilling part of an LFX mentorship project.
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 added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jan 26, 2026
Copy link

@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 introduces a useful script, hack/extract-flags.sh, for extracting command-line flags from Karmada components. The script is well-structured and serves as a good foundation for automated flag documentation and change detection.

I've provided a few suggestions to improve the script's robustness and efficiency:

  • Fixing a bug related to set -o pipefail that could cause the script to fail for components with no flags.
  • Refactoring the command-line argument parsing to use a more standard while loop.
  • Optimizing the flag extraction process to avoid redundant binary executions.

Overall, this is a valuable addition to the project's tooling.

@codecov-commenter
Copy link

codecov-commenter commented Jan 26, 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 46.54%. Comparing base (6592b4a) to head (f99c796).
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #7136      +/-   ##
==========================================
- Coverage   46.54%   46.54%   -0.01%     
==========================================
  Files         700      700              
  Lines       48136    48136              
==========================================
- Hits        22407    22405       -2     
- Misses      24044    24046       +2     
  Partials     1685     1685              
Flag Coverage Δ
unittests 46.54% <ø> (-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: Sarthak Jha <sarthak@Sarthaks-MacBook-Air.local>
@sarthakkjha
Copy link
Author

Hi @XiShanYongYe-Chang @RainbowMango, I have added a shell script to extract command line flags from Karmada components and track changes over time. Can you please review this and let me know if we are moving in the right direction?

@RainbowMango
Copy link
Member

@sarthakkjha Thanks for doing this. I guess this task is part of the CNCF LFX program Protect Karmada Component Flags from Unexpected Changes. Are you going to run for it?

@sarthakkjha
Copy link
Author

sarthakkjha commented Jan 27, 2026

@sarthakkjha Thanks for doing this. I guess this task is part of the CNCF LFX program Protect Karmada Component Flags from Unexpected Changes. Are you going to run for it?

Yes i'm planning to contribute to Karmada and I believe LFX would be a great way to start with the mentorship.

@RainbowMango
Copy link
Member

Thank you for your enthusiasm. I appreciate your interest in contributing.

But, given that this is part of the upcoming LFX program that we've recently published, and we haven't yet started the candidate selection. To ensure fairness, I'd like to hold off on merging any implementation until the selected mentee is onboarded and begins their work under the program.

You are welcome to talk to us about your idea regarding the implementation, through channels like a community meeting.

@XiShanYongYe-Chang
Copy link
Member

Thank you for your enthusiasm. I appreciate your interest in contributing.

But, given that this is part of the upcoming LFX program that we've recently published, and we haven't yet started the candidate selection. To ensure fairness, I'd like to hold off on merging any implementation until the selected mentee is onboarded and begins their work under the program.

You are welcome to talk to us about your idea regarding the implementation, through channels like a community meeting.

+1

@sarthakkjha
Copy link
Author

Thank you for your enthusiasm. I appreciate your interest in contributing.

But, given that this is part of the upcoming LFX program that we've recently published, and we haven't yet started the candidate selection. To ensure fairness, I'd like to hold off on merging any implementation until the selected mentee is onboarded and begins their work under the program.

You are welcome to talk to us about your idea regarding the implementation, through channels like a community meeting.

Yes, that makes sense. My intention was mainly to get feedback on whether my thinking and overall direction were correct. We can hold off on merging for now and instead align on the right approach and foundation for implementing this as part of the LFX project.

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/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants