Skip to content

Commit

Permalink
Update deprecated Kubernets API and improve error reporting
Browse files Browse the repository at this point in the history
This commit improves error reporting in Go integration tests, when a
module fails, its name and error are collected and printed at the end.

The deprecated `batch/v1beta1` is replaced by `batch/v1` in Kubernetes
manifests.
  • Loading branch information
belimawr committed Jun 13, 2024
1 parent c151f10 commit 0cf9cd1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
19 changes: 16 additions & 3 deletions dev-tools/mage/gotest.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,12 @@ func GoTestIntegrationForModule(ctx context.Context) error {
return err
}

type moduleErr struct {
name string
err error
}
foundModule := false
failedModules := []string{}
failedModules := []moduleErr{}
for _, fi := range modulesFileInfo {
if !fi.IsDir() {
continue
Expand All @@ -169,14 +173,23 @@ func GoTestIntegrationForModule(ctx context.Context) error {
})
if err != nil {
// err will already be report to stdout, collect failed module to report at end
failedModules = append(failedModules, fi.Name())
failedModules = append(failedModules, moduleErr{
name: fi.Name(),
err: err,
})
}
}
if module != "" && !foundModule {
return fmt.Errorf("no module %s", module)
}
if len(failedModules) > 0 {
return fmt.Errorf("failed modules: %s", strings.Join(failedModules, ", "))
errMsg := strings.Builder{}
names := []string{}
for _, m := range failedModules {
fmt.Fprintf(&errMsg, "Module: %s\nError: %s\n", m.name, m.err.Error())
names = append(names, m.name)
}
return fmt.Errorf("failed modules: %s.\n%s", strings.Join(names, ", "), errMsg.String())
}
return nil
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Cronjob that will execute each minute.
# It will print a message and sleep (reporting being active) for 5 seconds

apiVersion: batch/v1beta1
apiVersion: batch/v1
kind: CronJob
metadata:
name: mycronjob
Expand All @@ -19,4 +19,4 @@ spec:

restartPolicy: OnFailure
terminationGracePeriodSeconds: 0
concurrencyPolicy: Allow
concurrencyPolicy: Allow
2 changes: 1 addition & 1 deletion metricbeat/module/kubernetes/kubernetes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ spec:
requests:
storage: 1Mi
---
apiVersion: batch/v1beta1
apiVersion: batch/v1
kind: CronJob
metadata:
name: basic-cronjob
Expand Down

0 comments on commit 0cf9cd1

Please sign in to comment.