mirror of https://github.com/fluxcd/cli-utils.git
Exit with non-zero exit code on error
A change in exit code behavior was introduced in #166, where printing an error used to also cause the application to exit with a non-zero exit code. As a result, errors in e.g. `kpt live apply` exits the process with a 0 exit code. This change should bring it in line with how it works before, but I'm open to other solutions if there's a cleaner way to accomplish this without having an error log automatically mean that the application needs to exit.
This commit is contained in:
parent
03aba2693b
commit
b0bfb0451c
|
|
@ -5,6 +5,7 @@ package apply
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"k8s.io/apimachinery/pkg/api/meta"
|
"k8s.io/apimachinery/pkg/api/meta"
|
||||||
|
|
@ -17,6 +18,11 @@ import (
|
||||||
"sigs.k8s.io/cli-utils/pkg/object"
|
"sigs.k8s.io/cli-utils/pkg/object"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
defaultExitErrorCode int = 1
|
||||||
|
timeoutExitErrorCode int = -1
|
||||||
|
)
|
||||||
|
|
||||||
// BasicPrinter is a simple implementation that just prints the events
|
// BasicPrinter is a simple implementation that just prints the events
|
||||||
// from the channel in the default format for kubectl.
|
// from the channel in the default format for kubectl.
|
||||||
// We need to support different printers for different output formats.
|
// We need to support different printers for different output formats.
|
||||||
|
|
@ -130,7 +136,9 @@ func (b *BasicPrinter) processErrorEvent(ee event.ErrorEvent, c *statusCollector
|
||||||
p("%s/%s %s %s", id.GroupKind.Kind,
|
p("%s/%s %s %s", id.GroupKind.Kind,
|
||||||
id.Name, ls.Resource.Status, ls.Resource.Message)
|
id.Name, ls.Resource.Status, ls.Resource.Message)
|
||||||
}
|
}
|
||||||
|
os.Exit(timeoutExitErrorCode)
|
||||||
}
|
}
|
||||||
|
os.Exit(defaultExitErrorCode)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *BasicPrinter) processApplyEvent(ae event.ApplyEvent, as *applyStats,
|
func (b *BasicPrinter) processApplyEvent(ae event.ApplyEvent, as *applyStats,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue