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

Use logging library with json support in cmctl (part 2) #6119

Merged
merged 1 commit into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 19 additions & 5 deletions internal/cmd/util/exit.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,24 @@ import (

// SetExitCode sets the exit code to 1 if the error is not a context.Canceled error.
func SetExitCode(err error) {
if (err != nil) && errors.Is(err, context.DeadlineExceeded) {
errorExitCodeChannel <- 124 // Indicate that there was a timeout error
} else if (err != nil) && !errors.Is(err, context.Canceled) {
errorExitCodeChannel <- 1 // Indicate that there was an error
switch {
case err == nil || errors.Is(err, context.Canceled):
// If the context was canceled, we don't need to set the exit code
case errors.Is(err, context.DeadlineExceeded):
SetExitCodeValue(124) // Indicate that there was a timeout error
default:
SetExitCodeValue(1) // Indicate that there was an error
}
// If the context was canceled, we don't need to set the exit code
}

// SetExitCode sets the exit code to 1 if the error is not a context.Canceled error.
func SetExitCodeValue(code int) {
inteon marked this conversation as resolved.
Show resolved Hide resolved
if code != 0 {
select {
case errorExitCodeChannel <- code:
default:
// The exit code has already been set to a non-zero value.
}
}
// If the exit code is 0, we don't need to set the exit code
}
inteon marked this conversation as resolved.
Show resolved Hide resolved
5 changes: 3 additions & 2 deletions pkg/util/cmapichecker/cmapichecker.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,13 @@ var (
)

const (
crdsMappingError = `error finding the scope of the object: failed to get restmapping: no matches for kind "Certificate" in group "cert-manager.io"`
crdsMapping1Error = `error finding the scope of the object: failed to get restmapping: failed to find API group "cert-manager.io"`
Copy link
Member Author

Choose a reason for hiding this comment

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

There was a chanage in controller-runtime that caused this regex to stop matching.

Copy link
Member

@maelvls maelvls Aug 1, 2023

Choose a reason for hiding this comment

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

I wish we had some form of testing that would catch this kind of sublety, but I am also conscious of the effort it would take to fake the API server to respond with these errors... so I'm OK with the current state of things 😅

crdsMapping2Error = `error finding the scope of the object: failed to get restmapping: no matches for kind "Certificate" in group "cert-manager.io"`
crdsNotFoundError = `the server could not find the requested resource (post certificates.cert-manager.io)`
)

var (
regexErrCertManagerCRDsNotFound = regexp.MustCompile(`^(` + regexp.QuoteMeta(crdsMappingError) + `|` + regexp.QuoteMeta(crdsNotFoundError) + `)$`)
regexErrCertManagerCRDsNotFound = regexp.MustCompile(`^(` + regexp.QuoteMeta(crdsMapping1Error) + `|` + regexp.QuoteMeta(crdsMapping2Error) + `|` + regexp.QuoteMeta(crdsNotFoundError) + `)$`)
regexErrWebhookServiceFailure = regexp.MustCompile(`Post "(.*)": service "(.*)-webhook" not found`)
regexErrWebhookDeploymentFailure = regexp.MustCompile(`Post "(.*)": (.*): connect: connection refused`)
regexErrWebhookCertificateFailure = regexp.MustCompile(`Post "(.*)": x509: certificate signed by unknown authority`)
Expand Down