Skip to content

Commit

Permalink
ci(e2e): fail fast on worker setup errors (#387)
Browse files Browse the repository at this point in the history
Related to #381
  • Loading branch information
apricote authored Feb 22, 2023
1 parent 1c2ec7e commit 2a0dc46
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions e2etests/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,29 @@ func (s *hcloudK8sSetup) PrepareTestEnv(ctx context.Context, additionalSSHKeys [

var workers = 3 // Change this value if you want to have more workers for the test
var wg sync.WaitGroup
errs := make(chan error, workers)
for worker := 1; worker <= workers; worker++ {
wg.Add(1)
go s.createClusterWorker(ctx, additionalSSHKeys, &wg, worker)
go func(worker int) {
err = s.createClusterWorker(ctx, additionalSSHKeys, &wg, worker)
if err != nil {
errs <- err
}
}(worker)
}
wg.Wait()
close(errs)

// Return first error that happened
err = <-errs
if err != nil {
return err
}

return nil
}

func (s *hcloudK8sSetup) createClusterWorker(ctx context.Context, additionalSSHKeys []*hcloud.SSHKey, wg *sync.WaitGroup, worker int) {
func (s *hcloudK8sSetup) createClusterWorker(ctx context.Context, additionalSSHKeys []*hcloud.SSHKey, wg *sync.WaitGroup, worker int) error {
const op = "hcloudK8sSetup/createClusterWorker"
defer wg.Done()

Expand All @@ -118,28 +132,24 @@ func (s *hcloudK8sSetup) createClusterWorker(ctx context.Context, additionalSSHK

userData, err := s.getCloudInitConfig(false)
if err != nil {
fmt.Printf("[%s] %s getCloudInitConfig: %s", workerName, op, err)
return
return fmt.Errorf("[%s] %s getCloudInitConfig: %w", workerName, op, err)
}
srv, err := s.createServer(ctx, workerName, instanceType, additionalSSHKeys, err, userData)
if err != nil {
fmt.Printf("[%s] %s createServer: %s", workerName, op, err)
return
return fmt.Errorf("[%s] %s createServer: %w", workerName, op, err)
}
s.WorkerNodes = append(s.WorkerNodes, srv)

s.waitUntilSSHable(srv)

err = s.waitForCloudInit(srv)
if err != nil {
fmt.Printf("[%s] %s: wait for cloud init on worker: %v", srv.Name, op, err)
return
return fmt.Errorf("[%s] %s: wait for cloud init on worker: %w", srv.Name, op, err)
}

err = s.transferDockerImage(srv)
if err != nil {
fmt.Printf("[%s] %s: transfer image on worker: %v\n", srv.Name, op, err)
return
return fmt.Errorf("[%s] %s: transfer image on worker: %w", srv.Name, op, err)
}

fmt.Printf("[%s] %s Load Image\n", srv.Name, op)
Expand All @@ -148,9 +158,10 @@ func (s *hcloudK8sSetup) createClusterWorker(ctx context.Context, additionalSSHK

err = RunCommandOnServer(s.privKey, srv, transferCmd)
if err != nil {
fmt.Printf("[%s] %s: load image on worker: %v", srv.Name, op, err)
return
return fmt.Errorf("[%s] %s: load image on worker: %w", srv.Name, op, err)
}

return nil
}

func (s *hcloudK8sSetup) waitUntilSSHable(server *hcloud.Server) {
Expand Down

0 comments on commit 2a0dc46

Please sign in to comment.