Skip to content

Commit

Permalink
Add assertion for managed resources
Browse files Browse the repository at this point in the history
Signed-off-by: Sergen Yalçın <yalcinsergen97@gmail.com>
  • Loading branch information
sergenyalcin committed Aug 29, 2024
1 parent 0c0915f commit d4abb6a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
5 changes: 5 additions & 0 deletions internal/templates/03-delete.yaml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ spec:
for:
deletion: {}
{{- end }}
{{- if not .TestCase.OnlyCleanUptestResources }}
- script:
content: |
${KUBECTL} wait managed --all --for=delete --timeout -1s
{{- end }}
{{- if .TestCase.TeardownScriptPath }}
- command:
entrypoint: {{ .TestCase.TeardownScriptPath }}
Expand Down
6 changes: 6 additions & 0 deletions internal/templates/renderer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,9 @@ spec:
name: example-bucket
for:
deletion: {}
- script:
content: |
${KUBECTL} wait managed --all --for=delete --timeout -1s
`,
},
},
Expand Down Expand Up @@ -435,6 +438,9 @@ spec:
namespace: upbound-system
for:
deletion: {}
- script:
content: |
${KUBECTL} wait managed --all --for=delete --timeout -1s
- command:
entrypoint: /tmp/teardown.sh
`,
Expand Down
20 changes: 7 additions & 13 deletions internal/tester.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ var testFiles = []string{
"03-delete.yaml",
}

const crossplaneTempError = "crossplane: error: cannot get requested resource"

func newTester(ms []config.Manifest, opts *config.AutomatedTest) *tester {
return &tester{
options: opts,
Expand Down Expand Up @@ -125,24 +123,20 @@ func logCollector(done chan bool, ticker *time.Ticker, mutex sync.Locker, resour
case <-ticker.C:
mutex.Lock()
for _, r := range resources {
traceCmd := exec.Command("bash", "-c", fmt.Sprintf(`"${CROSSPLANE_CLI}" beta trace %s %s -o wide`, r.KindGroup, r.Name)) //nolint:gosec // Disabling gosec to allow dynamic shell command execution
// During the setup script is running, the crossplane command
// is failing because of the resource not found error.
// We do not want to show this error to the user because it
// is a noise and temporary one.
// The error output was redirected to a file.
traceCmd := exec.Command("bash", "-c", fmt.Sprintf(`"${CROSSPLANE_CLI}" beta trace %s %s -o wide 2>>/tmp/uptest_crossplane_temp_errors.log`, r.KindGroup, r.Name)) //nolint:gosec // Disabling gosec to allow dynamic shell command execution
output, err := traceCmd.CombinedOutput()
if err != nil {
// During the setup script is running, the crossplane command
// is failing because of the resource not found error.
// We do not want to show this error to the user because it
// is a noise and temporary one.
if !strings.Contains(string(output), crossplaneTempError) {
log.Printf("crossplane trace logs %s\n%s: %s: %s\n", time.Now(), "Error executing crossplane", err, string(output))
}
} else {
if err == nil {
log.Printf("crossplane trace logs %s\n%s\n", time.Now(), string(output))
}
}
mutex.Unlock()
}
}

}

func (t *tester) prepareConfig() (*config.TestCase, []config.Resource, error) { //nolint:gocyclo // TODO: can we break this?
Expand Down

0 comments on commit d4abb6a

Please sign in to comment.