Skip to content

Commit

Permalink
Merge pull request #6119 from inteon/ctl_logging_part2
Browse files Browse the repository at this point in the history
Use logging library with json support in cmctl (part 2)
  • Loading branch information
jetstack-bot committed Aug 1, 2023
2 parents d233758 + ae28746 commit b93ec2f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
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) {
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
}
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"`
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

0 comments on commit b93ec2f

Please sign in to comment.