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

Print kuttl logs if kuttl tests cannot be started #6225

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions changelog/fragments/6225-print-kuttl-logs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
entries:
- description: >
The `scorecard-test-kuttl` image always prints the kuttl logs
in case there is an error processing the kuttl report.

# kind is one of:
# - addition
# - change
# - deprecation
# - removal
# - bugfix
kind: change

# Is this a breaking change?
breaking: false

# NOTE: ONLY USE `pull_request_override` WHEN ADDING THIS
# FILE FOR A PREVIOUSLY MERGED PULL_REQUEST!
#
# The generator auto-detects the PR number from the commit
# message in which this file was originally added.
#
# What is the pull request number (without the "#")?
# pull_request_override: 0
9 changes: 4 additions & 5 deletions images/scorecard-test-kuttl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func main() {

var suite *Testsuite
if len(jsonReport.Testsuite) == 0 {
printErrorStatus(errors.New("empty kuttl test suite was found"))
printErrorStatus(errors.New("no kuttl test suite was found. kuttl may not have run successfully"))
return
}

Expand Down Expand Up @@ -103,6 +103,7 @@ func printErrorStatus(err error) {
r := v1alpha3.TestResult{}
r.State = v1alpha3.FailState
r.Errors = []string{err.Error()}
r.Log = getKuttlLogs()
s.Results = append(s.Results, r)
jsonOutput, err := json.MarshalIndent(s, "", " ")
if err != nil {
Expand Down Expand Up @@ -189,14 +190,12 @@ type Testsuites struct {
func getKuttlLogs() string {
stderrFile, err := os.ReadFile("/tmp/kuttl.stderr")
if err != nil {
printErrorStatus(fmt.Errorf("could not open kuttl stderr file %v", err))
return err.Error()
return fmt.Sprintf("could not open kuttl stderr file: %v", err)
}

stdoutFile, err := os.ReadFile("/tmp/kuttl.stdout")
if err != nil {
printErrorStatus(fmt.Errorf("could not open kuttl stdout file %v", err))
return err.Error()
return fmt.Sprintf("could not open kuttl stdout file: %v", err)
}

return string(stderrFile) + string(stdoutFile)
Expand Down