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

fix: ensure flux check returns non-zero exit code on failure #5267

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

h3nryc0ding
Copy link
Contributor

Fixes #5220 by returning a non-zero exist code for failed checks.

for _, id := range identifiers {
rs := coll.ResourceStatuses[id]
switch rs.Status {
case status.CurrentStatus:
sc.logger.Successf("%s: %s ready", rs.Identifier.Name, strings.ToLower(rs.Identifier.GroupKind.Kind))
case status.NotFoundStatus:
sc.logger.Failuref("%s: %s not found", rs.Identifier.Name, strings.ToLower(rs.Identifier.GroupKind.Kind))
errMsg := fmt.Sprintf("%s: %s not found", rs.Identifier.Name, strings.ToLower(rs.Identifier.GroupKind.Kind))
sc.logger.Failuref(errMsg)
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure what's gonna happen now that we both log and return the error, would we see the error printed twice? Can you please test that? Maybe we need to remove the log.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

StatusChecker.Assess is used in three places with inconsistent error handling:

  1. check.go

    flux2/cmd/flux/check.go

    Lines 215 to 217 in f0fecf7

    if err := statusChecker.Assess(ref...); err != nil {
    ok = false
    }

    • Does not use the error
  2. install.go

    flux2/cmd/flux/install.go

    Lines 279 to 281 in f0fecf7

    if err := statusChecker.Assess(componentRefs...); err != nil {
    return fmt.Errorf("install failed")
    }

    • Uses the error
  3. bootstrap_plain_git.go

    if err := checker.Assess(identifiers...); err != nil {
    return err
    }

    • Uses the error

This means either:

  • At least one of the locations logs the error twice, or
  • check.go is missing necessary logging or needs refactoring

Copy link
Member

Choose a reason for hiding this comment

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

Yeah maybe we need some refactoring here... We're busy preparing for KubeCon EU next week, can you please ping us again after KubeCon? Thanks 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

flux check always returns 0
2 participants