Skip to content

Commit

Permalink
🐛 Fix integration test with external installation (#924)
Browse files Browse the repository at this point in the history
Before this PR, we saw errors like:
'failed to parse response: http status 500: {"code":2,"message":"integration not found"}}'

That happened because of timing and re-use issues. This PR takes of this.

Signed-off-by: Christian Zunker <[email protected]>
  • Loading branch information
czunker authored Nov 8, 2023
1 parent dd435df commit b3dff07
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
12 changes: 12 additions & 0 deletions tests/framework/installer/installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"path/filepath"
"strings"
"testing"
"time"

mondoov2 "go.mondoo.com/mondoo-operator/api/v1alpha2"
"go.mondoo.com/mondoo-operator/pkg/utils/k8s"
Expand Down Expand Up @@ -64,6 +65,10 @@ func (i *MondooInstaller) InstallOperator() error {
}

zap.S().Info("The Mondoo operator is installed externally. Skipping installation...")
// We had race conditions were the integration wasn't ready when the operator tried to exchange the token
// for a service account. This sleep should give the integration enough time to get ready.
zap.S().Infof("Sleeping for 30 seconds to allow the token to get active")
time.Sleep(30 * time.Second)
return nil
}

Expand Down Expand Up @@ -122,6 +127,13 @@ func (i *MondooInstaller) UninstallOperator() error {
}
zap.S().Infof("Deleted Mondoo client secret %s/%s.", secret.Namespace, secret.Name)

// A new suite gets a new integration/token, so cleanup the old one.
secret.Name = utils.MondooTokenSecret
if err := i.K8sHelper.DeleteResourceIfExists(secret); err != nil {
return err
}
zap.S().Infof("Deleted Mondoo token secret %s/%s.", secret.Namespace, secret.Name)

if i.isInstalledExternally {
zap.S().Info("The Mondoo operator has been installed externally. Skipping uninstall...")
return nil
Expand Down
2 changes: 2 additions & 0 deletions tests/framework/nexus/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ func NewClient() (*Client, error) {
if apiToken == "" {
return nil, fmt.Errorf("missing environment variable %s", MONDOO_API_TOKEN_VAR)
}
fmt.Printf("Using GraphQL endpoint %s\n", gqlEndpoint)
fmt.Printf("Using org MRN %s\n", orgMrn)
// Initialize the client
client, err := mondoogql.NewClient(option.WithEndpoint(gqlEndpoint), option.WithAPIToken(apiToken))
if err != nil {
Expand Down

0 comments on commit b3dff07

Please sign in to comment.