diff --git a/cmd/uptest/main.go b/cmd/uptest/main.go index 508592d..a3d2547 100644 --- a/cmd/uptest/main.go +++ b/cmd/uptest/main.go @@ -45,6 +45,8 @@ var ( renderOnly = e2e.Flag("render-only", "Only render test files. Do not run the tests.").Default("false").Bool() logCollectInterval = e2e.Flag("log-collect-interval", "Specifies the interval duration for collecting logs. "+ "The duration should be provided in a format understood by the tool, such as seconds (s), minutes (m), or hours (h). For example, '30s' for 30 seconds, '5m' for 5 minutes, or '1h' for one hour.").Default("30s").Duration() + skipUpdate = e2e.Flag("skip-update", "Skip the update step of the test.").Default("false").Bool() + skipImport = e2e.Flag("skip-import", "Skip the import step of the test.").Default("false").Bool() ) func main() { @@ -95,6 +97,8 @@ func e2eTests() { DefaultTimeout: *defaultTimeout, Directory: *testDir, SkipDelete: *skipDelete, + SkipUpdate: *skipUpdate, + SkipImport: *skipImport, OnlyCleanUptestResources: *onlyCleanUptestResources, RenderOnly: *renderOnly, LogCollectionInterval: *logCollectInterval, diff --git a/internal/config/config.go b/internal/config/config.go index 15e5424..ff774b2 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -55,6 +55,8 @@ type AutomatedTest struct { DefaultConditions []string SkipDelete bool + SkipUpdate bool + SkipImport bool OnlyCleanUptestResources bool diff --git a/internal/tester.go b/internal/tester.go index 88d9bd4..e03a314 100644 --- a/internal/tester.go +++ b/internal/tester.go @@ -32,6 +32,8 @@ 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, @@ -122,14 +124,19 @@ func logCollector(done chan bool, ticker *time.Ticker, mutex sync.Locker, resour return case <-ticker.C: mutex.Lock() - log.Printf("crossplane trace logs %s\n", time.Now()) 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 output, err := traceCmd.CombinedOutput() if err != nil { - log.Println("Error executing crossplane:", err) + // 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 { - log.Println(string(output)) + log.Printf("crossplane trace logs %s\n%s\n", time.Now(), string(output)) } } mutex.Unlock() @@ -148,6 +155,7 @@ func (t *tester) prepareConfig() (*config.TestCase, []config.Resource, error) { } examples := make([]config.Resource, 0, len(t.manifests)) + rootFound := false for _, m := range t.manifests { obj := m.Object groupVersionKind := obj.GroupVersionKind() @@ -238,12 +246,26 @@ func (t *tester) prepareConfig() (*config.TestCase, []config.Resource, error) { tc.SkipUpdate = true } example.Root = true + rootFound = true } } examples = append(examples, example) } + if !rootFound { + log.Println("Skipping update step because the root resource does not exist") + tc.SkipUpdate = true + } + if t.options.SkipUpdate { + log.Println("Skipping update step because the skip-delete option is set to true") + tc.SkipUpdate = true + } + if t.options.SkipImport { + log.Println("Skipping import step because the skip-import option is set to true") + tc.SkipImport = true + } + return tc, examples, nil }