From a5c328a2a71fe8db70910bcb9c893a5a92cdaa7a Mon Sep 17 00:00:00 2001 From: Malte Poll Date: Tue, 6 Jun 2023 11:10:24 +0200 Subject: [PATCH] e2e: improve upgrade test portability --- .github/workflows/e2e-upgrade.yml | 2 ++ bazel/toolchains/go_module_deps.bzl | 8 +++++++ e2e/internal/upgrade/BUILD.bazel | 5 +++-- e2e/internal/upgrade/upgrade_test.go | 31 ++++++++++++++++++++++++---- go.mod | 1 + go.sum | 2 ++ 6 files changed, 43 insertions(+), 6 deletions(-) diff --git a/.github/workflows/e2e-upgrade.yml b/.github/workflows/e2e-upgrade.yml index 4474446c9..55f159c64 100644 --- a/.github/workflows/e2e-upgrade.yml +++ b/.github/workflows/e2e-upgrade.yml @@ -184,6 +184,7 @@ jobs: env: KUBECONFIG: ${{ steps.e2e_test.outputs.kubeconfig }} run: | + kubectl logs -n kube-system -l "app.kubernetes.io/name=constellation-operator" --tail=-1 > node-operator.logs kubectl logs -n kube-system -l "app.kubernetes.io/name=node-maintenance-operator" --tail=-1 > node-maintenance-operator.logs kubectl get nodeversions.update.edgeless.systems constellation-version -o yaml > constellation-version.yaml @@ -193,6 +194,7 @@ jobs: with: name: upgrade-logs path: | + node-operator.logs node-maintenance-operator.logs constellation-version.yaml diff --git a/bazel/toolchains/go_module_deps.bzl b/bazel/toolchains/go_module_deps.bzl index 02035fc0c..1f9bbbe11 100644 --- a/bazel/toolchains/go_module_deps.bzl +++ b/bazel/toolchains/go_module_deps.bzl @@ -829,6 +829,14 @@ def go_dependencies(): sum = "h1:XmPu4mXICgdGnC5dXGjUGbwUD/kUmS0l5Aop3LaevBM=", version = "v0.0.0-20230317132445-9c3c1fc0106e", ) + go_repository( + name = "com_github_bazelbuild_rules_go", + build_file_generation = "on", + build_file_proto_mode = "disable_global", + importpath = "github.com/bazelbuild/rules_go", + sum = "h1:wkJLUDx59dntWMghuL8++GteoU1To6sRoKJXuyFtmf8=", + version = "v0.39.1", + ) go_repository( name = "com_github_beeker1121_goque", diff --git a/e2e/internal/upgrade/BUILD.bazel b/e2e/internal/upgrade/BUILD.bazel index 7c265e450..c1e174daa 100644 --- a/e2e/internal/upgrade/BUILD.bazel +++ b/e2e/internal/upgrade/BUILD.bazel @@ -29,11 +29,11 @@ go_test( # keep count = 1, data = [ - "//cli:cli_enterprise_linux_amd64", + "//cli:cli_enterprise_host", ], embed = [":upgrade"], env = { - "PATH_CLI": "$(location //cli:cli_enterprise_linux_amd64)", + "PATH_CLI": "$(rlocationpath //cli:cli_enterprise_host)", }, # keep gotags = ["e2e"], @@ -48,6 +48,7 @@ go_test( "//internal/versions", "@com_github_spf13_afero//:afero", "@com_github_stretchr_testify//require", + "@io_bazel_rules_go//go/runfiles:go_default_library", "@io_k8s_api//core/v1:core", "@io_k8s_apimachinery//pkg/apis/meta/v1:meta", "@io_k8s_client_go//kubernetes", diff --git a/e2e/internal/upgrade/upgrade_test.go b/e2e/internal/upgrade/upgrade_test.go index b0f97e0f7..7b166dde1 100644 --- a/e2e/internal/upgrade/upgrade_test.go +++ b/e2e/internal/upgrade/upgrade_test.go @@ -17,11 +17,13 @@ import ( "log" "os" "os/exec" + "path/filepath" "strings" "sync" "testing" "time" + "github.com/bazelbuild/rules_go/go/runfiles" "github.com/edgelesssys/constellation/v2/e2e/internal/kubectl" attestationconfigfetcher "github.com/edgelesssys/constellation/v2/internal/api/attestationconfig/fetcher" "github.com/edgelesssys/constellation/v2/internal/config" @@ -68,6 +70,7 @@ func TestUpgrade(t *testing.T) { require.NotEqual(*targetImage, "", "--target-image needs to be specified") + log.Println("Waiting for nodes and pods to be ready.") testNodesEventuallyAvailable(t, k, *wantControl, *wantWorker) testPodsEventuallyReady(t, k, "kube-system") @@ -75,6 +78,7 @@ func TestUpgrade(t *testing.T) { require.NoError(err) // Migrate config if necessary. + log.Println("Migrating config if needed.") cmd := exec.CommandContext(context.Background(), cli, "config", "migrate", "--config", constants.ConfigFilename, "--force", "--debug") stdout, stderr, err := runCommandWithSeparateOutputs(cmd) require.NoError(err, "Stdout: %s\nStderr: %s", string(stdout), string(stderr)) @@ -138,16 +142,35 @@ func workingDir(workspace string) (string, error) { } // getCLIPath returns the path to the CLI. -func getCLIPath(cliPath string) (string, error) { +func getCLIPath(cliPathFlag string) (string, error) { pathCLI := os.Getenv("PATH_CLI") + var relCLIPath string switch { case pathCLI != "": - return pathCLI, nil - case cliPath != "": - return cliPath, nil + relCLIPath = pathCLI + case cliPathFlag != "": + relCLIPath = cliPathFlag default: return "", errors.New("neither 'PATH_CLI' nor 'cli' flag set") } + + // try to find the CLI in the working directory + // (e.g. when running via `go test` or when specifying a path manually) + workdir, err := os.Getwd() + if err != nil { + return "", fmt.Errorf("getting working directory: %w", err) + } + + absCLIPath := relCLIPath + if !filepath.IsAbs(relCLIPath) { + absCLIPath = filepath.Join(workdir, relCLIPath) + } + if _, err := os.Stat(absCLIPath); err == nil { + return absCLIPath, nil + } + + // fall back to runfiles (e.g. when running via bazel) + return runfiles.Rlocation(pathCLI) } // testPodsEventuallyReady checks that: diff --git a/go.mod b/go.mod index a2a4016ad..d535852c2 100644 --- a/go.mod +++ b/go.mod @@ -177,6 +177,7 @@ require ( github.com/aws/aws-sdk-go-v2/service/sso v1.12.10 // indirect github.com/aws/aws-sdk-go-v2/service/ssooidc v1.14.10 // indirect github.com/aws/aws-sdk-go-v2/service/sts v1.18.11 // indirect + github.com/bazelbuild/rules_go v0.39.1 github.com/benbjohnson/clock v1.3.0 // indirect github.com/beorn7/perks v1.0.1 // indirect github.com/blang/semver v3.5.1+incompatible // indirect diff --git a/go.sum b/go.sum index 51dc1d727..ef2ca1b64 100644 --- a/go.sum +++ b/go.sum @@ -295,6 +295,8 @@ github.com/aws/aws-sdk-go-v2/service/sts v1.18.11/go.mod h1:BgQOMsg8av8jset59jel github.com/aws/smithy-go v1.13.5 h1:hgz0X/DX0dGqTYpGALqXJoRKRj5oQ7150i5FdTePzO8= github.com/aws/smithy-go v1.13.5/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/aybabtme/rgbterm v0.0.0-20170906152045-cc83f3b3ce59/go.mod h1:q/89r3U2H7sSsE2t6Kca0lfwTK8JdoNGS/yzM/4iH5I= +github.com/bazelbuild/rules_go v0.39.1 h1:wkJLUDx59dntWMghuL8++GteoU1To6sRoKJXuyFtmf8= +github.com/bazelbuild/rules_go v0.39.1/go.mod h1:TMHmtfpvyfsxaqfL9WnahCsXMWDMICTw7XeK9yVb+YU= github.com/benbjohnson/clock v1.0.3/go.mod h1:bGMdMPoPVvcYyt1gHDf4J2KE153Yf9BuiUKYMaxlTDM= github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA= github.com/benbjohnson/clock v1.3.0 h1:ip6w0uFQkncKQ979AypyG0ER7mqUSBdKLOgAle/AT8A=