Skip to content
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

Pass context through cmd and use RunE instead of Run #33

Merged
merged 1 commit into from
Mar 7, 2024

Conversation

inteon
Copy link
Member

@inteon inteon commented Mar 7, 2024

Pass context by calling cmd.ExecuteContext(ctx) and retrieving it using cmd.Context(). Also, call cmdutil.CheckErr only in main.go and use RunE and PreRunE to pass the error to main.go.

An example of cmctl check api -v4 --logging-format=json --wait=5m still working:

{"ts":1709802469036.6274,"caller":"api/api.go:117","msg":"Not ready","v":2,"logger":"cert-manager.cmctl.checkAPI","err":"the cert-manager CRDs are not yet installed on the Kubernetes API server","underlyingError":"error finding the scope of the object: failed to get restmapping: no matches for kind \"Certificate\" in group \"cert-manager.io\""}
{"ts":1709802474038.2876,"caller":"api/api.go:117","msg":"Not ready","v":2,"logger":"cert-manager.cmctl.checkAPI","err":"the cert-manager CRDs are not yet installed on the Kubernetes API server","underlyingError":"error finding the scope of the object: failed to get restmapping: no matches for kind \"Certificate\" in group \"cert-manager.io\""}
^Cerror: the cert-manager CRDs are not yet installed on the Kubernetes API server
exit status 130

@jetstack-bot jetstack-bot added dco-signoff: yes Indicates that all commits in the pull request have the valid DCO sign-off message. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Mar 7, 2024
Signed-off-by: Tim Ramlot <42113979+inteon@users.noreply.github.com>
@@ -47,6 +47,7 @@ func NewCertManagerCtlCommand(ctx context.Context, in io.Reader, out, err io.Wri
return logf.ValidateAndApply(logOptions)
},
SilenceErrors: true, // Errors are already logged when calling cmd.Execute()
SilenceUsage: true, // Don't print usage when an error occurs
Copy link
Member Author

@inteon inteon Mar 7, 2024

Choose a reason for hiding this comment

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

We do not want cobra to print the usage every time there is an error.

@ThatsMrTalbot
Copy link
Contributor

/lgtm

@jetstack-bot jetstack-bot added the lgtm Indicates that a PR is ready to be merged. label Mar 7, 2024
@inteon
Copy link
Member Author

inteon commented Mar 7, 2024

/approve

@jetstack-bot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: inteon

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

The pull request process is described here

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

@jetstack-bot jetstack-bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Mar 7, 2024
@jetstack-bot jetstack-bot merged commit 9ead175 into cert-manager:main Mar 7, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. dco-signoff: yes Indicates that all commits in the pull request have the valid DCO sign-off message. lgtm Indicates that a PR is ready to be merged. 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.

3 participants