Skip to content

Commit

Permalink
Add new cli options: disable-import and disable-update
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 8a80a6a commit 0c0915f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
4 changes: 4 additions & 0 deletions cmd/uptest/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -95,6 +97,8 @@ func e2eTests() {
DefaultTimeout: *defaultTimeout,
Directory: *testDir,
SkipDelete: *skipDelete,
SkipUpdate: *skipUpdate,
SkipImport: *skipImport,
OnlyCleanUptestResources: *onlyCleanUptestResources,
RenderOnly: *renderOnly,
LogCollectionInterval: *logCollectInterval,
Expand Down
2 changes: 2 additions & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ type AutomatedTest struct {
DefaultConditions []string

SkipDelete bool
SkipUpdate bool
SkipImport bool

OnlyCleanUptestResources bool

Expand Down
28 changes: 25 additions & 3 deletions internal/tester.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit 0c0915f

Please sign in to comment.