Skip to content

✨ Migrate operator-controller cli handling to cobra #1717

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 14, 2025

Conversation

o-farag
Copy link
Contributor

@o-farag o-farag commented Feb 5, 2025

Description

Migrate operator-controller cli command handling to cobra

Maintain/update flag handling by migrating to cobra as requested @ #1650

Changes:

  • Stopped using pflags, moved to cobra
  • Changed how the version flag is processed, instead adding it as a subcommand
  • Moved flag processing/validation out of main()
  • Integrated cobra error handling with RunE while preserving setupLog error messages

Reviewer Checklist

  • API Go Documentation
  • Tests: Unit Tests (and E2E Tests, if appropriate)
  • Comprehensive Commit Messages
  • Links to related GitHub Issue(s)

@o-farag o-farag requested a review from a team as a code owner February 5, 2025 22:12
Copy link

netlify bot commented Feb 5, 2025

Deploy Preview for olmv1 ready!

Name Link
🔨 Latest commit d04c967
🔍 Latest deploy log https://app.netlify.com/sites/olmv1/deploys/67ae7916deef550008e8e485
😎 Deploy Preview https://deploy-preview-1717--olmv1.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@o-farag o-farag marked this pull request as draft February 5, 2025 22:12
@openshift-ci openshift-ci bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Feb 5, 2025
@o-farag
Copy link
Contributor Author

o-farag commented Feb 5, 2025

Some notes:

  • run() is monolithic and contains most of what used to be main(). I can break it up into helper functions if that's better, but I don't see a reason for it (other than maybe improved readability)
  • I made all changes in main.go, without introducing the file structure recommended in the cobra user guide. I can also change it to follow that guide, at the cost of having more files
  • Instead of having all errors go through RunE, I log all errors with RunE but allow errors that used setupLog to also still use that. I can change it to only one or the other if that's better

@o-farag o-farag marked this pull request as ready for review February 5, 2025 22:47
@openshift-ci openshift-ci bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Feb 5, 2025
@o-farag o-farag marked this pull request as draft February 5, 2025 22:51
@openshift-ci openshift-ci bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Feb 5, 2025
@o-farag o-farag marked this pull request as ready for review February 5, 2025 23:02
@openshift-ci openshift-ci bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Feb 5, 2025
@o-farag
Copy link
Contributor Author

o-farag commented Feb 6, 2025

@grokspawn could I get the workflow approved? I'd like to know id there's anything I need to fix. Thank you

@tmshort
Copy link
Contributor

tmshort commented Feb 11, 2025

This needs a rebase. Also, you'll likely want to do catalogd/cmd/catalogd/main.go as well (if not in this PR, then another).

@openshift-merge-robot openshift-merge-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 11, 2025
@LalatenduMohanty
Copy link
Member

@o-farag Sorry about the delay in reviewing the PR. Once you rebase the PR will review it. Thanks.

@o-farag
Copy link
Contributor Author

o-farag commented Feb 12, 2025

This needs a rebase. Also, you'll likely want to do catalogd/cmd/catalogd/main.go as well (if not in this PR, then another).

I believe this PR takes care of catalogd: #1598

@openshift-merge-robot openshift-merge-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 12, 2025
@o-farag
Copy link
Contributor Author

o-farag commented Feb 12, 2025

@LalatenduMohanty thanks for letting me know, I've rebased it

@o-farag
Copy link
Contributor Author

o-farag commented Feb 12, 2025

/retest

Copy link

openshift-ci bot commented Feb 12, 2025

@o-farag: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

In response to this:

/retest

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@o-farag
Copy link
Contributor Author

o-farag commented Feb 12, 2025

The e2e-kind test runs successfully on my own repo, and I have no failing tests locally

@LalatenduMohanty
Copy link
Member

The e2e-kind test runs successfully on my own repo, and I have no failing tests locally

Looks like a flake. We can rerun it to test once the PR review is done.

@openshift-merge-robot openshift-merge-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 13, 2025
@openshift-merge-robot openshift-merge-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 13, 2025
setupLog.Error(err, "unable to ensure empty cache directory")
os.Exit(1)
return err
Copy link
Member

Choose a reason for hiding this comment

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

By replacing os.Exit(1) with return err it is changing the binary's behavior little bit. With the current change we will error out if flags are not used properly and print the usage as well. Previously we wont print the usage. But the new behavior is better IMO.

Copy link
Member

@LalatenduMohanty LalatenduMohanty left a comment

Choose a reason for hiding this comment

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

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Feb 14, 2025
@LalatenduMohanty
Copy link
Member

/hold for someone from the maintainers group to take a look. Maintainers, feel free to remove the hold.

@openshift-ci openshift-ci bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Feb 14, 2025
Copy link

codecov bot commented Feb 14, 2025

Codecov Report

Attention: Patch coverage is 52.38095% with 40 lines in your changes missing coverage. Please review.

Project coverage is 68.24%. Comparing base (ee8d821) to head (d04c967).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
cmd/operator-controller/main.go 52.38% 34 Missing and 6 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1717      +/-   ##
==========================================
- Coverage   68.29%   68.24%   -0.05%     
==========================================
  Files          63       63              
  Lines        5116     5121       +5     
==========================================
+ Hits         3494     3495       +1     
- Misses       1392     1396       +4     
  Partials      230      230              
Flag Coverage Δ
e2e 51.59% <52.38%> (-0.12%) ⬇️
unit 55.86% <0.00%> (-0.06%) ⬇️

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.

Copy link
Contributor

@tmshort tmshort left a comment

Choose a reason for hiding this comment

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

/lgtm

@tmshort
Copy link
Contributor

tmshort commented Feb 14, 2025

/unhold

@openshift-ci openshift-ci bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Feb 14, 2025
@tmshort tmshort added this pull request to the merge queue Feb 14, 2025
@tmshort
Copy link
Contributor

tmshort commented Feb 14, 2025

Thank you for your contribution!

Merged via the queue into operator-framework:main with commit 05415ef Feb 14, 2025
21 of 23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants