From 394b871c5bc98c5a79d06e5b302c5d1c7666c342 Mon Sep 17 00:00:00 2001 From: Lucas Rodriguez Date: Tue, 28 Mar 2023 03:44:47 -0500 Subject: [PATCH 01/53] Add check for mismatched architectures for zarf init Add e2e test for verify this check works --- src/cmd/initialize.go | 25 +++++++++++ .../e2e/29_mismatched_architectures_test.go | 45 +++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 src/test/e2e/29_mismatched_architectures_test.go diff --git a/src/cmd/initialize.go b/src/cmd/initialize.go index e058b2cc8b..208679257e 100644 --- a/src/cmd/initialize.go +++ b/src/cmd/initialize.go @@ -15,6 +15,7 @@ import ( "github.com/AlecAivazis/survey/v2" "github.com/defenseunicorns/zarf/src/config" "github.com/defenseunicorns/zarf/src/config/lang" + "github.com/defenseunicorns/zarf/src/internal/cluster" "github.com/defenseunicorns/zarf/src/pkg/message" "github.com/defenseunicorns/zarf/src/pkg/packager" "github.com/defenseunicorns/zarf/src/pkg/utils" @@ -47,6 +48,16 @@ var initCmd = &cobra.Command{ message.Fatal(err, err.Error()) } + // Check that the init package architecture is the same as the cluster architecture + var initPackageArch string + if strings.Contains(initPackageName, "arm64") { + initPackageArch = "arm64" + } + if strings.Contains(initPackageName, "amd64") { + initPackageArch = "amd64" + } + verifyArchitecture(initPackageArch) + // Ensure uppercase keys from viper viperConfig := utils.TransformMapKeys(v.GetStringMapString(V_PKG_DEPLOY_SET), strings.ToUpper) pkgConfig.DeployOpts.SetVariables = utils.MergeMap(viperConfig, pkgConfig.DeployOpts.SetVariables) @@ -137,6 +148,20 @@ func downloadInitPackage(initPackageName, downloadCacheTarget string) error { return nil } +// verifyArchitecture verifies that the init package architecture matches the cluster architecture. +func verifyArchitecture(initPackageArch string) { + c := cluster.NewClusterOrDie() + + clusterArch, err := c.Kube.GetArchitecture() + if err != nil { + message.Fatal(err, err.Error()) + } + + if initPackageArch != clusterArch { + message.Fatalf(err, "this init package architecture is %s, but this cluster has the %s architecture", initPackageArch, clusterArch) + } +} + func validateInitFlags() error { // If 'git-url' is provided, make sure they provided values for the username and password of the push user if pkgConfig.InitOpts.GitServer.Address != "" { diff --git a/src/test/e2e/29_mismatched_architectures_test.go b/src/test/e2e/29_mismatched_architectures_test.go new file mode 100644 index 0000000000..e936fe93be --- /dev/null +++ b/src/test/e2e/29_mismatched_architectures_test.go @@ -0,0 +1,45 @@ +// SPDX-License-Identifier: Apache-2.0 +// SPDX-FileCopyrightText: 2021-Present The Zarf Authors + +// Package test provides e2e tests for Zarf. +package test + +import ( + "fmt" + "os" + "strings" + "testing" + + "github.com/stretchr/testify/require" +) + +// TestMismatchedArchitectures ensures that zarf produces an error +// when the init package architecture doesn't match the cluster architecture. +func TestMismatchedArchitectures(t *testing.T) { + t.Log("E2E: Zarf init with mismatched architectures") + e2e.setupWithCluster(t) + defer e2e.teardown(t) + + var mismatchedArch string + if e2e.arch == "amd64" { + mismatchedArch = "arm64" + } + if e2e.arch == "arm64" { + mismatchedArch = "amd64" + } + + // Pull the current zarf binary version to find the corresponding init package + version, stdErr, err := e2e.execZarfCommand("version") + require.NoError(t, err, version, stdErr) + + initPackageName := fmt.Sprintf("build/zarf-init-%s-%s.tar.zst", e2e.arch, strings.TrimSpace(version)) + mismatchedInitPackage := fmt.Sprintf("build/zarf-init-%s-%s.tar.zst", mismatchedArch, strings.TrimSpace(version)) + + // Rename the init package with the mismatched architecture + err = os.Rename(initPackageName, mismatchedInitPackage) + require.NoError(t, err) + + // Check that zarf init returned an error because of the mismatched architectures + output, stdErr, err := e2e.execZarfCommand("init", "--confirm") + require.Error(t, err, output, stdErr) +} From dc2e5e7b65eb4f7f86ecf68f8e514d0dbce4b121 Mon Sep 17 00:00:00 2001 From: Lucas Rodriguez Date: Wed, 29 Mar 2023 13:55:06 -0500 Subject: [PATCH 02/53] Update test to use UnknownVersion as the init package version --- src/test/e2e/29_mismatched_architectures_test.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/test/e2e/29_mismatched_architectures_test.go b/src/test/e2e/29_mismatched_architectures_test.go index e936fe93be..466e76160b 100644 --- a/src/test/e2e/29_mismatched_architectures_test.go +++ b/src/test/e2e/29_mismatched_architectures_test.go @@ -28,15 +28,20 @@ func TestMismatchedArchitectures(t *testing.T) { mismatchedArch = "amd64" } - // Pull the current zarf binary version to find the corresponding init package - version, stdErr, err := e2e.execZarfCommand("version") - require.NoError(t, err, version, stdErr) + // // Pull the current zarf binary version to find the corresponding init package + // version, stdErr, err := e2e.execZarfCommand("version") + // require.NoError(t, err, version, stdErr) + version := "UnknownVersion" + + // This should be the name of the init package that was built during the 'Build binary and zarf packages' stage. initPackageName := fmt.Sprintf("build/zarf-init-%s-%s.tar.zst", e2e.arch, strings.TrimSpace(version)) + + // This should be the name of the built init package with the incorrect/opposite architecture of the machine we're running on. mismatchedInitPackage := fmt.Sprintf("build/zarf-init-%s-%s.tar.zst", mismatchedArch, strings.TrimSpace(version)) // Rename the init package with the mismatched architecture - err = os.Rename(initPackageName, mismatchedInitPackage) + err := os.Rename(initPackageName, mismatchedInitPackage) require.NoError(t, err) // Check that zarf init returned an error because of the mismatched architectures From b47750ae8d3890f8006e7f413120af3cd3d6bebb Mon Sep 17 00:00:00 2001 From: Lucas Rodriguez Date: Wed, 29 Mar 2023 15:50:42 -0500 Subject: [PATCH 03/53] Update test to use --architecture flag with zarf init --- src/test/e2e/29_mismatched_architectures_test.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/test/e2e/29_mismatched_architectures_test.go b/src/test/e2e/29_mismatched_architectures_test.go index 466e76160b..d458a20a19 100644 --- a/src/test/e2e/29_mismatched_architectures_test.go +++ b/src/test/e2e/29_mismatched_architectures_test.go @@ -44,7 +44,8 @@ func TestMismatchedArchitectures(t *testing.T) { err := os.Rename(initPackageName, mismatchedInitPackage) require.NoError(t, err) - // Check that zarf init returned an error because of the mismatched architectures - output, stdErr, err := e2e.execZarfCommand("init", "--confirm") + // Make sure zarf init returns an error because of the mismatched architectures. + // We need to use the --architecture flag here to force zarf to find the renamed package. + output, stdErr, err := e2e.execZarfCommand("init", "--architecture", mismatchedArch, "--confirm") require.Error(t, err, output, stdErr) } From e88fdf25008aab4c33d9c0c69ea2aba6813281d3 Mon Sep 17 00:00:00 2001 From: Lucas Rodriguez Date: Wed, 29 Mar 2023 16:55:53 -0500 Subject: [PATCH 04/53] Update verifyArchitecture function to handle appliance mode Update test to require the specific error string to be returned --- src/cmd/initialize.go | 27 +++++++++++++------ .../e2e/29_mismatched_architectures_test.go | 9 +++---- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/src/cmd/initialize.go b/src/cmd/initialize.go index 208679257e..0903c1ff00 100644 --- a/src/cmd/initialize.go +++ b/src/cmd/initialize.go @@ -10,6 +10,7 @@ import ( "os" "path" "path/filepath" + "runtime" "strings" "github.com/AlecAivazis/survey/v2" @@ -48,7 +49,7 @@ var initCmd = &cobra.Command{ message.Fatal(err, err.Error()) } - // Check that the init package architecture is the same as the cluster architecture + // Check that the init package architecture is the same as the target system architecture var initPackageArch string if strings.Contains(initPackageName, "arm64") { initPackageArch = "arm64" @@ -148,17 +149,27 @@ func downloadInitPackage(initPackageName, downloadCacheTarget string) error { return nil } -// verifyArchitecture verifies that the init package architecture matches the cluster architecture. +// verifyArchitecture verifies that the init package architecture matches the target system architecture. func verifyArchitecture(initPackageArch string) { - c := cluster.NewClusterOrDie() + components := pkgConfig.DeployOpts.Components + var systemArch string + var err error - clusterArch, err := c.Kube.GetArchitecture() - if err != nil { - message.Fatal(err, err.Error()) + // If we're not running in appliance mode (deploying k3s), query the existing cluster for the architecture. + // If we are running in appliance mode, get the architecture of the machine we're running on. + if !strings.Contains(components, "k3s") { + c := cluster.NewClusterOrDie() + systemArch, err = c.Kube.GetArchitecture() + + if err != nil { + message.Fatal(err, err.Error()) + } + } else { + systemArch = runtime.GOARCH } - if initPackageArch != clusterArch { - message.Fatalf(err, "this init package architecture is %s, but this cluster has the %s architecture", initPackageArch, clusterArch) + if initPackageArch != systemArch { + message.Fatalf(err, "this init package architecture is %s, but the target system has the %s architecture", initPackageArch, systemArch) } } diff --git a/src/test/e2e/29_mismatched_architectures_test.go b/src/test/e2e/29_mismatched_architectures_test.go index d458a20a19..e9f5f78144 100644 --- a/src/test/e2e/29_mismatched_architectures_test.go +++ b/src/test/e2e/29_mismatched_architectures_test.go @@ -28,10 +28,6 @@ func TestMismatchedArchitectures(t *testing.T) { mismatchedArch = "amd64" } - // // Pull the current zarf binary version to find the corresponding init package - // version, stdErr, err := e2e.execZarfCommand("version") - // require.NoError(t, err, version, stdErr) - version := "UnknownVersion" // This should be the name of the init package that was built during the 'Build binary and zarf packages' stage. @@ -46,6 +42,7 @@ func TestMismatchedArchitectures(t *testing.T) { // Make sure zarf init returns an error because of the mismatched architectures. // We need to use the --architecture flag here to force zarf to find the renamed package. - output, stdErr, err := e2e.execZarfCommand("init", "--architecture", mismatchedArch, "--confirm") - require.Error(t, err, output, stdErr) + _, _, err = e2e.execZarfCommand("init", "--architecture", mismatchedArch, "--confirm") + expectedErrorString := fmt.Sprintf("this init package architecture is %s, but the target system has the %s architecture", mismatchedArch, e2e.arch) + require.EqualError(t, err, expectedErrorString) } From 64cf9955de5cc212043e5d109c6ab73d1a2afbb5 Mon Sep 17 00:00:00 2001 From: Lucas Rodriguez Date: Wed, 29 Mar 2023 17:38:49 -0500 Subject: [PATCH 05/53] Add mismatched arch error message to lang package Use ErrorAs function in test to check for specific error message returned --- src/cmd/initialize.go | 2 +- src/config/lang/english.go | 11 ++++++----- src/test/e2e/29_mismatched_architectures_test.go | 5 +++-- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/cmd/initialize.go b/src/cmd/initialize.go index 0903c1ff00..17bc9bea21 100644 --- a/src/cmd/initialize.go +++ b/src/cmd/initialize.go @@ -169,7 +169,7 @@ func verifyArchitecture(initPackageArch string) { } if initPackageArch != systemArch { - message.Fatalf(err, "this init package architecture is %s, but the target system has the %s architecture", initPackageArch, systemArch) + message.Fatalf(err, lang.CmdInitErrVerifyArchitecture, initPackageArch, systemArch) } } diff --git a/src/config/lang/english.go b/src/config/lang/english.go index 293627300b..6425d9dc90 100644 --- a/src/config/lang/english.go +++ b/src/config/lang/english.go @@ -117,11 +117,12 @@ zarf init --registry-push-password={PASSWORD} --registry-push-username={USERNAME zarf init --git-push-password={PASSWORD} --git-push-username={USERNAME} --git-url={URL} ` - CmdInitErrFlags = "Invalid command flags were provided." - CmdInitErrDownload = "failed to download the init package: %s" - CmdInitErrValidateGit = "the 'git-push-username' and 'git-push-password' flags must be provided if the 'git-url' flag is provided" - CmdInitErrValidateRegistry = "the 'registry-push-username' and 'registry-push-password' flags must be provided if the 'registry-url' flag is provided " - CmdInitErrUnableCreateCache = "Unable to create the cache directory: %s" + CmdInitErrFlags = "Invalid command flags were provided." + CmdInitErrDownload = "failed to download the init package: %s" + CmdInitErrValidateGit = "the 'git-push-username' and 'git-push-password' flags must be provided if the 'git-url' flag is provided" + CmdInitErrValidateRegistry = "the 'registry-push-username' and 'registry-push-password' flags must be provided if the 'registry-url' flag is provided " + CmdInitErrVerifyArchitecture = "this init package architecture is %s, but the target system has the %s architecture" + CmdInitErrUnableCreateCache = "Unable to create the cache directory: %s" CmdInitDownloadAsk = "It seems the init package could not be found locally, but can be downloaded from %s" CmdInitDownloadNote = "Note: This will require an internet connection." diff --git a/src/test/e2e/29_mismatched_architectures_test.go b/src/test/e2e/29_mismatched_architectures_test.go index e9f5f78144..ca090e9d59 100644 --- a/src/test/e2e/29_mismatched_architectures_test.go +++ b/src/test/e2e/29_mismatched_architectures_test.go @@ -10,6 +10,7 @@ import ( "strings" "testing" + "github.com/defenseunicorns/zarf/src/config/lang" "github.com/stretchr/testify/require" ) @@ -43,6 +44,6 @@ func TestMismatchedArchitectures(t *testing.T) { // Make sure zarf init returns an error because of the mismatched architectures. // We need to use the --architecture flag here to force zarf to find the renamed package. _, _, err = e2e.execZarfCommand("init", "--architecture", mismatchedArch, "--confirm") - expectedErrorString := fmt.Sprintf("this init package architecture is %s, but the target system has the %s architecture", mismatchedArch, e2e.arch) - require.EqualError(t, err, expectedErrorString) + expectedErrorMessage := fmt.Sprintf(lang.CmdInitErrVerifyArchitecture, mismatchedArch, e2e.arch) + require.ErrorAs(t, err, expectedErrorMessage) } From 3616ef982ff97332f2751f99a6adc3460296da31 Mon Sep 17 00:00:00 2001 From: Lucas Rodriguez Date: Wed, 29 Mar 2023 18:02:06 -0500 Subject: [PATCH 06/53] Use the Contains function in test to check for error message --- src/test/e2e/29_mismatched_architectures_test.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/test/e2e/29_mismatched_architectures_test.go b/src/test/e2e/29_mismatched_architectures_test.go index ca090e9d59..bada113b7d 100644 --- a/src/test/e2e/29_mismatched_architectures_test.go +++ b/src/test/e2e/29_mismatched_architectures_test.go @@ -15,7 +15,7 @@ import ( ) // TestMismatchedArchitectures ensures that zarf produces an error -// when the init package architecture doesn't match the cluster architecture. +// when the init package architecture doesn't match the target system architecture. func TestMismatchedArchitectures(t *testing.T) { t.Log("E2E: Zarf init with mismatched architectures") e2e.setupWithCluster(t) @@ -37,7 +37,7 @@ func TestMismatchedArchitectures(t *testing.T) { // This should be the name of the built init package with the incorrect/opposite architecture of the machine we're running on. mismatchedInitPackage := fmt.Sprintf("build/zarf-init-%s-%s.tar.zst", mismatchedArch, strings.TrimSpace(version)) - // Rename the init package with the mismatched architecture + // Rename the init package with the mismatched architecture. err := os.Rename(initPackageName, mismatchedInitPackage) require.NoError(t, err) @@ -45,5 +45,6 @@ func TestMismatchedArchitectures(t *testing.T) { // We need to use the --architecture flag here to force zarf to find the renamed package. _, _, err = e2e.execZarfCommand("init", "--architecture", mismatchedArch, "--confirm") expectedErrorMessage := fmt.Sprintf(lang.CmdInitErrVerifyArchitecture, mismatchedArch, e2e.arch) - require.ErrorAs(t, err, expectedErrorMessage) + require.Error(t, err) + require.Contains(t, err.Error(), expectedErrorMessage) } From ffecbf9661d9bc63ef8945bf53fa540b1a9b2142 Mon Sep 17 00:00:00 2001 From: Lucas Rodriguez Date: Wed, 29 Mar 2023 19:23:29 -0500 Subject: [PATCH 07/53] Still trying to capture and validate the error message properly --- src/cmd/initialize.go | 5 ++++- src/test/e2e/29_mismatched_architectures_test.go | 9 +++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/cmd/initialize.go b/src/cmd/initialize.go index 17bc9bea21..adb5f8a762 100644 --- a/src/cmd/initialize.go +++ b/src/cmd/initialize.go @@ -49,14 +49,17 @@ var initCmd = &cobra.Command{ message.Fatal(err, err.Error()) } - // Check that the init package architecture is the same as the target system architecture + // Check that the init package architecture is the same as the target system architecture. var initPackageArch string + if strings.Contains(initPackageName, "arm64") { initPackageArch = "arm64" } + if strings.Contains(initPackageName, "amd64") { initPackageArch = "amd64" } + verifyArchitecture(initPackageArch) // Ensure uppercase keys from viper diff --git a/src/test/e2e/29_mismatched_architectures_test.go b/src/test/e2e/29_mismatched_architectures_test.go index bada113b7d..29fc3609ae 100644 --- a/src/test/e2e/29_mismatched_architectures_test.go +++ b/src/test/e2e/29_mismatched_architectures_test.go @@ -22,9 +22,11 @@ func TestMismatchedArchitectures(t *testing.T) { defer e2e.teardown(t) var mismatchedArch string + if e2e.arch == "amd64" { mismatchedArch = "arm64" } + if e2e.arch == "arm64" { mismatchedArch = "amd64" } @@ -43,8 +45,7 @@ func TestMismatchedArchitectures(t *testing.T) { // Make sure zarf init returns an error because of the mismatched architectures. // We need to use the --architecture flag here to force zarf to find the renamed package. - _, _, err = e2e.execZarfCommand("init", "--architecture", mismatchedArch, "--confirm") - expectedErrorMessage := fmt.Sprintf(lang.CmdInitErrVerifyArchitecture, mismatchedArch, e2e.arch) - require.Error(t, err) - require.Contains(t, err.Error(), expectedErrorMessage) + stdOut, stdErr, err := e2e.execZarfCommand("init", "--architecture", mismatchedArch, "--confirm") + require.Error(t, err, stdOut, stdErr) + require.Containsf(t, stdErr, lang.CmdInitErrVerifyArchitecture, mismatchedArch, e2e.arch) } From edd5b1f08e0f70151a645c4f316ed7c582a3d8dd Mon Sep 17 00:00:00 2001 From: Lucas Rodriguez Date: Wed, 29 Mar 2023 19:46:55 -0500 Subject: [PATCH 08/53] Still messing with error output --- src/test/e2e/29_mismatched_architectures_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/e2e/29_mismatched_architectures_test.go b/src/test/e2e/29_mismatched_architectures_test.go index 29fc3609ae..352b474b9d 100644 --- a/src/test/e2e/29_mismatched_architectures_test.go +++ b/src/test/e2e/29_mismatched_architectures_test.go @@ -47,5 +47,5 @@ func TestMismatchedArchitectures(t *testing.T) { // We need to use the --architecture flag here to force zarf to find the renamed package. stdOut, stdErr, err := e2e.execZarfCommand("init", "--architecture", mismatchedArch, "--confirm") require.Error(t, err, stdOut, stdErr) - require.Containsf(t, stdErr, lang.CmdInitErrVerifyArchitecture, mismatchedArch, e2e.arch) + require.Containsf(t, stdErr, lang.CmdInitErrVerifyArchitecture, "This error message should contain a description for mismatched architectures.") } From 1d4773a884e0397ef559c61460b9e8b6e671473c Mon Sep 17 00:00:00 2001 From: Lucas Rodriguez Date: Wed, 29 Mar 2023 20:12:39 -0500 Subject: [PATCH 09/53] Format error message before checking for it --- src/test/e2e/29_mismatched_architectures_test.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/test/e2e/29_mismatched_architectures_test.go b/src/test/e2e/29_mismatched_architectures_test.go index 352b474b9d..cb16c96193 100644 --- a/src/test/e2e/29_mismatched_architectures_test.go +++ b/src/test/e2e/29_mismatched_architectures_test.go @@ -45,7 +45,8 @@ func TestMismatchedArchitectures(t *testing.T) { // Make sure zarf init returns an error because of the mismatched architectures. // We need to use the --architecture flag here to force zarf to find the renamed package. - stdOut, stdErr, err := e2e.execZarfCommand("init", "--architecture", mismatchedArch, "--confirm") - require.Error(t, err, stdOut, stdErr) - require.Containsf(t, stdErr, lang.CmdInitErrVerifyArchitecture, "This error message should contain a description for mismatched architectures.") + _, stdErr, err := e2e.execZarfCommand("init", "--architecture", mismatchedArch, "--confirm") + require.Error(t, err, stdErr) + expectedErrorMessage := fmt.Sprintf(lang.CmdInitErrVerifyArchitecture, mismatchedArch, e2e.arch) + require.Contains(t, stdErr, expectedErrorMessage) } From e8257809ee057463c7a06ae4d6c8a69e5a4d0053 Mon Sep 17 00:00:00 2001 From: Lucas Rodriguez Date: Thu, 30 Mar 2023 13:06:05 -0500 Subject: [PATCH 10/53] Remove use of TrimSpace for zarf version --- src/test/e2e/29_mismatched_architectures_test.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/test/e2e/29_mismatched_architectures_test.go b/src/test/e2e/29_mismatched_architectures_test.go index cb16c96193..00f5f2cf6d 100644 --- a/src/test/e2e/29_mismatched_architectures_test.go +++ b/src/test/e2e/29_mismatched_architectures_test.go @@ -7,7 +7,6 @@ package test import ( "fmt" "os" - "strings" "testing" "github.com/defenseunicorns/zarf/src/config/lang" @@ -34,10 +33,10 @@ func TestMismatchedArchitectures(t *testing.T) { version := "UnknownVersion" // This should be the name of the init package that was built during the 'Build binary and zarf packages' stage. - initPackageName := fmt.Sprintf("build/zarf-init-%s-%s.tar.zst", e2e.arch, strings.TrimSpace(version)) + initPackageName := fmt.Sprintf("build/zarf-init-%s-%s.tar.zst", e2e.arch, version) // This should be the name of the built init package with the incorrect/opposite architecture of the machine we're running on. - mismatchedInitPackage := fmt.Sprintf("build/zarf-init-%s-%s.tar.zst", mismatchedArch, strings.TrimSpace(version)) + mismatchedInitPackage := fmt.Sprintf("build/zarf-init-%s-%s.tar.zst", mismatchedArch, version) // Rename the init package with the mismatched architecture. err := os.Rename(initPackageName, mismatchedInitPackage) From 2b93e2625d538bc86592aa4717c7754e0bfac420 Mon Sep 17 00:00:00 2001 From: Lucas Rodriguez Date: Thu, 30 Mar 2023 15:07:42 -0500 Subject: [PATCH 11/53] Use arch field from Packager struct to get init package architecture --- src/cmd/initialize.go | 27 +++++++++++---------------- src/cmd/root.go | 3 +++ src/pkg/packager/common.go | 8 ++++---- src/pkg/packager/components.go | 4 ++-- src/pkg/packager/compose.go | 2 +- src/pkg/packager/deploy.go | 4 ++-- src/pkg/packager/variables.go | 2 +- src/pkg/packager/yaml.go | 6 +++--- 8 files changed, 27 insertions(+), 29 deletions(-) diff --git a/src/cmd/initialize.go b/src/cmd/initialize.go index adb5f8a762..be85954df6 100644 --- a/src/cmd/initialize.go +++ b/src/cmd/initialize.go @@ -12,6 +12,7 @@ import ( "path/filepath" "runtime" "strings" + "time" "github.com/AlecAivazis/survey/v2" "github.com/defenseunicorns/zarf/src/config" @@ -50,17 +51,7 @@ var initCmd = &cobra.Command{ } // Check that the init package architecture is the same as the target system architecture. - var initPackageArch string - - if strings.Contains(initPackageName, "arm64") { - initPackageArch = "arm64" - } - - if strings.Contains(initPackageName, "amd64") { - initPackageArch = "amd64" - } - - verifyArchitecture(initPackageArch) + verifyArchitecture() // Ensure uppercase keys from viper viperConfig := utils.TransformMapKeys(v.GetStringMapString(V_PKG_DEPLOY_SET), strings.ToUpper) @@ -153,17 +144,21 @@ func downloadInitPackage(initPackageName, downloadCacheTarget string) error { } // verifyArchitecture verifies that the init package architecture matches the target system architecture. -func verifyArchitecture(initPackageArch string) { +func verifyArchitecture() { components := pkgConfig.DeployOpts.Components + var systemArch string var err error // If we're not running in appliance mode (deploying k3s), query the existing cluster for the architecture. // If we are running in appliance mode, get the architecture of the machine we're running on. if !strings.Contains(components, "k3s") { - c := cluster.NewClusterOrDie() - systemArch, err = c.Kube.GetArchitecture() + c, err := cluster.NewClusterWithWait(30 * time.Second) + if err != nil { + message.Fatal(err, err.Error()) + } + systemArch, err = c.Kube.GetArchitecture() if err != nil { message.Fatal(err, err.Error()) } @@ -171,8 +166,8 @@ func verifyArchitecture(initPackageArch string) { systemArch = runtime.GOARCH } - if initPackageArch != systemArch { - message.Fatalf(err, lang.CmdInitErrVerifyArchitecture, initPackageArch, systemArch) + if pkg.Arch != systemArch { + message.Fatalf(err, lang.CmdInitErrVerifyArchitecture, pkg.Arch, systemArch) } } diff --git a/src/cmd/root.go b/src/cmd/root.go index 28b5e80654..72c2a85f12 100644 --- a/src/cmd/root.go +++ b/src/cmd/root.go @@ -13,6 +13,7 @@ import ( "github.com/defenseunicorns/zarf/src/config" "github.com/defenseunicorns/zarf/src/config/lang" "github.com/defenseunicorns/zarf/src/pkg/message" + "github.com/defenseunicorns/zarf/src/pkg/packager" "github.com/defenseunicorns/zarf/src/types" "github.com/pterm/pterm" "github.com/spf13/cobra" @@ -26,6 +27,8 @@ var ( // Default global config for the CLI pkgConfig = types.PackagerConfig{} + pkg = packager.Packager{} + // Viper instance used by the cmd package v *viper.Viper ) diff --git a/src/pkg/packager/common.go b/src/pkg/packager/common.go index 005635a926..09cc3b037a 100644 --- a/src/pkg/packager/common.go +++ b/src/pkg/packager/common.go @@ -30,7 +30,7 @@ type Packager struct { cfg *types.PackagerConfig cluster *cluster.Cluster tmp types.TempPaths - arch string + Arch string } /* @@ -96,7 +96,7 @@ func (p *Packager) GetPackageName() string { message.Debugf("packager.GetPackageName(%s)", message.JSONValue(p)) if p.cfg.IsInitConfig { - return GetInitPackageName(p.arch) + return GetInitPackageName(p.Arch) } packageName := p.cfg.Pkg.Metadata.Name @@ -106,10 +106,10 @@ func (p *Packager) GetPackageName() string { } if p.cfg.Pkg.Metadata.Version == "" { - return fmt.Sprintf("%s%s-%s.%s", config.ZarfPackagePrefix, packageName, p.arch, suffix) + return fmt.Sprintf("%s%s-%s.%s", config.ZarfPackagePrefix, packageName, p.Arch, suffix) } - return fmt.Sprintf("%s%s-%s-%s.%s", config.ZarfPackagePrefix, packageName, p.arch, p.cfg.Pkg.Metadata.Version, suffix) + return fmt.Sprintf("%s%s-%s-%s.%s", config.ZarfPackagePrefix, packageName, p.Arch, p.cfg.Pkg.Metadata.Version, suffix) } // ClearTempPaths removes the temp directory and any files within it. diff --git a/src/pkg/packager/components.go b/src/pkg/packager/components.go index c88aa84a62..d4a4c900eb 100644 --- a/src/pkg/packager/components.go +++ b/src/pkg/packager/components.go @@ -104,10 +104,10 @@ func (p *Packager) isCompatibleComponent(component types.ZarfComponent, filterBy var validArch, validOS bool // Test for valid architecture - if component.Only.Cluster.Architecture == "" || component.Only.Cluster.Architecture == p.arch { + if component.Only.Cluster.Architecture == "" || component.Only.Cluster.Architecture == p.Arch { validArch = true } else { - message.Debugf("Skipping component %s, %s is not compatible with %s", component.Name, component.Only.Cluster.Architecture, p.arch) + message.Debugf("Skipping component %s, %s is not compatible with %s", component.Name, component.Only.Cluster.Architecture, p.Arch) } // Test for a valid OS diff --git a/src/pkg/packager/compose.go b/src/pkg/packager/compose.go index 3a5b242420..4c2ccd88e8 100644 --- a/src/pkg/packager/compose.go +++ b/src/pkg/packager/compose.go @@ -99,7 +99,7 @@ func (p *Packager) getChildComponent(parent types.ZarfComponent, pathAncestry st } // Only add this component if it is valid for the target architecture. - if filterArch == "" || filterArch == p.arch { + if filterArch == "" || filterArch == p.Arch { child = component break } diff --git a/src/pkg/packager/deploy.go b/src/pkg/packager/deploy.go index ae9ef00049..f6c70e3e54 100644 --- a/src/pkg/packager/deploy.go +++ b/src/pkg/packager/deploy.go @@ -370,10 +370,10 @@ func (p *Packager) getUpdatedValueTemplate(component types.ZarfComponent) (value } // Only check the architecture if the package has images - if len(component.Images) > 0 && state.Architecture != p.arch { + if len(component.Images) > 0 && state.Architecture != p.Arch { // If the package has images but the architectures don't match, fail the deployment and warn the user to avoid ugly hidden errors with image push/pull return values, fmt.Errorf("this package architecture is %s, but this cluster seems to be initialized with the %s architecture", - p.arch, state.Architecture) + p.Arch, state.Architecture) } spinner.Success() diff --git a/src/pkg/packager/variables.go b/src/pkg/packager/variables.go index 1b11b88156..1badd50458 100644 --- a/src/pkg/packager/variables.go +++ b/src/pkg/packager/variables.go @@ -47,7 +47,7 @@ func (p *Packager) fillActiveTemplate() error { } // Add special variable for the current package architecture - templateMap["###ZARF_PKG_ARCH###"] = p.arch + templateMap["###ZARF_PKG_ARCH###"] = p.Arch return utils.ReloadYamlTemplate(&p.cfg.Pkg, templateMap) } diff --git a/src/pkg/packager/yaml.go b/src/pkg/packager/yaml.go index 70278d5f79..85cdaff60a 100644 --- a/src/pkg/packager/yaml.go +++ b/src/pkg/packager/yaml.go @@ -24,7 +24,7 @@ func (p *Packager) readYaml(path string, filterByOS bool) error { } // Set the arch from the package config before filtering. - p.arch = config.GetArch(p.cfg.Pkg.Metadata.Architecture, p.cfg.Pkg.Build.Architecture) + p.Arch = config.GetArch(p.cfg.Pkg.Metadata.Architecture, p.cfg.Pkg.Build.Architecture) // Filter each component to only compatible platforms. filteredComponents := []types.ZarfComponent{} @@ -55,8 +55,8 @@ func (p *Packager) writeYaml() error { hostname, hostErr := os.Hostname() // Normalize these for the package confirmation. - p.cfg.Pkg.Metadata.Architecture = p.arch - p.cfg.Pkg.Build.Architecture = p.arch + p.cfg.Pkg.Metadata.Architecture = p.Arch + p.cfg.Pkg.Build.Architecture = p.Arch // Record the time of package creation. p.cfg.Pkg.Build.Timestamp = now.Format(time.RFC1123Z) From f560f188b6f857dec507b58f83bcd950f5576f3c Mon Sep 17 00:00:00 2001 From: Lucas Rodriguez Date: Thu, 30 Mar 2023 15:27:25 -0500 Subject: [PATCH 12/53] Go back to using NewClusterOrDie --- src/cmd/initialize.go | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/cmd/initialize.go b/src/cmd/initialize.go index be85954df6..fe59ca3027 100644 --- a/src/cmd/initialize.go +++ b/src/cmd/initialize.go @@ -12,7 +12,6 @@ import ( "path/filepath" "runtime" "strings" - "time" "github.com/AlecAivazis/survey/v2" "github.com/defenseunicorns/zarf/src/config" @@ -153,10 +152,7 @@ func verifyArchitecture() { // If we're not running in appliance mode (deploying k3s), query the existing cluster for the architecture. // If we are running in appliance mode, get the architecture of the machine we're running on. if !strings.Contains(components, "k3s") { - c, err := cluster.NewClusterWithWait(30 * time.Second) - if err != nil { - message.Fatal(err, err.Error()) - } + c := cluster.NewClusterOrDie() systemArch, err = c.Kube.GetArchitecture() if err != nil { From 27b5e04a54891a26a5bcfb2d48a0cbf411559ceb Mon Sep 17 00:00:00 2001 From: Lucas Rodriguez Date: Fri, 31 Mar 2023 14:25:18 -0500 Subject: [PATCH 13/53] Revert back to getting package arch from package name --- src/cmd/initialize.go | 15 +++++++++++---- src/cmd/root.go | 3 --- src/pkg/packager/common.go | 8 ++++---- src/pkg/packager/components.go | 4 ++-- src/pkg/packager/compose.go | 2 +- src/pkg/packager/deploy.go | 4 ++-- src/pkg/packager/variables.go | 2 +- src/pkg/packager/yaml.go | 6 +++--- 8 files changed, 24 insertions(+), 20 deletions(-) diff --git a/src/cmd/initialize.go b/src/cmd/initialize.go index fe59ca3027..5967b0ae3f 100644 --- a/src/cmd/initialize.go +++ b/src/cmd/initialize.go @@ -50,7 +50,14 @@ var initCmd = &cobra.Command{ } // Check that the init package architecture is the same as the target system architecture. - verifyArchitecture() + var initPackageArch string + if strings.Contains(initPackageName, "amd64") { + initPackageArch = "amd64" + } + if strings.Contains(initPackageName, "arm64") { + initPackageArch = "arm64" + } + verifyArchitecture(initPackageArch) // Ensure uppercase keys from viper viperConfig := utils.TransformMapKeys(v.GetStringMapString(V_PKG_DEPLOY_SET), strings.ToUpper) @@ -143,7 +150,7 @@ func downloadInitPackage(initPackageName, downloadCacheTarget string) error { } // verifyArchitecture verifies that the init package architecture matches the target system architecture. -func verifyArchitecture() { +func verifyArchitecture(initPackageArch string) { components := pkgConfig.DeployOpts.Components var systemArch string @@ -162,8 +169,8 @@ func verifyArchitecture() { systemArch = runtime.GOARCH } - if pkg.Arch != systemArch { - message.Fatalf(err, lang.CmdInitErrVerifyArchitecture, pkg.Arch, systemArch) + if initPackageArch != systemArch { + message.Fatalf(err, lang.CmdInitErrVerifyArchitecture, initPackageArch, systemArch) } } diff --git a/src/cmd/root.go b/src/cmd/root.go index 72c2a85f12..28b5e80654 100644 --- a/src/cmd/root.go +++ b/src/cmd/root.go @@ -13,7 +13,6 @@ import ( "github.com/defenseunicorns/zarf/src/config" "github.com/defenseunicorns/zarf/src/config/lang" "github.com/defenseunicorns/zarf/src/pkg/message" - "github.com/defenseunicorns/zarf/src/pkg/packager" "github.com/defenseunicorns/zarf/src/types" "github.com/pterm/pterm" "github.com/spf13/cobra" @@ -27,8 +26,6 @@ var ( // Default global config for the CLI pkgConfig = types.PackagerConfig{} - pkg = packager.Packager{} - // Viper instance used by the cmd package v *viper.Viper ) diff --git a/src/pkg/packager/common.go b/src/pkg/packager/common.go index 09cc3b037a..005635a926 100644 --- a/src/pkg/packager/common.go +++ b/src/pkg/packager/common.go @@ -30,7 +30,7 @@ type Packager struct { cfg *types.PackagerConfig cluster *cluster.Cluster tmp types.TempPaths - Arch string + arch string } /* @@ -96,7 +96,7 @@ func (p *Packager) GetPackageName() string { message.Debugf("packager.GetPackageName(%s)", message.JSONValue(p)) if p.cfg.IsInitConfig { - return GetInitPackageName(p.Arch) + return GetInitPackageName(p.arch) } packageName := p.cfg.Pkg.Metadata.Name @@ -106,10 +106,10 @@ func (p *Packager) GetPackageName() string { } if p.cfg.Pkg.Metadata.Version == "" { - return fmt.Sprintf("%s%s-%s.%s", config.ZarfPackagePrefix, packageName, p.Arch, suffix) + return fmt.Sprintf("%s%s-%s.%s", config.ZarfPackagePrefix, packageName, p.arch, suffix) } - return fmt.Sprintf("%s%s-%s-%s.%s", config.ZarfPackagePrefix, packageName, p.Arch, p.cfg.Pkg.Metadata.Version, suffix) + return fmt.Sprintf("%s%s-%s-%s.%s", config.ZarfPackagePrefix, packageName, p.arch, p.cfg.Pkg.Metadata.Version, suffix) } // ClearTempPaths removes the temp directory and any files within it. diff --git a/src/pkg/packager/components.go b/src/pkg/packager/components.go index d4a4c900eb..c88aa84a62 100644 --- a/src/pkg/packager/components.go +++ b/src/pkg/packager/components.go @@ -104,10 +104,10 @@ func (p *Packager) isCompatibleComponent(component types.ZarfComponent, filterBy var validArch, validOS bool // Test for valid architecture - if component.Only.Cluster.Architecture == "" || component.Only.Cluster.Architecture == p.Arch { + if component.Only.Cluster.Architecture == "" || component.Only.Cluster.Architecture == p.arch { validArch = true } else { - message.Debugf("Skipping component %s, %s is not compatible with %s", component.Name, component.Only.Cluster.Architecture, p.Arch) + message.Debugf("Skipping component %s, %s is not compatible with %s", component.Name, component.Only.Cluster.Architecture, p.arch) } // Test for a valid OS diff --git a/src/pkg/packager/compose.go b/src/pkg/packager/compose.go index 864d7302bb..8a70cf5e79 100644 --- a/src/pkg/packager/compose.go +++ b/src/pkg/packager/compose.go @@ -99,7 +99,7 @@ func (p *Packager) getChildComponent(parent types.ZarfComponent, pathAncestry st } // Only add this component if it is valid for the target architecture. - if filterArch == "" || filterArch == p.Arch { + if filterArch == "" || filterArch == p.arch { child = component break } diff --git a/src/pkg/packager/deploy.go b/src/pkg/packager/deploy.go index f6c70e3e54..ae9ef00049 100644 --- a/src/pkg/packager/deploy.go +++ b/src/pkg/packager/deploy.go @@ -370,10 +370,10 @@ func (p *Packager) getUpdatedValueTemplate(component types.ZarfComponent) (value } // Only check the architecture if the package has images - if len(component.Images) > 0 && state.Architecture != p.Arch { + if len(component.Images) > 0 && state.Architecture != p.arch { // If the package has images but the architectures don't match, fail the deployment and warn the user to avoid ugly hidden errors with image push/pull return values, fmt.Errorf("this package architecture is %s, but this cluster seems to be initialized with the %s architecture", - p.Arch, state.Architecture) + p.arch, state.Architecture) } spinner.Success() diff --git a/src/pkg/packager/variables.go b/src/pkg/packager/variables.go index 1badd50458..1b11b88156 100644 --- a/src/pkg/packager/variables.go +++ b/src/pkg/packager/variables.go @@ -47,7 +47,7 @@ func (p *Packager) fillActiveTemplate() error { } // Add special variable for the current package architecture - templateMap["###ZARF_PKG_ARCH###"] = p.Arch + templateMap["###ZARF_PKG_ARCH###"] = p.arch return utils.ReloadYamlTemplate(&p.cfg.Pkg, templateMap) } diff --git a/src/pkg/packager/yaml.go b/src/pkg/packager/yaml.go index 85cdaff60a..70278d5f79 100644 --- a/src/pkg/packager/yaml.go +++ b/src/pkg/packager/yaml.go @@ -24,7 +24,7 @@ func (p *Packager) readYaml(path string, filterByOS bool) error { } // Set the arch from the package config before filtering. - p.Arch = config.GetArch(p.cfg.Pkg.Metadata.Architecture, p.cfg.Pkg.Build.Architecture) + p.arch = config.GetArch(p.cfg.Pkg.Metadata.Architecture, p.cfg.Pkg.Build.Architecture) // Filter each component to only compatible platforms. filteredComponents := []types.ZarfComponent{} @@ -55,8 +55,8 @@ func (p *Packager) writeYaml() error { hostname, hostErr := os.Hostname() // Normalize these for the package confirmation. - p.cfg.Pkg.Metadata.Architecture = p.Arch - p.cfg.Pkg.Build.Architecture = p.Arch + p.cfg.Pkg.Metadata.Architecture = p.arch + p.cfg.Pkg.Build.Architecture = p.arch // Record the time of package creation. p.cfg.Pkg.Build.Timestamp = now.Format(time.RFC1123Z) From 3cad48027d504d60b54c0352f4a5932ade94aa6e Mon Sep 17 00:00:00 2001 From: Lucas Rodriguez Date: Wed, 5 Apr 2023 19:46:30 -0500 Subject: [PATCH 14/53] Refactor package architecture validation Get pkg arch from pkg metatdata rather than built package name Make check for appliance mode more reliable Refactor test to create new packages to test against --- src/cmd/initialize.go | 37 ---------------- src/config/lang/english.go | 24 +++++------ src/pkg/packager/common.go | 38 ++++++++++++++++ src/pkg/packager/deploy.go | 4 ++ .../e2e/29_mismatched_architectures_test.go | 43 ++++++++++++------- .../deploy/zarf.yaml | 7 +++ .../init/zarf.yaml | 7 +++ 7 files changed, 96 insertions(+), 64 deletions(-) create mode 100644 src/test/test-packages/29-mismatched-architectures/deploy/zarf.yaml create mode 100644 src/test/test-packages/29-mismatched-architectures/init/zarf.yaml diff --git a/src/cmd/initialize.go b/src/cmd/initialize.go index 99f6412998..3674516f5c 100644 --- a/src/cmd/initialize.go +++ b/src/cmd/initialize.go @@ -10,13 +10,11 @@ import ( "os" "path" "path/filepath" - "runtime" "strings" "github.com/AlecAivazis/survey/v2" "github.com/defenseunicorns/zarf/src/config" "github.com/defenseunicorns/zarf/src/config/lang" - "github.com/defenseunicorns/zarf/src/internal/cluster" "github.com/defenseunicorns/zarf/src/pkg/message" "github.com/defenseunicorns/zarf/src/pkg/packager" "github.com/defenseunicorns/zarf/src/pkg/utils" @@ -49,16 +47,6 @@ var initCmd = &cobra.Command{ message.Fatal(err, err.Error()) } - // Check that the init package architecture is the same as the target system architecture. - var initPackageArch string - if strings.Contains(initPackageName, "amd64") { - initPackageArch = "amd64" - } - if strings.Contains(initPackageName, "arm64") { - initPackageArch = "arm64" - } - verifyArchitecture(initPackageArch) - // Ensure uppercase keys from viper viperConfig := utils.TransformMapKeys(v.GetStringMapString(V_PKG_DEPLOY_SET), strings.ToUpper) pkgConfig.DeployOpts.SetVariables = utils.MergeMap(viperConfig, pkgConfig.DeployOpts.SetVariables) @@ -149,31 +137,6 @@ func downloadInitPackage(initPackageName, downloadCacheTarget string) error { return nil } -// verifyArchitecture verifies that the init package architecture matches the target system architecture. -func verifyArchitecture(initPackageArch string) { - components := pkgConfig.DeployOpts.Components - - var systemArch string - var err error - - // If we're not running in appliance mode (deploying k3s), query the existing cluster for the architecture. - // If we are running in appliance mode, get the architecture of the machine we're running on. - if !strings.Contains(components, "k3s") { - c := cluster.NewClusterOrDie() - - systemArch, err = c.Kube.GetArchitecture() - if err != nil { - message.Fatal(err, err.Error()) - } - } else { - systemArch = runtime.GOARCH - } - - if initPackageArch != systemArch { - message.Fatalf(err, lang.CmdInitErrVerifyArchitecture, initPackageArch, systemArch) - } -} - func validateInitFlags() error { // If 'git-url' is provided, make sure they provided values for the username and password of the push user if pkgConfig.InitOpts.GitServer.Address != "" { diff --git a/src/config/lang/english.go b/src/config/lang/english.go index a0a89df442..80c60e0307 100644 --- a/src/config/lang/english.go +++ b/src/config/lang/english.go @@ -117,12 +117,11 @@ zarf init --registry-push-password={PASSWORD} --registry-push-username={USERNAME zarf init --git-push-password={PASSWORD} --git-push-username={USERNAME} --git-url={URL} ` - CmdInitErrFlags = "Invalid command flags were provided." - CmdInitErrDownload = "failed to download the init package: %s" - CmdInitErrValidateGit = "the 'git-push-username' and 'git-push-password' flags must be provided if the 'git-url' flag is provided" - CmdInitErrValidateRegistry = "the 'registry-push-username' and 'registry-push-password' flags must be provided if the 'registry-url' flag is provided " - CmdInitErrVerifyArchitecture = "this init package architecture is %s, but the target system has the %s architecture" - CmdInitErrUnableCreateCache = "Unable to create the cache directory: %s" + CmdInitErrFlags = "Invalid command flags were provided." + CmdInitErrDownload = "failed to download the init package: %s" + CmdInitErrValidateGit = "the 'git-push-username' and 'git-push-password' flags must be provided if the 'git-url' flag is provided" + CmdInitErrValidateRegistry = "the 'registry-push-username' and 'registry-push-password' flags must be provided if the 'registry-url' flag is provided " + CmdInitErrUnableCreateCache = "Unable to create the cache directory: %s" CmdInitDownloadAsk = "It seems the init package could not be found locally, but can be downloaded from %s" CmdInitDownloadNote = "Note: This will require an internet connection." @@ -211,12 +210,13 @@ zarf init --git-push-password={PASSWORD} --git-push-username={USERNAME} --git-ur CmdPackageCreateFlagSigningKey = "Path to private key file for signing packages" CmdPackageCreateFlagSigningKeyPassword = "Password to the private key file used for signing packages" - CmdPackageDeployFlagConfirm = "Confirm package deployment without prompting" - CmdPackageDeployFlagSet = "Specify deployment variables to set on the command line (KEY=value)" - CmdPackageDeployFlagComponents = "Comma-separated list of components to install. Adding this flag will skip the init prompts for which components to install" - CmdPackageDeployFlagShasum = "Shasum of the package to deploy. Required if deploying a remote package and \"--insecure\" is not provided" - CmdPackageDeployFlagSget = "Path to public sget key file for remote packages signed via cosign" - CmdPackageDeployFlagPublicKey = "Path to public key file for validating signed packages" + CmdPackageDeployFlagConfirm = "Confirm package deployment without prompting" + CmdPackageDeployFlagSet = "Specify deployment variables to set on the command line (KEY=value)" + CmdPackageDeployFlagComponents = "Comma-separated list of components to install. Adding this flag will skip the init prompts for which components to install" + CmdPackageDeployFlagShasum = "Shasum of the package to deploy. Required if deploying a remote package and \"--insecure\" is not provided" + CmdPackageDeployFlagSget = "Path to public sget key file for remote packages signed via cosign" + CmdPackageDeployFlagPublicKey = "Path to public key file for validating signed packages" + CmdPackageDeployValidateArchitectureErr = "this package architecture is %s, but the target cluster has the %s architecture. These architectures must be the same" CmdPackageInspectFlagSbom = "View SBOM contents while inspecting the package" CmdPackageInspectFlagSbomOut = "Specify an output directory for the SBOMs from the inspected Zarf package" diff --git a/src/pkg/packager/common.go b/src/pkg/packager/common.go index a55bf87465..4421f01bc6 100644 --- a/src/pkg/packager/common.go +++ b/src/pkg/packager/common.go @@ -12,16 +12,19 @@ import ( "io" "os" "path/filepath" + "runtime" "sort" "strings" "github.com/AlecAivazis/survey/v2" + "github.com/defenseunicorns/zarf/src/config/lang" "github.com/defenseunicorns/zarf/src/internal/cluster" "github.com/defenseunicorns/zarf/src/internal/packager/sbom" "github.com/defenseunicorns/zarf/src/types" "github.com/mholt/archiver/v3" "github.com/defenseunicorns/zarf/src/config" + "github.com/defenseunicorns/zarf/src/pkg/k8s" "github.com/defenseunicorns/zarf/src/pkg/message" "github.com/defenseunicorns/zarf/src/pkg/packager/deprecated" "github.com/defenseunicorns/zarf/src/pkg/utils" @@ -440,6 +443,41 @@ func (p *Packager) validatePackageChecksums() error { return nil } +// validatePackageArchitecture validates that the package architecture matches the target cluster architecture. +func (p *Packager) validatePackageArchitecture() error { + components := p.getValidComponents() + + var clusterArch string + var err error + + // Iterate over the components to determine if we're deploying an init package with k3s, + // and set appliance mode to true if we are. + for _, component := range components { + if component.Name == k8s.DistroIsK3s && p.cfg.IsInitConfig { + p.cfg.InitOpts.ApplianceMode = true + } + } + + // If we're deploying an appliance mode init package, set the cluster arch to the machine we're running on. + // If we're not deploying an appliance mode init package, attempt to query existing cluster for the arch. + if p.cfg.InitOpts.ApplianceMode { + clusterArch = runtime.GOARCH + } else { + c := cluster.NewClusterOrDie() + + clusterArch, err = c.Kube.GetArchitecture() + if err != nil { + return err + } + } + + if p.arch != clusterArch { + return fmt.Errorf(lang.CmdPackageDeployValidateArchitectureErr, p.arch, clusterArch) + } + + return nil +} + func (p *Packager) validatePackageSignature(publicKeyPath string) error { // If the insecure flag was provided, ignore the signature validation diff --git a/src/pkg/packager/deploy.go b/src/pkg/packager/deploy.go index 028c8b2808..7fa8266671 100644 --- a/src/pkg/packager/deploy.go +++ b/src/pkg/packager/deploy.go @@ -51,6 +51,10 @@ func (p *Packager) Deploy() error { p.cfg.IsInitConfig = true } + if err := p.validatePackageArchitecture(); err != nil { + return err + } + // Confirm the overall package deployment if !p.confirmAction("Deploy", p.cfg.SBOMViewFiles) { return fmt.Errorf("deployment cancelled") diff --git a/src/test/e2e/29_mismatched_architectures_test.go b/src/test/e2e/29_mismatched_architectures_test.go index 00f5f2cf6d..1873d4286d 100644 --- a/src/test/e2e/29_mismatched_architectures_test.go +++ b/src/test/e2e/29_mismatched_architectures_test.go @@ -6,7 +6,7 @@ package test import ( "fmt" - "os" + "path/filepath" "testing" "github.com/defenseunicorns/zarf/src/config/lang" @@ -20,32 +20,45 @@ func TestMismatchedArchitectures(t *testing.T) { e2e.setupWithCluster(t) defer e2e.teardown(t) + // Determine what test runner architecture we're running on, + // and set mismatchedArch to the opposite architecture. var mismatchedArch string - if e2e.arch == "amd64" { mismatchedArch = "arm64" } - if e2e.arch == "arm64" { mismatchedArch = "amd64" } - version := "UnknownVersion" - - // This should be the name of the init package that was built during the 'Build binary and zarf packages' stage. - initPackageName := fmt.Sprintf("build/zarf-init-%s-%s.tar.zst", e2e.arch, version) + var ( + testPackagesPath string = "src/test/test-packages/29-mistmatched-architectures" + deployPackagePath string = filepath.Join(testPackagesPath, "deploy") + initPackagePath string = filepath.Join(testPackagesPath, "init") + deployPackageName string = "mismatched-arch" + initPackageVersion string = "UnknownVersion" + mismatchedDeployPackageName string = fmt.Sprintf("build/zarf-package-%s-%s.tar.zst", deployPackageName, mismatchedArch) + mismatchedInitPackageName string = fmt.Sprintf("build/zarf-init-%s-%s.tar.zst", mismatchedArch, initPackageVersion) + expectedErrorMessage string = fmt.Sprintf(lang.CmdPackageDeployValidateArchitectureErr, mismatchedArch, e2e.arch) + ) - // This should be the name of the built init package with the incorrect/opposite architecture of the machine we're running on. - mismatchedInitPackage := fmt.Sprintf("build/zarf-init-%s-%s.tar.zst", mismatchedArch, version) + // Build init package with different arch than the cluster arch. + stdOut, stdErr, err := e2e.execZarfCommand("package", "create", "--architecture", mismatchedArch, "--confirm", initPackagePath) + require.NoError(t, err, stdOut, stdErr) + defer e2e.cleanFiles(mismatchedInitPackageName) - // Rename the init package with the mismatched architecture. - err := os.Rename(initPackageName, mismatchedInitPackage) - require.NoError(t, err) + // Build deploy package with different arch than the cluster arch. + stdOut, stdErr, err = e2e.execZarfCommand("package", "create", "--architecture", mismatchedArch, "--confirm", deployPackagePath) + require.NoError(t, err, stdOut, stdErr) + defer e2e.cleanFiles(mismatchedDeployPackageName) // Make sure zarf init returns an error because of the mismatched architectures. - // We need to use the --architecture flag here to force zarf to find the renamed package. - _, stdErr, err := e2e.execZarfCommand("init", "--architecture", mismatchedArch, "--confirm") + // We need to use the --architecture flag here to force zarf to find the package. + _, stdErr, err = e2e.execZarfCommand("init", "--architecture", mismatchedArch, "--confirm") + require.Error(t, err, stdErr) + require.Contains(t, stdErr, expectedErrorMessage) + + // Make sure zarf package deploy returns an error because of the mismatched architectures. + _, stdErr, err = e2e.execZarfCommand("package", "deploy", mismatchedDeployPackageName, "--confirm") require.Error(t, err, stdErr) - expectedErrorMessage := fmt.Sprintf(lang.CmdInitErrVerifyArchitecture, mismatchedArch, e2e.arch) require.Contains(t, stdErr, expectedErrorMessage) } diff --git a/src/test/test-packages/29-mismatched-architectures/deploy/zarf.yaml b/src/test/test-packages/29-mismatched-architectures/deploy/zarf.yaml new file mode 100644 index 0000000000..15a5d8a593 --- /dev/null +++ b/src/test/test-packages/29-mismatched-architectures/deploy/zarf.yaml @@ -0,0 +1,7 @@ +kind: ZarfPackageConfig +metadata: + name: mismatched-arch + description: Zarf package with different architecture than target cluster for tests + +components: + - name: mismatched-arch \ No newline at end of file diff --git a/src/test/test-packages/29-mismatched-architectures/init/zarf.yaml b/src/test/test-packages/29-mismatched-architectures/init/zarf.yaml new file mode 100644 index 0000000000..a9fe495725 --- /dev/null +++ b/src/test/test-packages/29-mismatched-architectures/init/zarf.yaml @@ -0,0 +1,7 @@ +kind: ZarfInitConfig +metadata: + name: mismatched-arch + description: Zarf init package with different architecture than target cluster for tests + +components: + - name: mismatched-arch \ No newline at end of file From 6c1aeb398a5ca0b731a6c67c760cc367f638a14c Mon Sep 17 00:00:00 2001 From: Lucas Rodriguez Date: Wed, 5 Apr 2023 21:02:24 -0500 Subject: [PATCH 15/53] Put package path before flags in package create for test --- src/test/e2e/29_mismatched_architectures_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/e2e/29_mismatched_architectures_test.go b/src/test/e2e/29_mismatched_architectures_test.go index 1873d4286d..1ec9607d67 100644 --- a/src/test/e2e/29_mismatched_architectures_test.go +++ b/src/test/e2e/29_mismatched_architectures_test.go @@ -42,12 +42,12 @@ func TestMismatchedArchitectures(t *testing.T) { ) // Build init package with different arch than the cluster arch. - stdOut, stdErr, err := e2e.execZarfCommand("package", "create", "--architecture", mismatchedArch, "--confirm", initPackagePath) + stdOut, stdErr, err := e2e.execZarfCommand("package", "create", initPackagePath, "--architecture", mismatchedArch, "--confirm") require.NoError(t, err, stdOut, stdErr) defer e2e.cleanFiles(mismatchedInitPackageName) // Build deploy package with different arch than the cluster arch. - stdOut, stdErr, err = e2e.execZarfCommand("package", "create", "--architecture", mismatchedArch, "--confirm", deployPackagePath) + stdOut, stdErr, err = e2e.execZarfCommand("package", "create", deployPackagePath, "--architecture", mismatchedArch, "--confirm") require.NoError(t, err, stdOut, stdErr) defer e2e.cleanFiles(mismatchedDeployPackageName) From d530e469842142753741ca16872ac4c219bc5fdd Mon Sep 17 00:00:00 2001 From: Lucas Rodriguez Date: Wed, 5 Apr 2023 21:57:53 -0500 Subject: [PATCH 16/53] Check if the package is using k8s --- src/pkg/packager/common.go | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/pkg/packager/common.go b/src/pkg/packager/common.go index 4421f01bc6..f8fcd09be2 100644 --- a/src/pkg/packager/common.go +++ b/src/pkg/packager/common.go @@ -445,10 +445,10 @@ func (p *Packager) validatePackageChecksums() error { // validatePackageArchitecture validates that the package architecture matches the target cluster architecture. func (p *Packager) validatePackageArchitecture() error { - components := p.getValidComponents() - var clusterArch string - var err error + + components := p.getValidComponents() + err := fmt.Errorf(lang.CmdPackageDeployValidateArchitectureErr, p.arch, clusterArch) // Iterate over the components to determine if we're deploying an init package with k3s, // and set appliance mode to true if we are. @@ -458,21 +458,27 @@ func (p *Packager) validatePackageArchitecture() error { } } - // If we're deploying an appliance mode init package, set the cluster arch to the machine we're running on. - // If we're not deploying an appliance mode init package, attempt to query existing cluster for the arch. + // If we're deploying an appliance mode init package, set the cluster arch to the arch of the machine we're running on. if p.cfg.InitOpts.ApplianceMode { clusterArch = runtime.GOARCH - } else { + + if p.arch != clusterArch { + return err + } + } + + // If k8s is being used, query the cluster for the architecture. + if p.cluster != nil { c := cluster.NewClusterOrDie() clusterArch, err = c.Kube.GetArchitecture() if err != nil { return err } - } - if p.arch != clusterArch { - return fmt.Errorf(lang.CmdPackageDeployValidateArchitectureErr, p.arch, clusterArch) + if p.arch != clusterArch { + return err + } } return nil From 267ab52b83b40b006cf25104f1f17a5654866820 Mon Sep 17 00:00:00 2001 From: Lucas Rodriguez Date: Wed, 5 Apr 2023 22:26:40 -0500 Subject: [PATCH 17/53] Add trailing forward slash to test package paths --- src/test/e2e/29_mismatched_architectures_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test/e2e/29_mismatched_architectures_test.go b/src/test/e2e/29_mismatched_architectures_test.go index 1ec9607d67..db61f79bbf 100644 --- a/src/test/e2e/29_mismatched_architectures_test.go +++ b/src/test/e2e/29_mismatched_architectures_test.go @@ -14,7 +14,7 @@ import ( ) // TestMismatchedArchitectures ensures that zarf produces an error -// when the init package architecture doesn't match the target system architecture. +// when the package architecture doesn't match the target cluster architecture. func TestMismatchedArchitectures(t *testing.T) { t.Log("E2E: Zarf init with mismatched architectures") e2e.setupWithCluster(t) @@ -32,8 +32,8 @@ func TestMismatchedArchitectures(t *testing.T) { var ( testPackagesPath string = "src/test/test-packages/29-mistmatched-architectures" - deployPackagePath string = filepath.Join(testPackagesPath, "deploy") - initPackagePath string = filepath.Join(testPackagesPath, "init") + deployPackagePath string = filepath.Join(testPackagesPath, "deploy/") + initPackagePath string = filepath.Join(testPackagesPath, "init/") deployPackageName string = "mismatched-arch" initPackageVersion string = "UnknownVersion" mismatchedDeployPackageName string = fmt.Sprintf("build/zarf-package-%s-%s.tar.zst", deployPackageName, mismatchedArch) From 58aceb903cdb489dcc26c1a43755777d26046aef Mon Sep 17 00:00:00 2001 From: Lucas Rodriguez Date: Wed, 5 Apr 2023 22:48:37 -0500 Subject: [PATCH 18/53] Remove use of filepath Join function for test package paths --- src/test/e2e/29_mismatched_architectures_test.go | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/test/e2e/29_mismatched_architectures_test.go b/src/test/e2e/29_mismatched_architectures_test.go index db61f79bbf..a1735b504d 100644 --- a/src/test/e2e/29_mismatched_architectures_test.go +++ b/src/test/e2e/29_mismatched_architectures_test.go @@ -6,7 +6,6 @@ package test import ( "fmt" - "path/filepath" "testing" "github.com/defenseunicorns/zarf/src/config/lang" @@ -31,14 +30,13 @@ func TestMismatchedArchitectures(t *testing.T) { } var ( - testPackagesPath string = "src/test/test-packages/29-mistmatched-architectures" - deployPackagePath string = filepath.Join(testPackagesPath, "deploy/") - initPackagePath string = filepath.Join(testPackagesPath, "init/") - deployPackageName string = "mismatched-arch" - initPackageVersion string = "UnknownVersion" - mismatchedDeployPackageName string = fmt.Sprintf("build/zarf-package-%s-%s.tar.zst", deployPackageName, mismatchedArch) - mismatchedInitPackageName string = fmt.Sprintf("build/zarf-init-%s-%s.tar.zst", mismatchedArch, initPackageVersion) - expectedErrorMessage string = fmt.Sprintf(lang.CmdPackageDeployValidateArchitectureErr, mismatchedArch, e2e.arch) + deployPackagePath = "src/test/test-packages/29-mistmatched-architectures/deploy/" + initPackagePath = "src/test/test-packages/29-mistmatched-architectures/init/" + deployPackageName = "mismatched-arch" + initPackageVersion = "UnknownVersion" + mismatchedDeployPackageName = fmt.Sprintf("build/zarf-package-%s-%s.tar.zst", deployPackageName, mismatchedArch) + mismatchedInitPackageName = fmt.Sprintf("build/zarf-init-%s-%s.tar.zst", mismatchedArch, initPackageVersion) + expectedErrorMessage = fmt.Sprintf(lang.CmdPackageDeployValidateArchitectureErr, mismatchedArch, e2e.arch) ) // Build init package with different arch than the cluster arch. From ccb4fdc427b85179b260f178b18bd9309b9fc139 Mon Sep 17 00:00:00 2001 From: Lucas Rodriguez Date: Wed, 5 Apr 2023 23:17:14 -0500 Subject: [PATCH 19/53] Use separate directories to store test zarf package configs --- src/test/e2e/29_mismatched_architectures_test.go | 4 ++-- .../deploy => 29-mismatched-architectures-deploy}/zarf.yaml | 0 .../init => 29-mismatched-architectures-init}/zarf.yaml | 0 3 files changed, 2 insertions(+), 2 deletions(-) rename src/test/test-packages/{29-mismatched-architectures/deploy => 29-mismatched-architectures-deploy}/zarf.yaml (100%) rename src/test/test-packages/{29-mismatched-architectures/init => 29-mismatched-architectures-init}/zarf.yaml (100%) diff --git a/src/test/e2e/29_mismatched_architectures_test.go b/src/test/e2e/29_mismatched_architectures_test.go index a1735b504d..60b2746d71 100644 --- a/src/test/e2e/29_mismatched_architectures_test.go +++ b/src/test/e2e/29_mismatched_architectures_test.go @@ -30,8 +30,8 @@ func TestMismatchedArchitectures(t *testing.T) { } var ( - deployPackagePath = "src/test/test-packages/29-mistmatched-architectures/deploy/" - initPackagePath = "src/test/test-packages/29-mistmatched-architectures/init/" + deployPackagePath = "src/test/test-packages/29-mistmatched-architectures-deploy/" + initPackagePath = "src/test/test-packages/29-mistmatched-architectures-init/" deployPackageName = "mismatched-arch" initPackageVersion = "UnknownVersion" mismatchedDeployPackageName = fmt.Sprintf("build/zarf-package-%s-%s.tar.zst", deployPackageName, mismatchedArch) diff --git a/src/test/test-packages/29-mismatched-architectures/deploy/zarf.yaml b/src/test/test-packages/29-mismatched-architectures-deploy/zarf.yaml similarity index 100% rename from src/test/test-packages/29-mismatched-architectures/deploy/zarf.yaml rename to src/test/test-packages/29-mismatched-architectures-deploy/zarf.yaml diff --git a/src/test/test-packages/29-mismatched-architectures/init/zarf.yaml b/src/test/test-packages/29-mismatched-architectures-init/zarf.yaml similarity index 100% rename from src/test/test-packages/29-mismatched-architectures/init/zarf.yaml rename to src/test/test-packages/29-mismatched-architectures-init/zarf.yaml From ebc6f6e6e73d9eeb73ef2005462c49ddc87be015 Mon Sep 17 00:00:00 2001 From: Lucas Rodriguez Date: Thu, 6 Apr 2023 09:12:46 -0500 Subject: [PATCH 20/53] Fix typo and change test package paths --- src/test/e2e/29_mismatched_architectures_test.go | 4 ++-- .../deploy}/zarf.yaml | 0 .../init}/zarf.yaml | 0 3 files changed, 2 insertions(+), 2 deletions(-) rename src/test/test-packages/{29-mismatched-architectures-deploy => 29-mismatched-architectures/deploy}/zarf.yaml (100%) rename src/test/test-packages/{29-mismatched-architectures-init => 29-mismatched-architectures/init}/zarf.yaml (100%) diff --git a/src/test/e2e/29_mismatched_architectures_test.go b/src/test/e2e/29_mismatched_architectures_test.go index 60b2746d71..ca2f8333ab 100644 --- a/src/test/e2e/29_mismatched_architectures_test.go +++ b/src/test/e2e/29_mismatched_architectures_test.go @@ -30,8 +30,8 @@ func TestMismatchedArchitectures(t *testing.T) { } var ( - deployPackagePath = "src/test/test-packages/29-mistmatched-architectures-deploy/" - initPackagePath = "src/test/test-packages/29-mistmatched-architectures-init/" + deployPackagePath = "src/test/test-packages/29-mismatched-architectures/deploy/" + initPackagePath = "src/test/test-packages/29-mismatched-architectures/init/" deployPackageName = "mismatched-arch" initPackageVersion = "UnknownVersion" mismatchedDeployPackageName = fmt.Sprintf("build/zarf-package-%s-%s.tar.zst", deployPackageName, mismatchedArch) diff --git a/src/test/test-packages/29-mismatched-architectures-deploy/zarf.yaml b/src/test/test-packages/29-mismatched-architectures/deploy/zarf.yaml similarity index 100% rename from src/test/test-packages/29-mismatched-architectures-deploy/zarf.yaml rename to src/test/test-packages/29-mismatched-architectures/deploy/zarf.yaml diff --git a/src/test/test-packages/29-mismatched-architectures-init/zarf.yaml b/src/test/test-packages/29-mismatched-architectures/init/zarf.yaml similarity index 100% rename from src/test/test-packages/29-mismatched-architectures-init/zarf.yaml rename to src/test/test-packages/29-mismatched-architectures/init/zarf.yaml From 5a6c986a26066fbaf969d750864b911c0cae5c58 Mon Sep 17 00:00:00 2001 From: Lucas Rodriguez Date: Thu, 6 Apr 2023 12:01:34 -0500 Subject: [PATCH 21/53] Use test packages with k8s resources --- src/test/e2e/29_mismatched_architectures_test.go | 11 ++++------- .../29-mismatched-architectures/deploy/zarf.yaml | 7 ------- .../29-mismatched-architectures/init/zarf.yaml | 7 ------- 3 files changed, 4 insertions(+), 21 deletions(-) delete mode 100644 src/test/test-packages/29-mismatched-architectures/deploy/zarf.yaml delete mode 100644 src/test/test-packages/29-mismatched-architectures/init/zarf.yaml diff --git a/src/test/e2e/29_mismatched_architectures_test.go b/src/test/e2e/29_mismatched_architectures_test.go index ca2f8333ab..c6257df951 100644 --- a/src/test/e2e/29_mismatched_architectures_test.go +++ b/src/test/e2e/29_mismatched_architectures_test.go @@ -30,22 +30,19 @@ func TestMismatchedArchitectures(t *testing.T) { } var ( - deployPackagePath = "src/test/test-packages/29-mismatched-architectures/deploy/" - initPackagePath = "src/test/test-packages/29-mismatched-architectures/init/" - deployPackageName = "mismatched-arch" initPackageVersion = "UnknownVersion" - mismatchedDeployPackageName = fmt.Sprintf("build/zarf-package-%s-%s.tar.zst", deployPackageName, mismatchedArch) - mismatchedInitPackageName = fmt.Sprintf("build/zarf-init-%s-%s.tar.zst", mismatchedArch, initPackageVersion) + mismatchedDeployPackageName = fmt.Sprintf("zarf-package-dos-games-%s.tar.zst", mismatchedArch) + mismatchedInitPackageName = fmt.Sprintf("zarf-init-%s-%s.tar.zst", mismatchedArch, initPackageVersion) expectedErrorMessage = fmt.Sprintf(lang.CmdPackageDeployValidateArchitectureErr, mismatchedArch, e2e.arch) ) // Build init package with different arch than the cluster arch. - stdOut, stdErr, err := e2e.execZarfCommand("package", "create", initPackagePath, "--architecture", mismatchedArch, "--confirm") + stdOut, stdErr, err := e2e.execZarfCommand("package", "create", ".", "--architecture", mismatchedArch, "--confirm") require.NoError(t, err, stdOut, stdErr) defer e2e.cleanFiles(mismatchedInitPackageName) // Build deploy package with different arch than the cluster arch. - stdOut, stdErr, err = e2e.execZarfCommand("package", "create", deployPackagePath, "--architecture", mismatchedArch, "--confirm") + stdOut, stdErr, err = e2e.execZarfCommand("package", "create", "examples/dos-games/", "--architecture", mismatchedArch, "--confirm") require.NoError(t, err, stdOut, stdErr) defer e2e.cleanFiles(mismatchedDeployPackageName) diff --git a/src/test/test-packages/29-mismatched-architectures/deploy/zarf.yaml b/src/test/test-packages/29-mismatched-architectures/deploy/zarf.yaml deleted file mode 100644 index 15a5d8a593..0000000000 --- a/src/test/test-packages/29-mismatched-architectures/deploy/zarf.yaml +++ /dev/null @@ -1,7 +0,0 @@ -kind: ZarfPackageConfig -metadata: - name: mismatched-arch - description: Zarf package with different architecture than target cluster for tests - -components: - - name: mismatched-arch \ No newline at end of file diff --git a/src/test/test-packages/29-mismatched-architectures/init/zarf.yaml b/src/test/test-packages/29-mismatched-architectures/init/zarf.yaml deleted file mode 100644 index a9fe495725..0000000000 --- a/src/test/test-packages/29-mismatched-architectures/init/zarf.yaml +++ /dev/null @@ -1,7 +0,0 @@ -kind: ZarfInitConfig -metadata: - name: mismatched-arch - description: Zarf init package with different architecture than target cluster for tests - -components: - - name: mismatched-arch \ No newline at end of file From b7aaeae1f2b6a1a09cacbe2a4a3f1bf9aa6ed47d Mon Sep 17 00:00:00 2001 From: Lucas Rodriguez Date: Wed, 12 Apr 2023 10:02:21 -0400 Subject: [PATCH 22/53] Update check for appliance mode init package --- src/pkg/packager/common.go | 18 +++++++++--------- src/pkg/packager/deploy.go | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/pkg/packager/common.go b/src/pkg/packager/common.go index 34a8fd9f20..a087d5a108 100644 --- a/src/pkg/packager/common.go +++ b/src/pkg/packager/common.go @@ -24,7 +24,6 @@ import ( "github.com/mholt/archiver/v3" "github.com/defenseunicorns/zarf/src/config" - "github.com/defenseunicorns/zarf/src/pkg/k8s" "github.com/defenseunicorns/zarf/src/pkg/message" "github.com/defenseunicorns/zarf/src/pkg/packager/deprecated" "github.com/defenseunicorns/zarf/src/pkg/utils" @@ -444,17 +443,18 @@ func (p *Packager) validatePackageChecksums() error { } // validatePackageArchitecture validates that the package architecture matches the target cluster architecture. -func (p *Packager) validatePackageArchitecture() error { +func (p *Packager) validatePackageArchitecture(initPackage bool) error { var clusterArch string - - components := p.getValidComponents() err := fmt.Errorf(lang.CmdPackageDeployValidateArchitectureErr, p.arch, clusterArch) - // Iterate over the components to determine if we're deploying an init package with k3s, - // and set appliance mode to true if we are. - for _, component := range components { - if component.Name == k8s.DistroIsK3s && p.cfg.IsInitConfig { - p.cfg.InitOpts.ApplianceMode = true + // If we're deploying an init package, iterate over the components to determine + // if we're deploying k3s, and set appliance mode to true if we are. + if initPackage { + components := p.getValidComponents() + for _, component := range components { + if component.Name == "k3s" { + p.cfg.InitOpts.ApplianceMode = true + } } } diff --git a/src/pkg/packager/deploy.go b/src/pkg/packager/deploy.go index 7fa8266671..c145b15d10 100644 --- a/src/pkg/packager/deploy.go +++ b/src/pkg/packager/deploy.go @@ -51,7 +51,7 @@ func (p *Packager) Deploy() error { p.cfg.IsInitConfig = true } - if err := p.validatePackageArchitecture(); err != nil { + if err := p.validatePackageArchitecture(p.cfg.IsInitConfig); err != nil { return err } From af2753f75ab3453a7b15f0a2b605588e0ba54888 Mon Sep 17 00:00:00 2001 From: Lucas Rodriguez Date: Thu, 13 Apr 2023 10:45:20 -0400 Subject: [PATCH 23/53] It works on my machine --- src/pkg/packager/common.go | 44 +++++++++++++------------------------- 1 file changed, 15 insertions(+), 29 deletions(-) diff --git a/src/pkg/packager/common.go b/src/pkg/packager/common.go index c475e33547..a5768499ba 100644 --- a/src/pkg/packager/common.go +++ b/src/pkg/packager/common.go @@ -15,6 +15,7 @@ import ( "runtime" "sort" "strings" + "time" "github.com/AlecAivazis/survey/v2" "github.com/defenseunicorns/zarf/src/config/lang" @@ -445,40 +446,25 @@ func (p *Packager) validatePackageChecksums() error { // validatePackageArchitecture validates that the package architecture matches the target cluster architecture. func (p *Packager) validatePackageArchitecture(initPackage bool) error { var clusterArch string - err := fmt.Errorf(lang.CmdPackageDeployValidateArchitectureErr, p.arch, clusterArch) - - // If we're deploying an init package, iterate over the components to determine - // if we're deploying k3s, and set appliance mode to true if we are. - if initPackage { - components := p.getValidComponents() - for _, component := range components { - if component.Name == "k3s" { - p.cfg.InitOpts.ApplianceMode = true - } - } - } - - // If we're deploying an appliance mode init package, set the cluster arch to the arch of the machine we're running on. - if p.cfg.InitOpts.ApplianceMode { - clusterArch = runtime.GOARCH - - if p.arch != clusterArch { - return err - } - } - // If k8s is being used, query the cluster for the architecture. + // If k8s resources are defined in the package, query the cluster for the architecture. + // If not, set the cluster architecture to the architecture of the machine we're running on. if p.cluster != nil { - c := cluster.NewClusterOrDie() + c, err := cluster.NewClusterWithWait(30 * time.Second) - clusterArch, err = c.Kube.GetArchitecture() - if err != nil { - return err - } + if err == nil { + clusterArch, err = c.Kube.GetArchitecture() - if p.arch != clusterArch { - return err + if err != nil { + return err + } } + } else { + clusterArch = runtime.GOARCH + } + + if p.arch != clusterArch { + return fmt.Errorf(lang.CmdPackageDeployValidateArchitectureErr, p.arch, clusterArch) } return nil From b1d09ba7c1bb20653b683bb3991a4f7ff12a9aeb Mon Sep 17 00:00:00 2001 From: Lucas Rodriguez Date: Thu, 13 Apr 2023 11:22:53 -0400 Subject: [PATCH 24/53] Update expected error message to handle both init and deploy failures in test --- src/test/e2e/29_mismatched_architectures_test.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/test/e2e/29_mismatched_architectures_test.go b/src/test/e2e/29_mismatched_architectures_test.go index c6257df951..9162828e6a 100644 --- a/src/test/e2e/29_mismatched_architectures_test.go +++ b/src/test/e2e/29_mismatched_architectures_test.go @@ -8,7 +8,6 @@ import ( "fmt" "testing" - "github.com/defenseunicorns/zarf/src/config/lang" "github.com/stretchr/testify/require" ) @@ -33,7 +32,7 @@ func TestMismatchedArchitectures(t *testing.T) { initPackageVersion = "UnknownVersion" mismatchedDeployPackageName = fmt.Sprintf("zarf-package-dos-games-%s.tar.zst", mismatchedArch) mismatchedInitPackageName = fmt.Sprintf("zarf-init-%s-%s.tar.zst", mismatchedArch, initPackageVersion) - expectedErrorMessage = fmt.Sprintf(lang.CmdPackageDeployValidateArchitectureErr, mismatchedArch, e2e.arch) + expectedErrorMessage = fmt.Sprintf("this package architecture is %s", mismatchedArch) ) // Build init package with different arch than the cluster arch. From c09dcf85b519d9d8128b72025fb1c963706189f8 Mon Sep 17 00:00:00 2001 From: Lucas Rodriguez Date: Thu, 13 Apr 2023 12:29:28 -0400 Subject: [PATCH 25/53] Remove unused function parameter --- src/pkg/packager/common.go | 2 +- src/pkg/packager/deploy.go | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/pkg/packager/common.go b/src/pkg/packager/common.go index a5768499ba..d19eb2670f 100644 --- a/src/pkg/packager/common.go +++ b/src/pkg/packager/common.go @@ -444,7 +444,7 @@ func (p *Packager) validatePackageChecksums() error { } // validatePackageArchitecture validates that the package architecture matches the target cluster architecture. -func (p *Packager) validatePackageArchitecture(initPackage bool) error { +func (p *Packager) validatePackageArchitecture() error { var clusterArch string // If k8s resources are defined in the package, query the cluster for the architecture. diff --git a/src/pkg/packager/deploy.go b/src/pkg/packager/deploy.go index b1abf412ad..3f9c3759dd 100644 --- a/src/pkg/packager/deploy.go +++ b/src/pkg/packager/deploy.go @@ -42,6 +42,10 @@ func (p *Packager) Deploy() error { return fmt.Errorf("unable to load the Zarf Package: %w", err) } + if err := p.validatePackageArchitecture(); err != nil { + return err + } + if err := p.validatePackageSignature(p.cfg.DeployOpts.PublicKeyPath); err != nil { return err } @@ -51,10 +55,6 @@ func (p *Packager) Deploy() error { p.cfg.IsInitConfig = true } - if err := p.validatePackageArchitecture(p.cfg.IsInitConfig); err != nil { - return err - } - // Confirm the overall package deployment if !p.confirmAction("Deploy", p.cfg.SBOMViewFiles) { return fmt.Errorf("deployment cancelled") From 045fbdb60ddfda701f8c69dba0ddd176ac5b68a0 Mon Sep 17 00:00:00 2001 From: Lucas Rodriguez Date: Thu, 13 Apr 2023 17:47:10 -0400 Subject: [PATCH 26/53] Trying to handle various package deployment scenarios --- src/pkg/packager/common.go | 53 ++++++++++++++++++++++++++++---------- 1 file changed, 40 insertions(+), 13 deletions(-) diff --git a/src/pkg/packager/common.go b/src/pkg/packager/common.go index d19eb2670f..6ef7f5baae 100644 --- a/src/pkg/packager/common.go +++ b/src/pkg/packager/common.go @@ -25,6 +25,7 @@ import ( "github.com/mholt/archiver/v3" "github.com/defenseunicorns/zarf/src/config" + "github.com/defenseunicorns/zarf/src/pkg/k8s" "github.com/defenseunicorns/zarf/src/pkg/message" "github.com/defenseunicorns/zarf/src/pkg/packager/deprecated" "github.com/defenseunicorns/zarf/src/pkg/utils" @@ -445,26 +446,52 @@ func (p *Packager) validatePackageChecksums() error { // validatePackageArchitecture validates that the package architecture matches the target cluster architecture. func (p *Packager) validatePackageArchitecture() error { + var applianceMode bool var clusterArch string + var err error - // If k8s resources are defined in the package, query the cluster for the architecture. - // If not, set the cluster architecture to the architecture of the machine we're running on. - if p.cluster != nil { - c, err := cluster.NewClusterWithWait(30 * time.Second) + // Iterate over the package components to determine whether we are working with an appliance mode init package. + components := p.getValidComponents() + for _, component := range components { + if component.Name == k8s.DistroIsK3s && p.cfg.Pkg.Kind == "ZarfInitConfig" { + applianceMode = true + } + } - if err == nil { - clusterArch, err = c.Kube.GetArchitecture() + // If we're working with an init package deploying k3s(appliance mode), set the clusterArch to the machine we're running on. + if applianceMode { + clusterArch = runtime.GOARCH - if err != nil { - return err - } + if p.arch != clusterArch { + return fmt.Errorf(lang.CmdPackageDeployValidateArchitectureErr, p.arch, clusterArch) } - } else { - clusterArch = runtime.GOARCH } - if p.arch != clusterArch { - return fmt.Errorf(lang.CmdPackageDeployValidateArchitectureErr, p.arch, clusterArch) + // If we're already connected to a cluster, query the cluster for the architecture. + if p.cluster != nil { + clusterArch, err = p.cluster.Kube.GetArchitecture() + if err != nil { + return err + } + + if p.arch != clusterArch { + return fmt.Errorf(lang.CmdPackageDeployValidateArchitectureErr, p.arch, clusterArch) + } + } else { + // If we're not already connected to a cluster, attemp to setup a new client connection. + c, err := cluster.NewClusterWithWait(30 * time.Second) + if err != nil { + return fmt.Errorf("unable to connect to the Kubernetes cluster: %w", err) + } + + clusterArch, err = c.Kube.GetArchitecture() + if err != nil { + return err + } + + if p.arch != clusterArch { + return fmt.Errorf(lang.CmdPackageDeployValidateArchitectureErr, p.arch, clusterArch) + } } return nil From e57f6e19c096577f9383ec08745389053bf073d1 Mon Sep 17 00:00:00 2001 From: Lucas Rodriguez Date: Thu, 13 Apr 2023 18:03:39 -0400 Subject: [PATCH 27/53] Remove setup of client connection --- src/pkg/packager/common.go | 28 ++++------------------------ 1 file changed, 4 insertions(+), 24 deletions(-) diff --git a/src/pkg/packager/common.go b/src/pkg/packager/common.go index 6ef7f5baae..5f62045d52 100644 --- a/src/pkg/packager/common.go +++ b/src/pkg/packager/common.go @@ -15,7 +15,6 @@ import ( "runtime" "sort" "strings" - "time" "github.com/AlecAivazis/survey/v2" "github.com/defenseunicorns/zarf/src/config/lang" @@ -459,12 +458,8 @@ func (p *Packager) validatePackageArchitecture() error { } // If we're working with an init package deploying k3s(appliance mode), set the clusterArch to the machine we're running on. - if applianceMode { + if applianceMode && p.cluster == nil { clusterArch = runtime.GOARCH - - if p.arch != clusterArch { - return fmt.Errorf(lang.CmdPackageDeployValidateArchitectureErr, p.arch, clusterArch) - } } // If we're already connected to a cluster, query the cluster for the architecture. @@ -473,25 +468,10 @@ func (p *Packager) validatePackageArchitecture() error { if err != nil { return err } + } - if p.arch != clusterArch { - return fmt.Errorf(lang.CmdPackageDeployValidateArchitectureErr, p.arch, clusterArch) - } - } else { - // If we're not already connected to a cluster, attemp to setup a new client connection. - c, err := cluster.NewClusterWithWait(30 * time.Second) - if err != nil { - return fmt.Errorf("unable to connect to the Kubernetes cluster: %w", err) - } - - clusterArch, err = c.Kube.GetArchitecture() - if err != nil { - return err - } - - if p.arch != clusterArch { - return fmt.Errorf(lang.CmdPackageDeployValidateArchitectureErr, p.arch, clusterArch) - } + if p.arch != clusterArch { + return fmt.Errorf(lang.CmdPackageDeployValidateArchitectureErr, p.arch, clusterArch) } return nil From fb96ba486c4b2d709bf82a3c27f71b940fcb45d9 Mon Sep 17 00:00:00 2001 From: Lucas Rodriguez Date: Thu, 13 Apr 2023 18:10:00 -0400 Subject: [PATCH 28/53] Put the arch check back in the conditionals --- src/pkg/packager/common.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/pkg/packager/common.go b/src/pkg/packager/common.go index 5f62045d52..997189b8db 100644 --- a/src/pkg/packager/common.go +++ b/src/pkg/packager/common.go @@ -460,6 +460,10 @@ func (p *Packager) validatePackageArchitecture() error { // If we're working with an init package deploying k3s(appliance mode), set the clusterArch to the machine we're running on. if applianceMode && p.cluster == nil { clusterArch = runtime.GOARCH + + if p.arch != clusterArch { + return fmt.Errorf(lang.CmdPackageDeployValidateArchitectureErr, p.arch, clusterArch) + } } // If we're already connected to a cluster, query the cluster for the architecture. @@ -468,10 +472,10 @@ func (p *Packager) validatePackageArchitecture() error { if err != nil { return err } - } - if p.arch != clusterArch { - return fmt.Errorf(lang.CmdPackageDeployValidateArchitectureErr, p.arch, clusterArch) + if p.arch != clusterArch { + return fmt.Errorf(lang.CmdPackageDeployValidateArchitectureErr, p.arch, clusterArch) + } } return nil From 2214fd1c82078c7b9d74b9a0238ab7f4daa23b1f Mon Sep 17 00:00:00 2001 From: Lucas Rodriguez Date: Tue, 18 Apr 2023 18:04:03 -0500 Subject: [PATCH 29/53] Remove cluster connection check Update test helper functions to use updated capitalized names --- src/pkg/packager/common.go | 2 +- .../e2e/29_mismatched_architectures_test.go | 20 +++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/pkg/packager/common.go b/src/pkg/packager/common.go index 997189b8db..a53464657e 100644 --- a/src/pkg/packager/common.go +++ b/src/pkg/packager/common.go @@ -458,7 +458,7 @@ func (p *Packager) validatePackageArchitecture() error { } // If we're working with an init package deploying k3s(appliance mode), set the clusterArch to the machine we're running on. - if applianceMode && p.cluster == nil { + if applianceMode { clusterArch = runtime.GOARCH if p.arch != clusterArch { diff --git a/src/test/e2e/29_mismatched_architectures_test.go b/src/test/e2e/29_mismatched_architectures_test.go index 9162828e6a..c7ccd5414c 100644 --- a/src/test/e2e/29_mismatched_architectures_test.go +++ b/src/test/e2e/29_mismatched_architectures_test.go @@ -15,16 +15,16 @@ import ( // when the package architecture doesn't match the target cluster architecture. func TestMismatchedArchitectures(t *testing.T) { t.Log("E2E: Zarf init with mismatched architectures") - e2e.setupWithCluster(t) - defer e2e.teardown(t) + e2e.SetupWithCluster(t) + defer e2e.Teardown(t) // Determine what test runner architecture we're running on, // and set mismatchedArch to the opposite architecture. var mismatchedArch string - if e2e.arch == "amd64" { + if e2e.Arch == "amd64" { mismatchedArch = "arm64" } - if e2e.arch == "arm64" { + if e2e.Arch == "arm64" { mismatchedArch = "amd64" } @@ -36,23 +36,23 @@ func TestMismatchedArchitectures(t *testing.T) { ) // Build init package with different arch than the cluster arch. - stdOut, stdErr, err := e2e.execZarfCommand("package", "create", ".", "--architecture", mismatchedArch, "--confirm") + stdOut, stdErr, err := e2e.ExecZarfCommand("package", "create", ".", "--architecture", mismatchedArch, "--confirm") require.NoError(t, err, stdOut, stdErr) - defer e2e.cleanFiles(mismatchedInitPackageName) + defer e2e.CleanFiles(mismatchedInitPackageName) // Build deploy package with different arch than the cluster arch. - stdOut, stdErr, err = e2e.execZarfCommand("package", "create", "examples/dos-games/", "--architecture", mismatchedArch, "--confirm") + stdOut, stdErr, err = e2e.ExecZarfCommand("package", "create", "examples/dos-games/", "--architecture", mismatchedArch, "--confirm") require.NoError(t, err, stdOut, stdErr) - defer e2e.cleanFiles(mismatchedDeployPackageName) + defer e2e.CleanFiles(mismatchedDeployPackageName) // Make sure zarf init returns an error because of the mismatched architectures. // We need to use the --architecture flag here to force zarf to find the package. - _, stdErr, err = e2e.execZarfCommand("init", "--architecture", mismatchedArch, "--confirm") + _, stdErr, err = e2e.ExecZarfCommand("init", "--architecture", mismatchedArch, "--confirm") require.Error(t, err, stdErr) require.Contains(t, stdErr, expectedErrorMessage) // Make sure zarf package deploy returns an error because of the mismatched architectures. - _, stdErr, err = e2e.execZarfCommand("package", "deploy", mismatchedDeployPackageName, "--confirm") + _, stdErr, err = e2e.ExecZarfCommand("package", "deploy", mismatchedDeployPackageName, "--confirm") require.Error(t, err, stdErr) require.Contains(t, stdErr, expectedErrorMessage) } From 960ba63245cb7151d82e6104d9e035567b9ab1b6 Mon Sep 17 00:00:00 2001 From: Lucas Rodriguez Date: Tue, 18 Apr 2023 20:33:48 -0500 Subject: [PATCH 30/53] Handle packages with k8s resources --- src/internal/cluster/common.go | 4 ++-- src/internal/cluster/tunnel.go | 6 ++--- src/pkg/packager/common.go | 41 +++++++++++++++++++++++++++++----- 3 files changed, 40 insertions(+), 11 deletions(-) diff --git a/src/internal/cluster/common.go b/src/internal/cluster/common.go index ba6c67bdca..876b2e2be1 100644 --- a/src/internal/cluster/common.go +++ b/src/internal/cluster/common.go @@ -18,7 +18,7 @@ type Cluster struct { } const ( - defaultTimeout = 30 * time.Second + DefaultTimeout = 30 * time.Second agentLabel = "zarf.dev/agent" ) @@ -28,7 +28,7 @@ var labels = k8s.Labels{ // NewClusterOrDie creates a new cluster instance and waits up to 30 seconds for the cluster to be ready or throws a fatal error. func NewClusterOrDie() *Cluster { - c, err := NewClusterWithWait(defaultTimeout) + c, err := NewClusterWithWait(DefaultTimeout) if err != nil { message.Fatalf(err, "Failed to connect to cluster") } diff --git a/src/internal/cluster/tunnel.go b/src/internal/cluster/tunnel.go index ef81123edb..6a873dac6a 100644 --- a/src/internal/cluster/tunnel.go +++ b/src/internal/cluster/tunnel.go @@ -124,7 +124,7 @@ func ServiceInfoFromNodePortURL(nodePortURL string) (*ServiceInfo, error) { return nil, fmt.Errorf("node port services should use the port range 30000-32767") } - kube, err := k8s.NewWithWait(message.Debugf, labels, defaultTimeout) + kube, err := k8s.NewWithWait(message.Debugf, labels, DefaultTimeout) if err != nil { return nil, err } @@ -187,7 +187,7 @@ func ServiceInfoFromServiceURL(serviceURL string) (*ServiceInfo, error) { func NewTunnel(namespace, resourceType, resourceName string, local, remote int) (*Tunnel, error) { message.Debugf("tunnel.NewTunnel(%s, %s, %s, %d, %d)", namespace, resourceType, resourceName, local, remote) - kube, err := k8s.NewWithWait(message.Debugf, labels, defaultTimeout) + kube, err := k8s.NewWithWait(message.Debugf, labels, DefaultTimeout) if err != nil { return &Tunnel{}, err } @@ -406,7 +406,7 @@ func (tunnel *Tunnel) establish() (string, error) { defer spinner.Stop() } - kube, err := k8s.NewWithWait(message.Debugf, labels, defaultTimeout) + kube, err := k8s.NewWithWait(message.Debugf, labels, DefaultTimeout) if err != nil { return "", fmt.Errorf("unable to connect to the cluster: %w", err) } diff --git a/src/pkg/packager/common.go b/src/pkg/packager/common.go index a53464657e..4b7f575925 100644 --- a/src/pkg/packager/common.go +++ b/src/pkg/packager/common.go @@ -445,19 +445,29 @@ func (p *Packager) validatePackageChecksums() error { // validatePackageArchitecture validates that the package architecture matches the target cluster architecture. func (p *Packager) validatePackageArchitecture() error { - var applianceMode bool - var clusterArch string - var err error + var ( + applianceMode bool + clusterArch string + err error + k8sTarget bool + ) - // Iterate over the package components to determine whether we are working with an appliance mode init package. + // Iterate over the package components. components := p.getValidComponents() for _, component := range components { + // Determine whether we are working with an appliance mode init package. if component.Name == k8s.DistroIsK3s && p.cfg.Pkg.Kind == "ZarfInitConfig" { applianceMode = true } + + // Determine whether we are deploying k8s resources. + if component.Images != nil { + k8sTarget = true + } } - // If we're working with an init package deploying k3s(appliance mode), set the clusterArch to the machine we're running on. + // If we're working with an init package deploying k3s(appliance mode), + // set the clusterArch to the machine we're running on. if applianceMode { clusterArch = runtime.GOARCH @@ -466,13 +476,32 @@ func (p *Packager) validatePackageArchitecture() error { } } - // If we're already connected to a cluster, query the cluster for the architecture. + /* + If we're already connected to a cluster, query the cluster for the architecture. + + If we're not already connected to a cluster and we're deploying k8s resources, + attempt to establish a new k8s client connection and query the cluster for the architecture. + */ if p.cluster != nil { clusterArch, err = p.cluster.Kube.GetArchitecture() if err != nil { return err } + if p.arch != clusterArch { + return fmt.Errorf(lang.CmdPackageDeployValidateArchitectureErr, p.arch, clusterArch) + } + } else if k8sTarget { + client, err := cluster.NewClusterWithWait(cluster.DefaultTimeout) + if err != nil { + return err + } + + clusterArch, err = client.Kube.GetArchitecture() + if err != nil { + return err + } + if p.arch != clusterArch { return fmt.Errorf(lang.CmdPackageDeployValidateArchitectureErr, p.arch, clusterArch) } From 93bb34d7874299664476040ddd88ce5e70f58dfa Mon Sep 17 00:00:00 2001 From: Lucas Rodriguez Date: Tue, 18 Apr 2023 20:42:13 -0500 Subject: [PATCH 31/53] Set spinner parameter to false in NewClusterWithWait --- src/pkg/packager/common.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pkg/packager/common.go b/src/pkg/packager/common.go index 4b7f575925..059850b79e 100644 --- a/src/pkg/packager/common.go +++ b/src/pkg/packager/common.go @@ -492,7 +492,7 @@ func (p *Packager) validatePackageArchitecture() error { return fmt.Errorf(lang.CmdPackageDeployValidateArchitectureErr, p.arch, clusterArch) } } else if k8sTarget { - client, err := cluster.NewClusterWithWait(cluster.DefaultTimeout) + client, err := cluster.NewClusterWithWait(cluster.DefaultTimeout, false) if err != nil { return err } From 3076a18bf30cf9a6282b767bc02fdb1503a3f8d7 Mon Sep 17 00:00:00 2001 From: Lucas Rodriguez Date: Tue, 18 Apr 2023 21:04:35 -0500 Subject: [PATCH 32/53] Add test case to verify packages without k8s resources --- .../e2e/29_mismatched_architectures_test.go | 33 ++++++++++++------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/src/test/e2e/29_mismatched_architectures_test.go b/src/test/e2e/29_mismatched_architectures_test.go index c7ccd5414c..41f8448e98 100644 --- a/src/test/e2e/29_mismatched_architectures_test.go +++ b/src/test/e2e/29_mismatched_architectures_test.go @@ -14,7 +14,7 @@ import ( // TestMismatchedArchitectures ensures that zarf produces an error // when the package architecture doesn't match the target cluster architecture. func TestMismatchedArchitectures(t *testing.T) { - t.Log("E2E: Zarf init with mismatched architectures") + t.Log("E2E: Mismatched architectures") e2e.SetupWithCluster(t) defer e2e.Teardown(t) @@ -29,30 +29,41 @@ func TestMismatchedArchitectures(t *testing.T) { } var ( - initPackageVersion = "UnknownVersion" - mismatchedDeployPackageName = fmt.Sprintf("zarf-package-dos-games-%s.tar.zst", mismatchedArch) - mismatchedInitPackageName = fmt.Sprintf("zarf-init-%s-%s.tar.zst", mismatchedArch, initPackageVersion) - expectedErrorMessage = fmt.Sprintf("this package architecture is %s", mismatchedArch) + initPackageVersion = "UnknownVersion" + mismatchedComponentChoicePackage = fmt.Sprintf("zarf-package-component-choice-%s.tar.zst", mismatchedArch) + mismatchedGamesPackage = fmt.Sprintf("zarf-package-dos-games-%s.tar.zst", mismatchedArch) + mismatchedInitPackage = fmt.Sprintf("zarf-init-%s-%s.tar.zst", mismatchedArch, initPackageVersion) + expectedErrorMessage = fmt.Sprintf("this package architecture is %s", mismatchedArch) ) // Build init package with different arch than the cluster arch. stdOut, stdErr, err := e2e.ExecZarfCommand("package", "create", ".", "--architecture", mismatchedArch, "--confirm") require.NoError(t, err, stdOut, stdErr) - defer e2e.CleanFiles(mismatchedInitPackageName) + defer e2e.CleanFiles(mismatchedInitPackage) - // Build deploy package with different arch than the cluster arch. + // Build dos-games package with different arch than the cluster arch. stdOut, stdErr, err = e2e.ExecZarfCommand("package", "create", "examples/dos-games/", "--architecture", mismatchedArch, "--confirm") require.NoError(t, err, stdOut, stdErr) - defer e2e.CleanFiles(mismatchedDeployPackageName) + defer e2e.CleanFiles(mismatchedGamesPackage) - // Make sure zarf init returns an error because of the mismatched architectures. + // Build component-choice package with different arch than the cluster arch. + stdOut, stdErr, err = e2e.ExecZarfCommand("package", "create", "examples/component-choice/", "--architecture", mismatchedArch, "--confirm") + require.NoError(t, err, stdOut, stdErr) + defer e2e.CleanFiles(mismatchedComponentChoicePackage) + + // Ensure zarf init returns an error because of the mismatched architectures. // We need to use the --architecture flag here to force zarf to find the package. _, stdErr, err = e2e.ExecZarfCommand("init", "--architecture", mismatchedArch, "--confirm") require.Error(t, err, stdErr) require.Contains(t, stdErr, expectedErrorMessage) - // Make sure zarf package deploy returns an error because of the mismatched architectures. - _, stdErr, err = e2e.ExecZarfCommand("package", "deploy", mismatchedDeployPackageName, "--confirm") + // Ensure zarf package deploy returns an error because of the mismatched architectures. + _, stdErr, err = e2e.ExecZarfCommand("package", "deploy", mismatchedGamesPackage, "--confirm") require.Error(t, err, stdErr) require.Contains(t, stdErr, expectedErrorMessage) + + // Ensure zarf package deploy is successful when a package has a mismatched architecture, + // but isn't deploying any k8s resources. + stdOut, stdErr, err = e2e.ExecZarfCommand("package", "deploy", mismatchedComponentChoicePackage, "--confirm") + require.NoError(t, err, stdOut, stdErr) } From 9c604c9bc32f4816fc24379d5ed79684dc603e49 Mon Sep 17 00:00:00 2001 From: Lucas Rodriguez Date: Tue, 18 Apr 2023 21:29:22 -0500 Subject: [PATCH 33/53] Consider successful check if applianceMode returns no error --- src/pkg/packager/common.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/pkg/packager/common.go b/src/pkg/packager/common.go index 059850b79e..f9f9dcd5bc 100644 --- a/src/pkg/packager/common.go +++ b/src/pkg/packager/common.go @@ -474,6 +474,8 @@ func (p *Packager) validatePackageArchitecture() error { if p.arch != clusterArch { return fmt.Errorf(lang.CmdPackageDeployValidateArchitectureErr, p.arch, clusterArch) } + + return nil } /* From 8fb0bd214b193e3ee93f4a313f38cf8f63b7fb30 Mon Sep 17 00:00:00 2001 From: Lucas Rodriguez Date: Sun, 23 Apr 2023 14:35:44 -0500 Subject: [PATCH 34/53] Update cluster connection method Remove logic to check for appliance mode Add comment to DefaultTimeout constant Replace use of 30 second timeouts with DefaultTimeout --- go.mod | 2 +- src/cmd/destroy.go | 3 +- src/internal/cluster/common.go | 1 + src/pkg/packager/common.go | 61 +++------------------------------- src/pkg/packager/deploy.go | 2 +- src/pkg/packager/remove.go | 3 +- 6 files changed, 9 insertions(+), 63 deletions(-) diff --git a/go.mod b/go.mod index ed0829e01b..bc84e88a47 100644 --- a/go.mod +++ b/go.mod @@ -10,6 +10,7 @@ replace ( ) require ( + cuelang.org/go v0.4.3 github.com/AlecAivazis/survey/v2 v2.3.6 github.com/Masterminds/semver/v3 v3.2.0 github.com/alecthomas/jsonschema v0.0.0-20220216202328-9eeeec9d044b @@ -56,7 +57,6 @@ require ( bitbucket.org/creachadair/shell v0.0.7 // indirect cloud.google.com/go/compute v1.19.0 // indirect cloud.google.com/go/compute/metadata v0.2.3 // indirect - cuelang.org/go v0.4.3 // indirect github.com/AdaLogics/go-fuzz-headers v0.0.0-20230106234847-43070de90fa1 // indirect github.com/AliyunContainerService/ack-ram-tool/pkg/credentials/alibabacloudsdkgo/helper v0.2.0 // indirect github.com/Azure/azure-sdk-for-go v66.0.0+incompatible // indirect diff --git a/src/cmd/destroy.go b/src/cmd/destroy.go index 512a576fb2..336a24ace6 100644 --- a/src/cmd/destroy.go +++ b/src/cmd/destroy.go @@ -8,7 +8,6 @@ import ( "errors" "os" "regexp" - "time" "github.com/defenseunicorns/zarf/src/config" "github.com/defenseunicorns/zarf/src/config/lang" @@ -30,7 +29,7 @@ var destroyCmd = &cobra.Command{ Short: lang.CmdDestroyShort, Long: lang.CmdDestroyLong, Run: func(cmd *cobra.Command, args []string) { - c, err := cluster.NewClusterWithWait(30*time.Second, true) + c, err := cluster.NewClusterWithWait(cluster.DefaultTimeout, true) if err != nil { message.Fatalf(err, lang.ErrNoClusterConnection) } diff --git a/src/internal/cluster/common.go b/src/internal/cluster/common.go index d706f1b770..4913b172e3 100644 --- a/src/internal/cluster/common.go +++ b/src/internal/cluster/common.go @@ -18,6 +18,7 @@ type Cluster struct { } const ( + // The default time to wait for a cluster to be ready. DefaultTimeout = 30 * time.Second agentLabel = "zarf.dev/agent" ) diff --git a/src/pkg/packager/common.go b/src/pkg/packager/common.go index f9f9dcd5bc..f7fff6d4cd 100644 --- a/src/pkg/packager/common.go +++ b/src/pkg/packager/common.go @@ -12,7 +12,6 @@ import ( "io" "os" "path/filepath" - "runtime" "sort" "strings" @@ -24,7 +23,6 @@ import ( "github.com/mholt/archiver/v3" "github.com/defenseunicorns/zarf/src/config" - "github.com/defenseunicorns/zarf/src/pkg/k8s" "github.com/defenseunicorns/zarf/src/pkg/message" "github.com/defenseunicorns/zarf/src/pkg/packager/deprecated" "github.com/defenseunicorns/zarf/src/pkg/utils" @@ -445,65 +443,14 @@ func (p *Packager) validatePackageChecksums() error { // validatePackageArchitecture validates that the package architecture matches the target cluster architecture. func (p *Packager) validatePackageArchitecture() error { - var ( - applianceMode bool - clusterArch string - err error - k8sTarget bool - ) - - // Iterate over the package components. - components := p.getValidComponents() - for _, component := range components { - // Determine whether we are working with an appliance mode init package. - if component.Name == k8s.DistroIsK3s && p.cfg.Pkg.Kind == "ZarfInitConfig" { - applianceMode = true - } - - // Determine whether we are deploying k8s resources. - if component.Images != nil { - k8sTarget = true - } - } - - // If we're working with an init package deploying k3s(appliance mode), - // set the clusterArch to the machine we're running on. - if applianceMode { - clusterArch = runtime.GOARCH - - if p.arch != clusterArch { - return fmt.Errorf(lang.CmdPackageDeployValidateArchitectureErr, p.arch, clusterArch) - } - - return nil - } - - /* - If we're already connected to a cluster, query the cluster for the architecture. - - If we're not already connected to a cluster and we're deploying k8s resources, - attempt to establish a new k8s client connection and query the cluster for the architecture. - */ - if p.cluster != nil { - clusterArch, err = p.cluster.Kube.GetArchitecture() - if err != nil { - return err - } - - if p.arch != clusterArch { - return fmt.Errorf(lang.CmdPackageDeployValidateArchitectureErr, p.arch, clusterArch) - } - } else if k8sTarget { - client, err := cluster.NewClusterWithWait(cluster.DefaultTimeout, false) - if err != nil { - return err - } - - clusterArch, err = client.Kube.GetArchitecture() + // Attempt to connect to a cluster to get the architecture. + if cluster, err := cluster.NewClusterWithWait(cluster.DefaultTimeout, false); err == nil { + clusterArch, err := cluster.Kube.GetArchitecture() if err != nil { return err } + // Check if the package architecture and the cluster architecture are the same. if p.arch != clusterArch { return fmt.Errorf(lang.CmdPackageDeployValidateArchitectureErr, p.arch, clusterArch) } diff --git a/src/pkg/packager/deploy.go b/src/pkg/packager/deploy.go index 263f38e272..d181caec7a 100644 --- a/src/pkg/packager/deploy.go +++ b/src/pkg/packager/deploy.go @@ -221,7 +221,7 @@ func (p *Packager) deployComponent(component types.ZarfComponent, noImgChecksum // Make sure we have access to the cluster if p.cluster == nil { - p.cluster, err = cluster.NewClusterWithWait(30*time.Second, true) + p.cluster, err = cluster.NewClusterWithWait(cluster.DefaultTimeout, true) if err != nil { return charts, fmt.Errorf("unable to connect to the Kubernetes cluster: %w", err) } diff --git a/src/pkg/packager/remove.go b/src/pkg/packager/remove.go index 24170dea98..4013cfb43b 100644 --- a/src/pkg/packager/remove.go +++ b/src/pkg/packager/remove.go @@ -8,7 +8,6 @@ import ( "encoding/json" "fmt" "strings" - "time" "github.com/defenseunicorns/zarf/src/config" "github.com/defenseunicorns/zarf/src/internal/cluster" @@ -64,7 +63,7 @@ func (p *Packager) Remove(packageName string) (err error) { if requiresCluster { // If we need the cluster, connect to it and pull the package secret if p.cluster == nil { - p.cluster, err = cluster.NewClusterWithWait(30*time.Second, true) + p.cluster, err = cluster.NewClusterWithWait(cluster.DefaultTimeout, true) if err != nil { return fmt.Errorf("unable to connect to the Kubernetes cluster: %w", err) } From bdabd2a95fc64dba384a83719502ed34c465fe7a Mon Sep 17 00:00:00 2001 From: Lucas Rodriguez Date: Mon, 24 Apr 2023 19:51:56 -0500 Subject: [PATCH 35/53] Add architecture validation to k3s package --- packages/distros/k3s/zarf.yaml | 8 ++++++++ .../e2e/29_mismatched_architectures_test.go | 20 ++++--------------- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/packages/distros/k3s/zarf.yaml b/packages/distros/k3s/zarf.yaml index f8a2c0897a..a149013e68 100644 --- a/packages/distros/k3s/zarf.yaml +++ b/packages/distros/k3s/zarf.yaml @@ -27,6 +27,10 @@ components: - source: https://github.com/k3s-io/k3s/releases/download/v1.24.1+k3s1/k3s-airgap-images-amd64.tar.zst shasum: 6736f9fa4d5754d60b0508bafb2f888170cb99a2d93a3a1617a919ca4ee74034 target: /var/lib/rancher/k3s/agent/images/k3s.tar.zst + actions: + onDeploy: + before: + - cmd: if [[ $(arch) != "x86_64" ]]; then echo "this package architecture is amd64, but the target cluster has the arm64 architecture. These architectures must be the same" && exit 1; fi # ARM-64 version of the K3s stack - name: k3s @@ -51,3 +55,7 @@ components: - source: https://github.com/k3s-io/k3s/releases/download/v1.24.1+k3s1/k3s-airgap-images-arm64.tar.zst shasum: 12029e4bbfecfa16942345aeac798f4790e568a7202c2b85ee068d7b4756ba04 target: /var/lib/rancher/k3s/agent/images/k3s.tar.zst + actions: + onDeploy: + before: + - cmd: if [[ $(arch) != "arm64" ]]; then echo "this package architecture is arm64, but the target cluster has the amd64 architecture. These architectures must be the same" && exit 1; fi \ No newline at end of file diff --git a/src/test/e2e/29_mismatched_architectures_test.go b/src/test/e2e/29_mismatched_architectures_test.go index 41f8448e98..92f270c822 100644 --- a/src/test/e2e/29_mismatched_architectures_test.go +++ b/src/test/e2e/29_mismatched_architectures_test.go @@ -29,11 +29,10 @@ func TestMismatchedArchitectures(t *testing.T) { } var ( - initPackageVersion = "UnknownVersion" - mismatchedComponentChoicePackage = fmt.Sprintf("zarf-package-component-choice-%s.tar.zst", mismatchedArch) - mismatchedGamesPackage = fmt.Sprintf("zarf-package-dos-games-%s.tar.zst", mismatchedArch) - mismatchedInitPackage = fmt.Sprintf("zarf-init-%s-%s.tar.zst", mismatchedArch, initPackageVersion) - expectedErrorMessage = fmt.Sprintf("this package architecture is %s", mismatchedArch) + initPackageVersion = "UnknownVersion" + mismatchedGamesPackage = fmt.Sprintf("zarf-package-dos-games-%s.tar.zst", mismatchedArch) + mismatchedInitPackage = fmt.Sprintf("zarf-init-%s-%s.tar.zst", mismatchedArch, initPackageVersion) + expectedErrorMessage = fmt.Sprintf("this package architecture is %s", mismatchedArch) ) // Build init package with different arch than the cluster arch. @@ -46,24 +45,13 @@ func TestMismatchedArchitectures(t *testing.T) { require.NoError(t, err, stdOut, stdErr) defer e2e.CleanFiles(mismatchedGamesPackage) - // Build component-choice package with different arch than the cluster arch. - stdOut, stdErr, err = e2e.ExecZarfCommand("package", "create", "examples/component-choice/", "--architecture", mismatchedArch, "--confirm") - require.NoError(t, err, stdOut, stdErr) - defer e2e.CleanFiles(mismatchedComponentChoicePackage) - // Ensure zarf init returns an error because of the mismatched architectures. // We need to use the --architecture flag here to force zarf to find the package. _, stdErr, err = e2e.ExecZarfCommand("init", "--architecture", mismatchedArch, "--confirm") require.Error(t, err, stdErr) - require.Contains(t, stdErr, expectedErrorMessage) // Ensure zarf package deploy returns an error because of the mismatched architectures. _, stdErr, err = e2e.ExecZarfCommand("package", "deploy", mismatchedGamesPackage, "--confirm") require.Error(t, err, stdErr) require.Contains(t, stdErr, expectedErrorMessage) - - // Ensure zarf package deploy is successful when a package has a mismatched architecture, - // but isn't deploying any k8s resources. - stdOut, stdErr, err = e2e.ExecZarfCommand("package", "deploy", mismatchedComponentChoicePackage, "--confirm") - require.NoError(t, err, stdOut, stdErr) } From fec42f9023f2eebe5c7bb715a6ab6e29e578f507 Mon Sep 17 00:00:00 2001 From: Lucas Rodriguez Date: Mon, 24 Apr 2023 20:01:05 -0500 Subject: [PATCH 36/53] Add name of constant DefaultTimeout to comment to fix linting error --- src/internal/cluster/common.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/internal/cluster/common.go b/src/internal/cluster/common.go index 4913b172e3..11bfa7a3e9 100644 --- a/src/internal/cluster/common.go +++ b/src/internal/cluster/common.go @@ -18,7 +18,7 @@ type Cluster struct { } const ( - // The default time to wait for a cluster to be ready. + // DefaultTimeout is the default time to wait for a cluster to be ready. DefaultTimeout = 30 * time.Second agentLabel = "zarf.dev/agent" ) From b4f977629a11c849f9131e1556a5ff368eee7487 Mon Sep 17 00:00:00 2001 From: Lucas Rodriguez Date: Mon, 24 Apr 2023 20:19:10 -0500 Subject: [PATCH 37/53] Add test case for zarf init in appliance mode --- src/test/e2e/29_mismatched_architectures_test.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/test/e2e/29_mismatched_architectures_test.go b/src/test/e2e/29_mismatched_architectures_test.go index 92f270c822..d3abd22bd2 100644 --- a/src/test/e2e/29_mismatched_architectures_test.go +++ b/src/test/e2e/29_mismatched_architectures_test.go @@ -49,6 +49,12 @@ func TestMismatchedArchitectures(t *testing.T) { // We need to use the --architecture flag here to force zarf to find the package. _, stdErr, err = e2e.ExecZarfCommand("init", "--architecture", mismatchedArch, "--confirm") require.Error(t, err, stdErr) + require.Contains(t, stdErr, expectedErrorMessage) + + // Ensure zarf init in appliance mode returns an error because of the mismatched architectures. + // We need to use the --architecture flag here to force zarf to find the package. + _, stdErr, err = e2e.ExecZarfCommand("init", "--architecture", mismatchedArch, "--components=k3s", "--confirm") + require.Error(t, err, stdErr) // Ensure zarf package deploy returns an error because of the mismatched architectures. _, stdErr, err = e2e.ExecZarfCommand("package", "deploy", mismatchedGamesPackage, "--confirm") From 219c272c17519a5a42b895775253179e40c3cc89 Mon Sep 17 00:00:00 2001 From: Lucas Rodriguez Date: Mon, 24 Apr 2023 21:32:33 -0500 Subject: [PATCH 38/53] Add appliance mode test case to zarf_init_test Add helper function for setting mismatched arch in tests --- src/test/common.go | 13 ++++++++++ src/test/e2e/20_zarf_init_test.go | 24 +++++++++++++++++-- .../e2e/29_mismatched_architectures_test.go | 18 ++------------ 3 files changed, 37 insertions(+), 18 deletions(-) diff --git a/src/test/common.go b/src/test/common.go index 5f968ec9bb..402e7598cf 100644 --- a/src/test/common.go +++ b/src/test/common.go @@ -17,6 +17,7 @@ import ( type ZarfE2ETest struct { ZarfBinPath string Arch string + MismatchedArch string ApplianceMode bool RunClusterTests bool } @@ -75,3 +76,15 @@ func (e2e *ZarfE2ETest) CleanFiles(files ...string) { _ = os.RemoveAll(file) } } + +// SetMismatchedArch determines what architecture our tests are running on, +// and sets e2e.MismatchedArch to the opposite architecture. +func (e2e *ZarfE2ETest) SetMismatchedArch() string { + if e2e.Arch == "amd64" { + e2e.MismatchedArch = "arm64" + } + if e2e.Arch == "arm64" { + e2e.MismatchedArch = "amd64" + } + return e2e.MismatchedArch +} diff --git a/src/test/e2e/20_zarf_init_test.go b/src/test/e2e/20_zarf_init_test.go index cabbb49afe..8493ea8f2a 100644 --- a/src/test/e2e/20_zarf_init_test.go +++ b/src/test/e2e/20_zarf_init_test.go @@ -6,6 +6,7 @@ package test import ( "context" + "fmt" "testing" "time" @@ -27,13 +28,30 @@ func TestZarfInit(t *testing.T) { ctx, cancel := context.WithTimeout(context.TODO(), 10*time.Minute) defer cancel() + var ( + mismatchedArch = e2e.SetMismatchedArch() + initPackageVersion = "UnknownVersion" + mismatchedInitPackage = fmt.Sprintf("zarf-init-%s-%s.tar.zst", mismatchedArch, initPackageVersion) + ) + + // Build init package with different arch than the cluster arch. + stdOut, stdErr, err := e2e.ExecZarfCommand("package", "create", ".", "--architecture", mismatchedArch, "--confirm") + require.NoError(t, err, stdOut, stdErr) + defer e2e.CleanFiles(mismatchedInitPackage) + + // Check that `zarf init` fails in appliance mode when we try to initialize a k3s cluster + // on a machine with a different architecture than the package architecture. + // We need to use the --architecture flag here to force zarf to find the package. + _, stdErr, err = e2e.ExecZarfCommand("init", "--architecture", mismatchedArch, "--components=k3s", "--confirm") + require.Error(t, err, stdErr) + // run `zarf init` - _, stdErr, err := exec.CmdWithContext(ctx, exec.PrintCfg(), e2e.ZarfBinPath, "init", "--components="+initComponents, "--confirm", "--nodeport", "31337") + _, stdErr, err = exec.CmdWithContext(ctx, exec.PrintCfg(), e2e.ZarfBinPath, "init", "--components="+initComponents, "--confirm", "--nodeport", "31337") require.Contains(t, stdErr, "artifacts with software bill-of-materials (SBOM) included") require.NoError(t, err) // Check that gitea is actually running and healthy - stdOut, _, err := e2e.ExecZarfCommand("tools", "kubectl", "get", "pods", "-l", "app in (gitea)", "-n", "zarf", "-o", "jsonpath={.items[*].status.phase}") + stdOut, _, err = e2e.ExecZarfCommand("tools", "kubectl", "get", "pods", "-l", "app in (gitea)", "-n", "zarf", "-o", "jsonpath={.items[*].status.phase}") require.NoError(t, err) require.Contains(t, stdOut, "Running") @@ -61,4 +79,6 @@ func TestZarfInit(t *testing.T) { // Special sizing-hacking for reducing resources where Kind + CI eats a lot of free cycles (ignore errors) _, _, _ = e2e.ExecZarfCommand("tools", "kubectl", "scale", "deploy", "-n", "kube-system", "coredns", "--replicas=1") _, _, _ = e2e.ExecZarfCommand("tools", "kubectl", "scale", "deploy", "-n", "zarf", "agent-hook", "--replicas=1") + + // } diff --git a/src/test/e2e/29_mismatched_architectures_test.go b/src/test/e2e/29_mismatched_architectures_test.go index d3abd22bd2..d01291dd4b 100644 --- a/src/test/e2e/29_mismatched_architectures_test.go +++ b/src/test/e2e/29_mismatched_architectures_test.go @@ -18,19 +18,10 @@ func TestMismatchedArchitectures(t *testing.T) { e2e.SetupWithCluster(t) defer e2e.Teardown(t) - // Determine what test runner architecture we're running on, - // and set mismatchedArch to the opposite architecture. - var mismatchedArch string - if e2e.Arch == "amd64" { - mismatchedArch = "arm64" - } - if e2e.Arch == "arm64" { - mismatchedArch = "amd64" - } - var ( - initPackageVersion = "UnknownVersion" + mismatchedArch = e2e.SetMismatchedArch() mismatchedGamesPackage = fmt.Sprintf("zarf-package-dos-games-%s.tar.zst", mismatchedArch) + initPackageVersion = "UnknownVersion" mismatchedInitPackage = fmt.Sprintf("zarf-init-%s-%s.tar.zst", mismatchedArch, initPackageVersion) expectedErrorMessage = fmt.Sprintf("this package architecture is %s", mismatchedArch) ) @@ -51,11 +42,6 @@ func TestMismatchedArchitectures(t *testing.T) { require.Error(t, err, stdErr) require.Contains(t, stdErr, expectedErrorMessage) - // Ensure zarf init in appliance mode returns an error because of the mismatched architectures. - // We need to use the --architecture flag here to force zarf to find the package. - _, stdErr, err = e2e.ExecZarfCommand("init", "--architecture", mismatchedArch, "--components=k3s", "--confirm") - require.Error(t, err, stdErr) - // Ensure zarf package deploy returns an error because of the mismatched architectures. _, stdErr, err = e2e.ExecZarfCommand("package", "deploy", mismatchedGamesPackage, "--confirm") require.Error(t, err, stdErr) From df8a6a98f53648107e572d9dfbce2b555c537819 Mon Sep 17 00:00:00 2001 From: Lucas Rodriguez Date: Mon, 24 Apr 2023 22:06:27 -0500 Subject: [PATCH 39/53] Remove echo statement from arch check in k3s package actions Set maxRetries to 0 --- packages/distros/k3s/zarf.yaml | 6 ++++-- src/test/e2e/20_zarf_init_test.go | 2 -- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/distros/k3s/zarf.yaml b/packages/distros/k3s/zarf.yaml index a149013e68..3a43872aab 100644 --- a/packages/distros/k3s/zarf.yaml +++ b/packages/distros/k3s/zarf.yaml @@ -30,7 +30,8 @@ components: actions: onDeploy: before: - - cmd: if [[ $(arch) != "x86_64" ]]; then echo "this package architecture is amd64, but the target cluster has the arm64 architecture. These architectures must be the same" && exit 1; fi + - cmd: if [[ $(arch) != "x86_64" ]]; then exit 1; fi + maxRetries: 0 # ARM-64 version of the K3s stack - name: k3s @@ -58,4 +59,5 @@ components: actions: onDeploy: before: - - cmd: if [[ $(arch) != "arm64" ]]; then echo "this package architecture is arm64, but the target cluster has the amd64 architecture. These architectures must be the same" && exit 1; fi \ No newline at end of file + - cmd: if [[ $(arch) != "arm64" ]]; then exit 1; fi + maxRetries: 0 \ No newline at end of file diff --git a/src/test/e2e/20_zarf_init_test.go b/src/test/e2e/20_zarf_init_test.go index 8493ea8f2a..f4558e6c1a 100644 --- a/src/test/e2e/20_zarf_init_test.go +++ b/src/test/e2e/20_zarf_init_test.go @@ -79,6 +79,4 @@ func TestZarfInit(t *testing.T) { // Special sizing-hacking for reducing resources where Kind + CI eats a lot of free cycles (ignore errors) _, _, _ = e2e.ExecZarfCommand("tools", "kubectl", "scale", "deploy", "-n", "kube-system", "coredns", "--replicas=1") _, _, _ = e2e.ExecZarfCommand("tools", "kubectl", "scale", "deploy", "-n", "zarf", "agent-hook", "--replicas=1") - - // } From d7e9cdcbcf7e90af8e58adf8e822b9c27f0869b0 Mon Sep 17 00:00:00 2001 From: Lucas Rodriguez Date: Mon, 1 May 2023 17:48:53 -0500 Subject: [PATCH 40/53] Update action cmd in k3s package for checking arch --- packages/distros/k3s/zarf.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/distros/k3s/zarf.yaml b/packages/distros/k3s/zarf.yaml index 3a43872aab..3e14237220 100644 --- a/packages/distros/k3s/zarf.yaml +++ b/packages/distros/k3s/zarf.yaml @@ -30,7 +30,7 @@ components: actions: onDeploy: before: - - cmd: if [[ $(arch) != "x86_64" ]]; then exit 1; fi + - cmd: if [[ $(arch) != "x86_64" ]]; then echo \"I failed\" && exit 1; fi maxRetries: 0 # ARM-64 version of the K3s stack @@ -59,5 +59,5 @@ components: actions: onDeploy: before: - - cmd: if [[ $(arch) != "arm64" ]]; then exit 1; fi + - cmd: if [[ $(arch) != "arm64" ]]; then echo \"I failed\" && exit 1; fi maxRetries: 0 \ No newline at end of file From 17681911dda239206fa6da71328d54bf39166e9d Mon Sep 17 00:00:00 2001 From: Lucas Rodriguez Date: Mon, 1 May 2023 18:51:15 -0500 Subject: [PATCH 41/53] Check for exit code 0 when running actions --- src/cmd/tools/wait.go | 4 +- src/internal/cluster/data.go | 2 +- src/internal/packager/git/clone.go | 2 +- src/pkg/packager/actions.go | 5 ++- src/pkg/utils/exec/exec.go | 16 ++++---- src/test/common.go | 2 +- src/test/e2e/00_use_cli_test.go | 24 +++++------ src/test/e2e/01_component_choice_test.go | 6 +-- src/test/e2e/02_component_actions_test.go | 18 ++++----- src/test/e2e/03_temp_directory_deploy_test.go | 2 +- src/test/e2e/04_create_templating_test.go | 6 +-- src/test/e2e/05_multi_part_test.go | 4 +- src/test/e2e/06_create_sbom_test.go | 8 ++-- src/test/e2e/07_create_git_test.go | 18 ++++----- src/test/e2e/20_zarf_init_test.go | 22 +++++----- src/test/e2e/21_connect_test.go | 4 +- src/test/e2e/22_git_and_flux_test.go | 10 ++--- src/test/e2e/23_data_injection_test.go | 6 +-- src/test/e2e/24_variables_test.go | 10 ++--- src/test/e2e/25_helm_test.go | 40 +++++++++---------- src/test/e2e/26_simple_packages_test.go | 8 ++-- src/test/e2e/27_cosign_deploy_test.go | 4 +- src/test/e2e/28_wait_test.go | 4 +- .../e2e/29_mismatched_architectures_test.go | 8 ++-- src/test/e2e/30_config_file_test.go | 16 ++++---- .../e2e/31_component_action_remove_test.go | 4 +- .../e2e/32_checksum_and_signature_test.go | 10 ++--- .../40_deprecated_component_scripts_test.go | 6 +-- .../e2e/41_deprecations_set_variables_test.go | 8 ++-- src/test/e2e/50_oci_package_test.go | 28 ++++++------- src/test/e2e/99_yolo_test.go | 6 +-- src/test/external-test/common.go | 2 +- .../external-test/ext_in_cluster_init_test.go | 2 +- src/test/nightly/ecr_publish_test.go | 14 +++---- .../upgrade-test/previously_built_test.go | 20 +++++----- 35 files changed, 176 insertions(+), 173 deletions(-) diff --git a/src/cmd/tools/wait.go b/src/cmd/tools/wait.go index 956ae26b8f..1e7a70f225 100644 --- a/src/cmd/tools/wait.go +++ b/src/cmd/tools/wait.go @@ -111,7 +111,7 @@ var waitForCmd = &cobra.Command{ spinner.Updatef(existMsg) // Check if the resource exists. args := []string{"tools", "kubectl", "get", "-n", waitNamespace, kind, identifier} - if stdout, stderr, err := exec.Cmd(zarfBinPath, args...); err != nil { + if stdout, stderr, _, err := exec.Cmd(zarfBinPath, args...); err != nil { message.Debug(stdout, stderr, err) continue } @@ -130,7 +130,7 @@ var waitForCmd = &cobra.Command{ "--timeout=" + waitTimeout} // If there is an error, log it and try again. - if stdout, stderr, err := exec.Cmd(zarfBinPath, args...); err != nil { + if stdout, stderr, _, err := exec.Cmd(zarfBinPath, args...); err != nil { message.Debug(stdout, stderr, err) continue } diff --git a/src/internal/cluster/data.go b/src/internal/cluster/data.go index d1767343c2..33d59a4314 100644 --- a/src/internal/cluster/data.go +++ b/src/internal/cluster/data.go @@ -46,7 +46,7 @@ func (c *Cluster) HandleDataInjection(wg *sync.WaitGroup, data types.ZarfDataInj // Get the OS shell to execute commands in shell, shellArgs := exec.GetOSShell(types.ZarfComponentActionShell{Windows: "cmd"}) - if _, _, err := exec.Cmd(shell, shellArgs, "tar --version"); err != nil { + if _, _, _, err := exec.Cmd(shell, shellArgs, "tar --version"); err != nil { message.Error(err, "Unable to execute tar on this system. Please ensure it is installed and on your $PATH.") return } diff --git a/src/internal/packager/git/clone.go b/src/internal/packager/git/clone.go index 6ef4301350..81ecb25b80 100644 --- a/src/internal/packager/git/clone.go +++ b/src/internal/packager/git/clone.go @@ -87,7 +87,7 @@ func (g *Git) gitCloneFallback(gitURL string, ref plumbing.ReferenceName) error Stdout: g.Spinner, Stderr: g.Spinner, } - _, _, err := exec.CmdWithContext(context.TODO(), execConfig, "git", cmdArgs...) + _, _, _, err := exec.CmdWithContext(context.TODO(), execConfig, "git", cmdArgs...) if err != nil { return err } diff --git a/src/pkg/packager/actions.go b/src/pkg/packager/actions.go index 66887890b0..6c910a91d0 100644 --- a/src/pkg/packager/actions.go +++ b/src/pkg/packager/actions.go @@ -278,11 +278,14 @@ func actionRun(ctx context.Context, cfg types.ZarfComponentActionDefaults, cmd s execCfg.Stderr = spinner } - out, errOut, err := exec.CmdWithContext(ctx, execCfg, shell, shellArgs, cmd) + out, errOut, exitCode, err := exec.CmdWithContext(ctx, execCfg, shell, shellArgs, cmd) // Dump final complete output (respect mute to prevent sensitive values from hitting the logs). if !cfg.Mute { message.Debug(cmd, out, errOut) } + if exitCode != 0 { + return "", err + } return out, err } diff --git a/src/pkg/utils/exec/exec.go b/src/pkg/utils/exec/exec.go index 09ca2a4794..93a8fa5089 100644 --- a/src/pkg/utils/exec/exec.go +++ b/src/pkg/utils/exec/exec.go @@ -39,20 +39,20 @@ func PrintCfg() Config { } // Cmd executes a given command with given config. -func Cmd(command string, args ...string) (string, string, error) { +func Cmd(command string, args ...string) (string, string, int, error) { return CmdWithContext(context.TODO(), Config{}, command, args...) } // CmdWithPrint executes a given command with given config and prints the command. func CmdWithPrint(command string, args ...string) error { - _, _, err := CmdWithContext(context.TODO(), PrintCfg(), command, args...) + _, _, _, err := CmdWithContext(context.TODO(), PrintCfg(), command, args...) return err } // CmdWithContext executes a given command with given config. -func CmdWithContext(ctx context.Context, config Config, command string, args ...string) (string, string, error) { +func CmdWithContext(ctx context.Context, config Config, command string, args ...string) (string, string, int, error) { if command == "" { - return "", "", errors.New("command is required") + return "", "", 0, errors.New("command is required") } // Set up the command. @@ -106,7 +106,7 @@ func CmdWithContext(ctx context.Context, config Config, command string, args ... // Start the command. if err := cmd.Start(); err != nil { - return "", "", err + return "", "", 0, err } // Add to waitgroup for each goroutine. @@ -129,14 +129,14 @@ func CmdWithContext(ctx context.Context, config Config, command string, args ... // Abort if there was an error capturing the command's outputs. if errStdout != nil { - return "", "", fmt.Errorf("failed to capture the stdout command output: %w", errStdout) + return "", "", 0, fmt.Errorf("failed to capture the stdout command output: %w", errStdout) } if errStderr != nil { - return "", "", fmt.Errorf("failed to capture the stderr command output: %w", errStderr) + return "", "", 0, fmt.Errorf("failed to capture the stderr command output: %w", errStderr) } // Wait for the command to finish and return the buffered outputs, regardless of whether we printed them. - return stdoutBuf.String(), stderrBuf.String(), cmd.Wait() + return stdoutBuf.String(), stderrBuf.String(), cmd.ProcessState.ExitCode(), cmd.Wait() } // LaunchURL opens a URL in the default browser. diff --git a/src/test/common.go b/src/test/common.go index 402e7598cf..5d4cbe253e 100644 --- a/src/test/common.go +++ b/src/test/common.go @@ -66,7 +66,7 @@ func (e2e *ZarfE2ETest) Teardown(t *testing.T) { } // ExecZarfCommand executes a Zarf command. -func (e2e *ZarfE2ETest) ExecZarfCommand(commandString ...string) (string, string, error) { +func (e2e *ZarfE2ETest) ExecZarfCommand(commandString ...string) (string, string, int, error) { return exec.CmdWithContext(context.TODO(), exec.PrintCfg(), e2e.ZarfBinPath, commandString...) } diff --git a/src/test/e2e/00_use_cli_test.go b/src/test/e2e/00_use_cli_test.go index af3e3ae05c..4f61e01a87 100644 --- a/src/test/e2e/00_use_cli_test.go +++ b/src/test/e2e/00_use_cli_test.go @@ -36,54 +36,54 @@ func TestUseCLI(t *testing.T) { err := os.WriteFile(shasumTestFilePath, []byte("random test data 🦄\n"), 0600) assert.NoError(t, err) - stdOut, stdErr, err := e2e.ExecZarfCommand("prepare", "sha256sum", shasumTestFilePath) + stdOut, stdErr, _, err := e2e.ExecZarfCommand("prepare", "sha256sum", shasumTestFilePath) assert.NoError(t, err, stdOut, stdErr) assert.Equal(t, expectedShasum, stdOut, "The expected SHASUM should equal the actual SHASUM") // Test `zarf prepare sha256sum` for a remote asset expectedShasum = "c3cdea0573ba5a058ec090b5d2683bf398e8b1614c37ec81136ed03b78167617\n" - stdOut, stdErr, err = e2e.ExecZarfCommand("prepare", "sha256sum", "https://zarf-public.s3-us-gov-west-1.amazonaws.com/pipelines/zarf-prepare-shasum-remote-test-file.txt") + stdOut, stdErr, _, err = e2e.ExecZarfCommand("prepare", "sha256sum", "https://zarf-public.s3-us-gov-west-1.amazonaws.com/pipelines/zarf-prepare-shasum-remote-test-file.txt") assert.NoError(t, err, stdOut, stdErr) assert.Contains(t, stdOut, expectedShasum, "The expected SHASUM should equal the actual SHASUM") // Test `zarf version` - stdOut, _, err = e2e.ExecZarfCommand("version") + stdOut, _, _, err = e2e.ExecZarfCommand("version") assert.NoError(t, err) assert.NotEqual(t, len(stdOut), 0, "Zarf version should not be an empty string") assert.NotEqual(t, stdOut, "UnknownVersion", "Zarf version should not be the default value") // Test `zarf prepare find-images` for a remote asset - stdOut, stdErr, err = e2e.ExecZarfCommand("prepare", "find-images", "examples/helm-alt-release-name") + stdOut, stdErr, _, err = e2e.ExecZarfCommand("prepare", "find-images", "examples/helm-alt-release-name") assert.NoError(t, err, stdOut, stdErr) assert.Contains(t, stdOut, "ghcr.io/stefanprodan/podinfo:6.1.6", "The chart image should be found by Zarf") // Test `zarf prepare find-images` for a local asset - stdOut, stdErr, err = e2e.ExecZarfCommand("prepare", "find-images", "examples/helm-local-chart") + stdOut, stdErr, _, err = e2e.ExecZarfCommand("prepare", "find-images", "examples/helm-local-chart") assert.NoError(t, err, stdOut, stdErr) assert.Contains(t, stdOut, "nginx:1.16.0", "The chart image should be found by Zarf") // Test for expected failure when given a bad component input - _, _, err = e2e.ExecZarfCommand("init", "--confirm", "--components=k3s,foo,logging") + _, _, _, err = e2e.ExecZarfCommand("init", "--confirm", "--components=k3s,foo,logging") assert.Error(t, err) // Test that changing the log level actually applies the requested level - _, stdErr, _ = e2e.ExecZarfCommand("version", "--log-level=debug") + _, stdErr, _, _ = e2e.ExecZarfCommand("version", "--log-level=debug") expectedOutString := "Log level set to debug" require.Contains(t, stdErr, expectedOutString, "The log level should be changed to 'debug'") // Test that `zarf package deploy` gives an error if deploying a remote package without the --insecure or --shasum flags - stdOut, stdErr, err = e2e.ExecZarfCommand("package", "deploy", "https://zarf-examples.s3.amazonaws.com/zarf-package-appliance-demo-doom-20210125.tar.zst", "--confirm") + stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "deploy", "https://zarf-examples.s3.amazonaws.com/zarf-package-appliance-demo-doom-20210125.tar.zst", "--confirm") assert.Error(t, err, stdOut, stdErr) pkgName := fmt.Sprintf("zarf-package-dos-games-%s.tar.zst", e2e.Arch) _ = os.Mkdir(otherTmpPath, 0750) - stdOut, stdErr, err = e2e.ExecZarfCommand("package", "create", "examples/dos-games", "--confirm", "--zarf-cache", cachePath, "--tmpdir", otherTmpPath, "--log-level=debug") + stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "create", "examples/dos-games", "--confirm", "--zarf-cache", cachePath, "--tmpdir", otherTmpPath, "--log-level=debug") require.Contains(t, stdErr, otherTmpPath, "The other tmp path should show as being created") require.NoError(t, err, stdOut, stdErr) - stdOut, stdErr, err = e2e.ExecZarfCommand("package", "inspect", pkgName, "--tmpdir", otherTmpPath, "--log-level=debug") + stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "inspect", pkgName, "--tmpdir", otherTmpPath, "--log-level=debug") require.Contains(t, stdErr, otherTmpPath, "The other tmp path should show as being created") require.NoError(t, err, stdOut, stdErr) @@ -94,7 +94,7 @@ func TestUseCLI(t *testing.T) { assert.Greater(t, len(files), 1) // Test removal of cache - stdOut, stdErr, err = e2e.ExecZarfCommand("tools", "clear-cache", "--zarf-cache", cachePath) + stdOut, stdErr, _, err = e2e.ExecZarfCommand("tools", "clear-cache", "--zarf-cache", cachePath) require.NoError(t, err, stdOut, stdErr) // Check that ReadDir returns no such file or directory for the cachePath @@ -111,7 +111,7 @@ func TestUseCLI(t *testing.T) { tlsCA := "tls.ca" tlsCert := "tls.crt" tlsKey := "tls.key" - stdOut, stdErr, err = e2e.ExecZarfCommand("tools", "gen-pki", "github.com", "--sub-alt-name", "google.com") + stdOut, stdErr, _, err = e2e.ExecZarfCommand("tools", "gen-pki", "github.com", "--sub-alt-name", "google.com") require.NoError(t, err, stdOut, stdErr) require.Contains(t, stdErr, "Successfully created a chain of trust for github.com") diff --git a/src/test/e2e/01_component_choice_test.go b/src/test/e2e/01_component_choice_test.go index e81f3f0c83..6de8906a04 100644 --- a/src/test/e2e/01_component_choice_test.go +++ b/src/test/e2e/01_component_choice_test.go @@ -27,11 +27,11 @@ func TestComponentChoice(t *testing.T) { // Try to deploy both and expect failure due to only one component allowed at a time // We currently don't have a pattern to actually test the interactive prompt, so just testing automation for now - stdOut, stdErr, err := e2e.ExecZarfCommand("package", "deploy", path, "--confirm", "--components=first-choice,second-choice") + stdOut, stdErr, _, err := e2e.ExecZarfCommand("package", "deploy", path, "--confirm", "--components=first-choice,second-choice") require.Error(t, err, stdOut, stdErr) // Deploy a single choice and expect success - stdOut, stdErr, err = e2e.ExecZarfCommand("package", "deploy", path, "--confirm", "--components=first-choice") + stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "deploy", path, "--confirm", "--components=first-choice") require.NoError(t, err, stdOut, stdErr) // Verify the file was created @@ -40,7 +40,7 @@ func TestComponentChoice(t *testing.T) { require.NoFileExists(t, secondFile) // Deploy using default choice - stdOut, stdErr, err = e2e.ExecZarfCommand("package", "deploy", path, "--confirm") + stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "deploy", path, "--confirm") require.NoError(t, err, stdOut, stdErr) // Verify the file was created diff --git a/src/test/e2e/02_component_actions_test.go b/src/test/e2e/02_component_actions_test.go index f4e56156a4..f9631373ef 100644 --- a/src/test/e2e/02_component_actions_test.go +++ b/src/test/e2e/02_component_actions_test.go @@ -36,7 +36,7 @@ func TestComponentActions(t *testing.T) { /* Create */ // Try creating the package to test the onCreate actions. - stdOut, stdErr, err := e2e.ExecZarfCommand("package", "create", "examples/component-actions", "--confirm") + stdOut, stdErr, _, err := e2e.ExecZarfCommand("package", "create", "examples/component-actions", "--confirm") require.NoError(t, err, stdOut, stdErr) require.Contains(t, stdErr, "Completed \"touch test-create-before.txt\"") require.Contains(t, stdErr, "multiline!") @@ -57,7 +57,7 @@ func TestComponentActions(t *testing.T) { /* Deploy */ path := fmt.Sprintf("build/zarf-package-component-actions-%s.tar.zst", e2e.Arch) // Deploy the simple script that should pass. - stdOut, stdErr, err = e2e.ExecZarfCommand("package", "deploy", path, "--confirm", "--components=on-deploy-and-remove") + stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "deploy", path, "--confirm", "--components=on-deploy-and-remove") require.NoError(t, err, stdOut, stdErr) // Check that the deploy artifacts were created. @@ -66,7 +66,7 @@ func TestComponentActions(t *testing.T) { } // Remove the simple script that should pass. - stdOut, stdErr, err = e2e.ExecZarfCommand("package", "remove", path, "--confirm", "--components=on-deploy-and-remove") + stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "remove", path, "--confirm", "--components=on-deploy-and-remove") require.NoError(t, err, stdOut, stdErr) // Check that the deploy artifacts were created. @@ -75,17 +75,17 @@ func TestComponentActions(t *testing.T) { } // Deploy the simple action that should fail the timeout. - stdOut, stdErr, err = e2e.ExecZarfCommand("package", "deploy", path, "--confirm", "--components=on-deploy-with-timeout") + stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "deploy", path, "--confirm", "--components=on-deploy-with-timeout") require.Error(t, err, stdOut, stdErr) require.Contains(t, stdErr, "😭😭😭 this action failed because it took too long to run 😭😭😭") // Test using a Zarf Variable within the action - stdOut, stdErr, err = e2e.ExecZarfCommand("package", "deploy", path, "--confirm", "--components=on-deploy-with-variable", "-l=trace") + stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "deploy", path, "--confirm", "--components=on-deploy-with-variable", "-l=trace") require.NoError(t, err, stdOut, stdErr) require.Contains(t, stdErr, "the dog says ruff") // Test using dynamic and multiple-variables - stdOut, stdErr, err = e2e.ExecZarfCommand("package", "deploy", path, "--confirm", "--components=on-deploy-with-dynamic-variable,on-deploy-with-multiple-variables", "-l=trace") + stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "deploy", path, "--confirm", "--components=on-deploy-with-dynamic-variable,on-deploy-with-multiple-variables", "-l=trace") require.NoError(t, err, stdOut, stdErr) require.Contains(t, stdErr, "the cat says meow") require.Contains(t, stdErr, "the dog says ruff") @@ -93,12 +93,12 @@ func TestComponentActions(t *testing.T) { require.Contains(t, stdErr, "with a TF_VAR, the snake also says hiss") // Test using environment variables - stdOut, stdErr, err = e2e.ExecZarfCommand("package", "deploy", path, "--confirm", "--components=on-deploy-with-env-var") + stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "deploy", path, "--confirm", "--components=on-deploy-with-env-var") require.NoError(t, err, stdOut, stdErr) require.FileExists(t, deployWithEnvVarArtifact) // Test using a templated file but without dynamic variables - stdOut, stdErr, err = e2e.ExecZarfCommand("package", "deploy", path, "--confirm", "--components=on-deploy-with-template-use-of-variable") + stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "deploy", path, "--confirm", "--components=on-deploy-with-template-use-of-variable") require.NoError(t, err, stdOut, stdErr) outTemplated, err := os.ReadFile("templated.txt") require.NoError(t, err) @@ -110,7 +110,7 @@ func TestComponentActions(t *testing.T) { e2e.CleanFiles("templated.txt") // Test using a templated file with dynamic variables - stdOut, stdErr, err = e2e.ExecZarfCommand("package", "deploy", path, "--confirm", "--components=on-deploy-with-template-use-of-variable,on-deploy-with-dynamic-variable,on-deploy-with-multiple-variables") + stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "deploy", path, "--confirm", "--components=on-deploy-with-template-use-of-variable,on-deploy-with-dynamic-variable,on-deploy-with-multiple-variables") require.NoError(t, err, stdOut, stdErr) outTemplated, err = os.ReadFile("templated.txt") require.NoError(t, err) diff --git a/src/test/e2e/03_temp_directory_deploy_test.go b/src/test/e2e/03_temp_directory_deploy_test.go index 7e9fd4fc5d..dbafb20996 100644 --- a/src/test/e2e/03_temp_directory_deploy_test.go +++ b/src/test/e2e/03_temp_directory_deploy_test.go @@ -32,7 +32,7 @@ func TestTempDirectoryDeploy(t *testing.T) { _ = os.Mkdir(otherTmpPath, 0750) - stdOut, stdErr, err := e2e.ExecZarfCommand("package", "deploy", path, "--confirm", "--tmpdir", otherTmpPath, "--log-level=debug") + stdOut, stdErr, _, err := e2e.ExecZarfCommand("package", "deploy", path, "--confirm", "--tmpdir", otherTmpPath, "--log-level=debug") require.Contains(t, stdErr, otherTmpPath, "The other tmp path should show as being created") require.NoError(t, err, stdOut, stdErr) diff --git a/src/test/e2e/04_create_templating_test.go b/src/test/e2e/04_create_templating_test.go index f70da2fdbc..61e1747ce8 100644 --- a/src/test/e2e/04_create_templating_test.go +++ b/src/test/e2e/04_create_templating_test.go @@ -28,15 +28,15 @@ func TestCreateTemplating(t *testing.T) { pkgName := fmt.Sprintf("zarf-package-variables-%s.tar.zst", e2e.Arch) // Test that not specifying a package variable results in an error - _, stdErr, _ := e2e.ExecZarfCommand("package", "create", "examples/variables", "--confirm", "--zarf-cache", cachePath) + _, stdErr, _, _ := e2e.ExecZarfCommand("package", "create", "examples/variables", "--confirm", "--zarf-cache", cachePath) expectedOutString := "variable 'NGINX_VERSION' must be '--set' when using the '--confirm' flag" require.Contains(t, stdErr, "", expectedOutString) // Test a simple package variable example with `--set` (will fail to pull an image if this is not set correctly) - stdOut, stdErr, err := e2e.ExecZarfCommand("package", "create", "examples/variables", "--set", "NGINX_VERSION=1.23.3", "--confirm", "--zarf-cache", cachePath) + stdOut, stdErr, _, err := e2e.ExecZarfCommand("package", "create", "examples/variables", "--set", "NGINX_VERSION=1.23.3", "--confirm", "--zarf-cache", cachePath) require.NoError(t, err, stdOut, stdErr) - stdOut, stdErr, err = e2e.ExecZarfCommand("t", "archiver", "decompress", pkgName, decompressPath, "--decompress-all", "-l=trace") + stdOut, stdErr, _, err = e2e.ExecZarfCommand("t", "archiver", "decompress", pkgName, decompressPath, "--decompress-all", "-l=trace") require.NoError(t, err, stdOut, stdErr) // Check that the constant in the zarf.yaml is replaced correctly diff --git a/src/test/e2e/05_multi_part_test.go b/src/test/e2e/05_multi_part_test.go index 661fe742af..a0e8c5d7f1 100644 --- a/src/test/e2e/05_multi_part_test.go +++ b/src/test/e2e/05_multi_part_test.go @@ -27,7 +27,7 @@ func TestMultiPartPackage(t *testing.T) { e2e.CleanFiles(deployPath, outputFile) // Create the package with a max size of 1MB - stdOut, stdErr, err := e2e.ExecZarfCommand("package", "create", createPath, "--confirm", "--max-package-size=1") + stdOut, stdErr, _, err := e2e.ExecZarfCommand("package", "create", createPath, "--confirm", "--max-package-size=1") require.NoError(t, err, stdOut, stdErr) list, err := filepath.Glob("zarf-package-multi-part-*") @@ -35,7 +35,7 @@ func TestMultiPartPackage(t *testing.T) { // Length is 7 because there are 6 parts and 1 manifest require.Len(t, list, 7) - stdOut, stdErr, err = e2e.ExecZarfCommand("package", "deploy", deployPath, "--confirm") + stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "deploy", deployPath, "--confirm") require.NoError(t, err, stdOut, stdErr) // Verify the package was deployed diff --git a/src/test/e2e/06_create_sbom_test.go b/src/test/e2e/06_create_sbom_test.go index d64d06c396..5d4f9be60c 100644 --- a/src/test/e2e/06_create_sbom_test.go +++ b/src/test/e2e/06_create_sbom_test.go @@ -22,7 +22,7 @@ func TestCreateSBOM(t *testing.T) { pkgName := fmt.Sprintf("zarf-package-dos-games-%s.tar.zst", e2e.Arch) - stdOut, stdErr, err := e2e.ExecZarfCommand("package", "create", "examples/dos-games", "--confirm", "--zarf-cache", cachePath, "--sbom-out", sbomPath) + stdOut, stdErr, _, err := e2e.ExecZarfCommand("package", "create", "examples/dos-games", "--confirm", "--zarf-cache", cachePath, "--sbom-out", sbomPath) require.NoError(t, err, stdOut, stdErr) require.Contains(t, stdErr, "Creating SBOMs for 1 images and 0 components with files.") // Test that the game package generates the SBOMs we expect (images only) @@ -36,7 +36,7 @@ func TestCreateSBOM(t *testing.T) { // Clean the SBOM path so it is force to be recreated e2e.CleanFiles(sbomPath) - stdOut, stdErr, err = e2e.ExecZarfCommand("package", "inspect", pkgName, "--sbom-out", sbomPath) + stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "inspect", pkgName, "--sbom-out", sbomPath) require.NoError(t, err, stdOut, stdErr) // Test that the game package generates the SBOMs we expect (images only) _, err = os.ReadFile(filepath.Join(sbomPath, "dos-games", "sbom-viewer-defenseunicorns_zarf-game_multi-tile-dark.html")) @@ -47,12 +47,12 @@ func TestCreateSBOM(t *testing.T) { require.NoError(t, err) // Pull the current zarf binary version to find the corresponding init package - version, stdErr, err := e2e.ExecZarfCommand("version") + version, stdErr, _, err := e2e.ExecZarfCommand("version") require.NoError(t, err, version, stdErr) initName := fmt.Sprintf("build/zarf-init-%s-%s.tar.zst", e2e.Arch, strings.TrimSpace(version)) - stdOut, stdErr, err = e2e.ExecZarfCommand("package", "inspect", initName, "--sbom-out", sbomPath) + stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "inspect", initName, "--sbom-out", sbomPath) require.NoError(t, err, stdOut, stdErr) // Test that we preserve the filepath _, err = os.ReadFile(filepath.Join(sbomPath, "dos-games", "sbom-viewer-defenseunicorns_zarf-game_multi-tile-dark.html")) diff --git a/src/test/e2e/07_create_git_test.go b/src/test/e2e/07_create_git_test.go index 16a0c08948..36f66b8199 100644 --- a/src/test/e2e/07_create_git_test.go +++ b/src/test/e2e/07_create_git_test.go @@ -22,13 +22,13 @@ func TestCreateGit(t *testing.T) { // Extract the test package. path := fmt.Sprintf("build/zarf-package-git-data-%s-v1.0.0.tar.zst", e2e.Arch) - stdOut, stdErr, err := e2e.ExecZarfCommand("tools", "archiver", "decompress", path, extractDir, "--decompress-all") + stdOut, stdErr, _, err := e2e.ExecZarfCommand("tools", "archiver", "decompress", path, extractDir, "--decompress-all") require.NoError(t, err, stdOut, stdErr) defer e2e.CleanFiles(extractDir) // Verify the full-repo component. gitDirFlag := fmt.Sprintf("--git-dir=%s/components/full-repo/repos/nocode-953829860/.git", extractDir) - stdOut, stdErr, err = exec.Cmd("git", gitDirFlag, "log", "--oneline", "--decorate") + stdOut, stdErr, _, err = exec.Cmd("git", gitDirFlag, "log", "--oneline", "--decorate") require.NoError(t, err, stdOut, stdErr) require.Contains(t, stdOut, "c46f06e add no code") require.Contains(t, stdOut, "(tag: 1.0.0)") @@ -36,40 +36,40 @@ func TestCreateGit(t *testing.T) { // Verify a repo with a shorthand tag. gitDirFlag = fmt.Sprintf("--git-dir=%s/components/specific-tag/repos/zarf-4023393304/.git", extractDir) - stdOut, stdErr, err = exec.Cmd("git", gitDirFlag, "log", "HEAD^..HEAD", "--oneline", "--decorate") + stdOut, stdErr, _, err = exec.Cmd("git", gitDirFlag, "log", "HEAD^..HEAD", "--oneline", "--decorate") require.NoError(t, err, stdOut, stdErr) require.Contains(t, stdOut, "(HEAD -> zarf-ref-v0.15.0, tag: v0.15.0) Normalize --confirm behavior in the CLI (#297)") // Verify a repo with a shorthand tag only has one tag. - stdOut, stdErr, err = exec.Cmd("git", gitDirFlag, "tag") + stdOut, stdErr, _, err = exec.Cmd("git", gitDirFlag, "tag") require.NoError(t, err, stdOut, stdErr) require.Equal(t, "v0.15.0\n", stdOut) // Verify a repo with a full git refspec tag. gitDirFlag = fmt.Sprintf("--git-dir=%s/components/specific-tag/repos/zarf-2175050463/.git", extractDir) - stdOut, stdErr, err = exec.Cmd("git", gitDirFlag, "log", "HEAD^..HEAD", "--oneline", "--decorate") + stdOut, stdErr, _, err = exec.Cmd("git", gitDirFlag, "log", "HEAD^..HEAD", "--oneline", "--decorate") require.NoError(t, err, stdOut, stdErr) require.Contains(t, stdOut, "(HEAD -> zarf-ref-v0.16.0, tag: v0.16.0) slightly re-arrange zarf arch diagram layout (#383)") // Verify a repo with a full git refspec tag only has one tag. - stdOut, stdErr, err = exec.Cmd("git", gitDirFlag, "tag") + stdOut, stdErr, _, err = exec.Cmd("git", gitDirFlag, "tag") require.NoError(t, err, stdOut, stdErr) require.Equal(t, "v0.16.0\n", stdOut) // Verify a repo with a branch. gitDirFlag = fmt.Sprintf("--git-dir=%s/components/specific-branch/repos/big-bang-2705706079/.git", extractDir) - stdOut, stdErr, err = exec.Cmd("git", gitDirFlag, "log", "HEAD^..HEAD", "--oneline", "--decorate") + stdOut, stdErr, _, err = exec.Cmd("git", gitDirFlag, "log", "HEAD^..HEAD", "--oneline", "--decorate") require.NoError(t, err, stdOut, stdErr) require.Contains(t, stdOut, "(HEAD -> release-1.54.x, tag: 1.54.0-rc.0, tag: 1.54.0, online-upstream/release-1.54.x)") // Verify a repo with a branch only has one branch. - stdOut, stdErr, err = exec.Cmd("git", gitDirFlag, "branch") + stdOut, stdErr, _, err = exec.Cmd("git", gitDirFlag, "branch") require.NoError(t, err, stdOut, stdErr) require.Equal(t, "* release-1.54.x\n", stdOut) // Verify a repo with a commit hash. gitDirFlag = fmt.Sprintf("--git-dir=%s/components/specific-hash/repos/zarf-1356873667/.git", extractDir) - stdOut, stdErr, err = exec.Cmd("git", gitDirFlag, "log", "HEAD^..HEAD", "--oneline", "--decorate") + stdOut, stdErr, _, err = exec.Cmd("git", gitDirFlag, "log", "HEAD^..HEAD", "--oneline", "--decorate") require.NoError(t, err, stdOut, stdErr) require.Contains(t, stdOut, "(HEAD -> zarf-ref-c74e2e9626da0400e0a41e78319b3054c53a5d4e, tag: v0.21.3) Re-add docker buildx for release pipeilne") } diff --git a/src/test/e2e/20_zarf_init_test.go b/src/test/e2e/20_zarf_init_test.go index f4558e6c1a..4d92544bdb 100644 --- a/src/test/e2e/20_zarf_init_test.go +++ b/src/test/e2e/20_zarf_init_test.go @@ -35,48 +35,48 @@ func TestZarfInit(t *testing.T) { ) // Build init package with different arch than the cluster arch. - stdOut, stdErr, err := e2e.ExecZarfCommand("package", "create", ".", "--architecture", mismatchedArch, "--confirm") + stdOut, stdErr, _, err := e2e.ExecZarfCommand("package", "create", ".", "--architecture", mismatchedArch, "--confirm") require.NoError(t, err, stdOut, stdErr) defer e2e.CleanFiles(mismatchedInitPackage) // Check that `zarf init` fails in appliance mode when we try to initialize a k3s cluster // on a machine with a different architecture than the package architecture. // We need to use the --architecture flag here to force zarf to find the package. - _, stdErr, err = e2e.ExecZarfCommand("init", "--architecture", mismatchedArch, "--components=k3s", "--confirm") + _, stdErr, _, err = e2e.ExecZarfCommand("init", "--architecture", mismatchedArch, "--components=k3s", "--confirm") require.Error(t, err, stdErr) // run `zarf init` - _, stdErr, err = exec.CmdWithContext(ctx, exec.PrintCfg(), e2e.ZarfBinPath, "init", "--components="+initComponents, "--confirm", "--nodeport", "31337") + _, stdErr, _, err = exec.CmdWithContext(ctx, exec.PrintCfg(), e2e.ZarfBinPath, "init", "--components="+initComponents, "--confirm", "--nodeport", "31337") require.Contains(t, stdErr, "artifacts with software bill-of-materials (SBOM) included") require.NoError(t, err) // Check that gitea is actually running and healthy - stdOut, _, err = e2e.ExecZarfCommand("tools", "kubectl", "get", "pods", "-l", "app in (gitea)", "-n", "zarf", "-o", "jsonpath={.items[*].status.phase}") + stdOut, _, _, err = e2e.ExecZarfCommand("tools", "kubectl", "get", "pods", "-l", "app in (gitea)", "-n", "zarf", "-o", "jsonpath={.items[*].status.phase}") require.NoError(t, err) require.Contains(t, stdOut, "Running") // Check that the logging stack is actually running and healthy - stdOut, _, err = e2e.ExecZarfCommand("tools", "kubectl", "get", "pods", "-l", "app in (loki)", "-n", "zarf", "-o", "jsonpath={.items[*].status.phase}") + stdOut, _, _, err = e2e.ExecZarfCommand("tools", "kubectl", "get", "pods", "-l", "app in (loki)", "-n", "zarf", "-o", "jsonpath={.items[*].status.phase}") require.NoError(t, err) require.Contains(t, stdOut, "Running") - stdOut, _, err = e2e.ExecZarfCommand("tools", "kubectl", "get", "pods", "-l", "app.kubernetes.io/name in (grafana)", "-n", "zarf", "-o", "jsonpath={.items[*].status.phase}") + stdOut, _, _, err = e2e.ExecZarfCommand("tools", "kubectl", "get", "pods", "-l", "app.kubernetes.io/name in (grafana)", "-n", "zarf", "-o", "jsonpath={.items[*].status.phase}") require.NoError(t, err) require.Contains(t, stdOut, "Running") - stdOut, _, err = e2e.ExecZarfCommand("tools", "kubectl", "get", "pods", "-l", "app.kubernetes.io/name in (promtail)", "-n", "zarf", "-o", "jsonpath={.items[*].status.phase}") + stdOut, _, _, err = e2e.ExecZarfCommand("tools", "kubectl", "get", "pods", "-l", "app.kubernetes.io/name in (promtail)", "-n", "zarf", "-o", "jsonpath={.items[*].status.phase}") require.NoError(t, err) require.Contains(t, stdOut, "Running") // Check that the registry is running on the correct NodePort - stdOut, _, err = e2e.ExecZarfCommand("tools", "kubectl", "get", "service", "-n", "zarf", "zarf-docker-registry", "-o=jsonpath='{.spec.ports[*].nodePort}'") + stdOut, _, _, err = e2e.ExecZarfCommand("tools", "kubectl", "get", "service", "-n", "zarf", "zarf-docker-registry", "-o=jsonpath='{.spec.ports[*].nodePort}'") require.NoError(t, err) require.Contains(t, stdOut, "31337") // Check that the registry is running with the correct scale down policy - stdOut, _, err = e2e.ExecZarfCommand("tools", "kubectl", "get", "hpa", "-n", "zarf", "zarf-docker-registry", "-o=jsonpath='{.spec.behavior.scaleDown.selectPolicy}'") + stdOut, _, _, err = e2e.ExecZarfCommand("tools", "kubectl", "get", "hpa", "-n", "zarf", "zarf-docker-registry", "-o=jsonpath='{.spec.behavior.scaleDown.selectPolicy}'") require.NoError(t, err) require.Contains(t, stdOut, "Min") // Special sizing-hacking for reducing resources where Kind + CI eats a lot of free cycles (ignore errors) - _, _, _ = e2e.ExecZarfCommand("tools", "kubectl", "scale", "deploy", "-n", "kube-system", "coredns", "--replicas=1") - _, _, _ = e2e.ExecZarfCommand("tools", "kubectl", "scale", "deploy", "-n", "zarf", "agent-hook", "--replicas=1") + _, _, _, _ = e2e.ExecZarfCommand("tools", "kubectl", "scale", "deploy", "-n", "kube-system", "coredns", "--replicas=1") + _, _, _, _ = e2e.ExecZarfCommand("tools", "kubectl", "scale", "deploy", "-n", "zarf", "agent-hook", "--replicas=1") } diff --git a/src/test/e2e/21_connect_test.go b/src/test/e2e/21_connect_test.go index 74e7d5f73e..6dab1718e4 100644 --- a/src/test/e2e/21_connect_test.go +++ b/src/test/e2e/21_connect_test.go @@ -24,7 +24,7 @@ func TestConnect(t *testing.T) { defer e2e.Teardown(t) // Make the Registry contains the images we expect - stdOut, stdErr, err := e2e.ExecZarfCommand("tools", "registry", "catalog") + stdOut, stdErr, _, err := e2e.ExecZarfCommand("tools", "registry", "catalog") assert.NoError(t, err, stdOut, stdErr) registryList := strings.Split(strings.Trim(stdOut, "\n "), "\n") @@ -55,6 +55,6 @@ func TestConnect(t *testing.T) { assert.NoError(t, err) assert.Equal(t, 200, respLog.StatusCode) - stdOut, stdErr, err = e2e.ExecZarfCommand("package", "remove", "init", "--components=logging", "--confirm") + stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "remove", "init", "--components=logging", "--confirm") require.NoError(t, err, stdOut, stdErr) } diff --git a/src/test/e2e/22_git_and_flux_test.go b/src/test/e2e/22_git_and_flux_test.go index 89fc9223cb..25fdfb7f0a 100644 --- a/src/test/e2e/22_git_and_flux_test.go +++ b/src/test/e2e/22_git_and_flux_test.go @@ -25,7 +25,7 @@ func TestGitAndFlux(t *testing.T) { path := fmt.Sprintf("build/zarf-package-git-data-%s-v1.0.0.tar.zst", e2e.Arch) // Deploy the gitops example - stdOut, stdErr, err := e2e.ExecZarfCommand("package", "deploy", path, "--confirm") + stdOut, stdErr, _, err := e2e.ExecZarfCommand("package", "deploy", path, "--confirm") require.NoError(t, err, stdOut, stdErr) tunnel, err := cluster.NewZarfTunnel() @@ -38,10 +38,10 @@ func TestGitAndFlux(t *testing.T) { testGitServerTagAndHash(t, tunnel.HTTPEndpoint()) waitFluxPodInfoDeployment(t) - stdOut, stdErr, err = e2e.ExecZarfCommand("package", "remove", "flux-test", "--confirm") + stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "remove", "flux-test", "--confirm") require.NoError(t, err, stdOut, stdErr) - stdOut, stdErr, err = e2e.ExecZarfCommand("package", "remove", "init", "--components=git-server", "--confirm") + stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "remove", "init", "--components=git-server", "--confirm") require.NoError(t, err, stdOut, stdErr) } @@ -104,9 +104,9 @@ func testGitServerTagAndHash(t *testing.T, gitURL string) { func waitFluxPodInfoDeployment(t *testing.T) { // Deploy the flux example and verify that it works path := fmt.Sprintf("build/zarf-package-flux-test-%s.tar.zst", e2e.Arch) - stdOut, stdErr, err := e2e.ExecZarfCommand("package", "deploy", path, "--confirm") + stdOut, stdErr, _, err := e2e.ExecZarfCommand("package", "deploy", path, "--confirm") require.NoError(t, err, stdOut, stdErr) - kubectlOut, _, _ := e2e.ExecZarfCommand("tools", "kubectl", "-n=podinfo", "rollout", "status", "deployment/podinfo") + kubectlOut, _, _, _ := e2e.ExecZarfCommand("tools", "kubectl", "-n=podinfo", "rollout", "status", "deployment/podinfo") assert.Contains(t, string(kubectlOut), "successfully rolled out") } diff --git a/src/test/e2e/23_data_injection_test.go b/src/test/e2e/23_data_injection_test.go index 740d8d0fdb..70e810068e 100644 --- a/src/test/e2e/23_data_injection_test.go +++ b/src/test/e2e/23_data_injection_test.go @@ -28,12 +28,12 @@ func TestDataInjection(t *testing.T) { } // Verify the file and injection marker were created - stdOut, stdErr, err := exec.CmdWithContext(context.TODO(), exec.PrintCfg(), "kubectl", "--namespace=demo", "logs", "--tail=5", "--selector=app=data-injection", "-c=data-injection") + stdOut, stdErr, _, err := exec.CmdWithContext(context.TODO(), exec.PrintCfg(), "kubectl", "--namespace=demo", "logs", "--tail=5", "--selector=app=data-injection", "-c=data-injection") require.NoError(t, err, stdOut, stdErr) assert.Contains(t, stdOut, "this-is-an-example-file.txt") assert.Contains(t, stdOut, ".zarf-injection-") - stdOut, stdErr, err = e2e.ExecZarfCommand("package", "remove", "data-injection-demo", "--confirm") + stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "remove", "data-injection-demo", "--confirm") require.NoError(t, err, stdOut, stdErr) } @@ -43,6 +43,6 @@ func runDataInjection(t *testing.T, path string) { defer cancel() // Deploy the data injection example - stdOut, stdErr, err := exec.CmdWithContext(ctx, exec.PrintCfg(), e2e.ZarfBinPath, "package", "deploy", path, "--confirm") + stdOut, stdErr, _, err := exec.CmdWithContext(ctx, exec.PrintCfg(), e2e.ZarfBinPath, "package", "deploy", path, "--confirm") require.NoError(t, err, stdOut, stdErr) } diff --git a/src/test/e2e/24_variables_test.go b/src/test/e2e/24_variables_test.go index 686a083a8c..c94fbd57a9 100644 --- a/src/test/e2e/24_variables_test.go +++ b/src/test/e2e/24_variables_test.go @@ -24,12 +24,12 @@ func TestVariables(t *testing.T) { e2e.CleanFiles(tfPath) // Test that not specifying a prompted variable results in an error - _, stdErr, _ := e2e.ExecZarfCommand("package", "deploy", path, "--confirm") + _, stdErr, _, _ := e2e.ExecZarfCommand("package", "deploy", path, "--confirm") expectedOutString := "variable 'SITE_NAME' must be '--set' when using the '--confirm' flag" require.Contains(t, stdErr, "", expectedOutString) // Deploy nginx - stdOut, stdErr, err := e2e.ExecZarfCommand("package", "deploy", path, "--confirm", "--set", "SITE_NAME=Lula Web", "--set", "AWS_REGION=unicorn-land", "-l", "trace") + stdOut, stdErr, _, err := e2e.ExecZarfCommand("package", "deploy", path, "--confirm", "--set", "SITE_NAME=Lula Web", "--set", "AWS_REGION=unicorn-land", "-l", "trace") require.NoError(t, err, stdOut, stdErr) // Verify that unicorn-land was not included in the log require.NotContains(t, stdErr, "unicorn-land") @@ -40,7 +40,7 @@ func TestVariables(t *testing.T) { require.Contains(t, string(outputTF), "unicorn-land") // Verify the configmap was properly templated - kubectlOut, _, _ := e2e.ExecZarfCommand("tools", "kubectl", "-n", "nginx", "get", "configmap", "nginx-configmap", "-o", "jsonpath='{.data.index\\.html}' ") + kubectlOut, _, _, _ := e2e.ExecZarfCommand("tools", "kubectl", "-n", "nginx", "get", "configmap", "nginx-configmap", "-o", "jsonpath='{.data.index\\.html}' ") // OPTIONAL_FOOTER should remain unset because it was not set during deploy assert.Contains(t, string(kubectlOut), "\n \n ") // STYLE should take the default value @@ -53,11 +53,11 @@ func TestVariables(t *testing.T) { assert.Contains(t, string(kubectlOut), "unicorn-land") // Verify that the nginx deployment was successful (the NGINX_VERSION constant templated the image correctly) - kubectlOut, _, err = e2e.ExecZarfCommand("tools", "kubectl", "get", "pods", "-l", "app in (nginx)", "-n", "nginx", "-o", "jsonpath={.items[*].status.phase}") + kubectlOut, _, _, err = e2e.ExecZarfCommand("tools", "kubectl", "get", "pods", "-l", "app in (nginx)", "-n", "nginx", "-o", "jsonpath={.items[*].status.phase}") require.NoError(t, err) require.Contains(t, kubectlOut, "Running") - stdOut, stdErr, err = e2e.ExecZarfCommand("package", "remove", path, "--confirm") + stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "remove", path, "--confirm") require.NoError(t, err, stdOut, stdErr) e2e.CleanFiles(tfPath) diff --git a/src/test/e2e/25_helm_test.go b/src/test/e2e/25_helm_test.go index e5a49c14df..ac10ff8dba 100644 --- a/src/test/e2e/25_helm_test.go +++ b/src/test/e2e/25_helm_test.go @@ -37,7 +37,7 @@ func testHelmReleaseName(t *testing.T) { path := fmt.Sprintf("build/zarf-package-test-helm-releasename-%s.tar.zst", e2e.Arch) // Deploy the package. - stdOut, stdErr, err := e2e.ExecZarfCommand("package", "deploy", path, "--confirm") + stdOut, stdErr, _, err := e2e.ExecZarfCommand("package", "deploy", path, "--confirm") require.NoError(t, err, stdOut, stdErr) // Verify multiple helm installs of different release names were deployed. @@ -45,7 +45,7 @@ func testHelmReleaseName(t *testing.T) { assert.Contains(t, string(kubectlOut), "cool-name-podinfo") // Remove the package. - stdOut, stdErr, err = e2e.ExecZarfCommand("package", "remove", "test-helm-releasename", "--confirm") + stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "remove", "test-helm-releasename", "--confirm") require.NoError(t, err, stdOut, stdErr) } @@ -55,15 +55,15 @@ func testHelmLocalChart(t *testing.T) { path := fmt.Sprintf("build/zarf-package-test-helm-local-chart-%s.tar.zst", e2e.Arch) // Deploy the package. - stdOut, stdErr, err := e2e.ExecZarfCommand("package", "deploy", path, "--confirm") + stdOut, stdErr, _, err := e2e.ExecZarfCommand("package", "deploy", path, "--confirm") require.NoError(t, err, stdOut, stdErr) // Verify that nginx successfully deploys in the cluster - kubectlOut, _, _ := e2e.ExecZarfCommand("tools", "kubectl", "-n=local-chart", "rollout", "status", "deployment/local-demo") + kubectlOut, _, _, _ := e2e.ExecZarfCommand("tools", "kubectl", "-n=local-chart", "rollout", "status", "deployment/local-demo") assert.Contains(t, string(kubectlOut), "successfully rolled out") // Remove the package. - stdOut, stdErr, err = e2e.ExecZarfCommand("package", "remove", "test-helm-local-chart", "--confirm") + stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "remove", "test-helm-local-chart", "--confirm") require.NoError(t, err, stdOut, stdErr) } @@ -71,13 +71,13 @@ func testHelmEscaping(t *testing.T) { t.Log("E2E: Helm chart escaping") // Create the package. - stdOut, stdErr, err := e2e.ExecZarfCommand("package", "create", "src/test/test-packages/25-evil-templates/", "--confirm") + stdOut, stdErr, _, err := e2e.ExecZarfCommand("package", "create", "src/test/test-packages/25-evil-templates/", "--confirm") require.NoError(t, err, stdOut, stdErr) path := fmt.Sprintf("zarf-package-evil-templates-%s.tar.zst", e2e.Arch) // Deploy the package. - stdOut, stdErr, err = e2e.ExecZarfCommand("package", "deploy", path, "--confirm") + stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "deploy", path, "--confirm") require.NoError(t, err, stdOut, stdErr) // Verify the configmap was deployed and escaped. @@ -88,7 +88,7 @@ func testHelmEscaping(t *testing.T) { assert.Contains(t, string(kubectlOut), `description: Pod {{$labels.pod}} in {{$labels.namespace}} got OOMKilled`) // Remove the package. - stdOut, stdErr, err = e2e.ExecZarfCommand("package", "remove", "evil-templates", "--confirm") + stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "remove", "evil-templates", "--confirm") require.NoError(t, err, stdOut, stdErr) } @@ -98,17 +98,17 @@ func testHelmOCIChart(t *testing.T) { path := fmt.Sprintf("build/zarf-package-helm-oci-chart-%s-0.0.1.tar.zst", e2e.Arch) // Deploy the package. - stdOut, stdErr, err := e2e.ExecZarfCommand("package", "deploy", path, "--confirm") + stdOut, stdErr, _, err := e2e.ExecZarfCommand("package", "deploy", path, "--confirm") require.NoError(t, err, stdOut, stdErr) // Verify that podinfo successfully deploys in the cluster - kubectlOut, _, _ := e2e.ExecZarfCommand("tools", "kubectl", "-n=helm-oci-demo", "rollout", "status", "deployment/podinfo") + kubectlOut, _, _, _ := e2e.ExecZarfCommand("tools", "kubectl", "-n=helm-oci-demo", "rollout", "status", "deployment/podinfo") assert.Contains(t, string(kubectlOut), "successfully rolled out") - kubectlOut, _, _ = e2e.ExecZarfCommand("tools", "kubectl", "-n=helm-oci-demo", "get", "deployment", "podinfo", "-o=jsonpath={.metadata.labels}") + kubectlOut, _, _, _ = e2e.ExecZarfCommand("tools", "kubectl", "-n=helm-oci-demo", "get", "deployment", "podinfo", "-o=jsonpath={.metadata.labels}") assert.Contains(t, string(kubectlOut), "6.3.3") // Remove the package. - stdOut, stdErr, err = e2e.ExecZarfCommand("package", "remove", "helm-oci-chart", "--confirm") + stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "remove", "helm-oci-chart", "--confirm") require.NoError(t, err, stdOut, stdErr) } @@ -119,11 +119,11 @@ func testHelmUninstallRollback(t *testing.T) { evilPath := fmt.Sprintf("zarf-package-dos-games-%s.tar.zst", e2e.Arch) // Create the evil package (with the bad configmap). - stdOut, stdErr, err := e2e.ExecZarfCommand("package", "create", "src/test/test-packages/25-evil-dos-games/", "--confirm") + stdOut, stdErr, _, err := e2e.ExecZarfCommand("package", "create", "src/test/test-packages/25-evil-dos-games/", "--confirm") require.NoError(t, err, stdOut, stdErr) // Deploy the evil package. - stdOut, stdErr, err = e2e.ExecZarfCommand("package", "deploy", evilPath, "--confirm") + stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "deploy", evilPath, "--confirm") require.Error(t, err, stdOut, stdErr) // Ensure that this does not leave behind a dos-games chart @@ -132,7 +132,7 @@ func testHelmUninstallRollback(t *testing.T) { assert.NotContains(t, string(helmOut), "zarf-f53a99d4a4dd9a3575bedf59cd42d48d751ae866") // Deploy the good package. - stdOut, stdErr, err = e2e.ExecZarfCommand("package", "deploy", goodPath, "--confirm") + stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "deploy", goodPath, "--confirm") require.NoError(t, err, stdOut, stdErr) // Ensure that this does create a dos-games chart @@ -141,7 +141,7 @@ func testHelmUninstallRollback(t *testing.T) { assert.Contains(t, string(helmOut), "zarf-f53a99d4a4dd9a3575bedf59cd42d48d751ae866") // Deploy the evil package. - stdOut, stdErr, err = e2e.ExecZarfCommand("package", "deploy", evilPath, "--confirm") + stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "deploy", evilPath, "--confirm") require.Error(t, err, stdOut, stdErr) // Ensure that the dos-games chart was not uninstalled @@ -150,7 +150,7 @@ func testHelmUninstallRollback(t *testing.T) { assert.Contains(t, string(helmOut), "zarf-f53a99d4a4dd9a3575bedf59cd42d48d751ae866") // Remove the package. - stdOut, stdErr, err = e2e.ExecZarfCommand("package", "remove", "dos-games", "--confirm") + stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "remove", "dos-games", "--confirm") require.NoError(t, err, stdOut, stdErr) } @@ -161,11 +161,11 @@ func testHelmAdoption(t *testing.T) { deploymentManifest := "src/test/test-packages/25-manifest-adoption/deployment.yaml" // Deploy dos-games manually into the cluster without Zarf - kubectlOut, _, _ := e2e.ExecZarfCommand("tools", "kubectl", "apply", "-f", deploymentManifest) + kubectlOut, _, _, _ := e2e.ExecZarfCommand("tools", "kubectl", "apply", "-f", deploymentManifest) assert.Contains(t, string(kubectlOut), "deployment.apps/game created") // Deploy dos-games into the cluster with Zarf - stdOut, stdErr, err := e2e.ExecZarfCommand("package", "deploy", packagePath, "--confirm", "--adopt-existing-resources") + stdOut, stdErr, _, err := e2e.ExecZarfCommand("package", "deploy", packagePath, "--confirm", "--adopt-existing-resources") require.NoError(t, err, stdOut, stdErr) // Ensure that this does create a dos-games chart @@ -174,6 +174,6 @@ func testHelmAdoption(t *testing.T) { assert.Contains(t, string(helmOut), "zarf-f53a99d4a4dd9a3575bedf59cd42d48d751ae866") // Remove the package. - stdOut, stdErr, err = e2e.ExecZarfCommand("package", "remove", "dos-games", "--confirm") + stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "remove", "dos-games", "--confirm") require.NoError(t, err, stdOut, stdErr) } diff --git a/src/test/e2e/26_simple_packages_test.go b/src/test/e2e/26_simple_packages_test.go index 063d93b514..651ade182b 100644 --- a/src/test/e2e/26_simple_packages_test.go +++ b/src/test/e2e/26_simple_packages_test.go @@ -22,7 +22,7 @@ func TestDosGames(t *testing.T) { path := fmt.Sprintf("build/zarf-package-dos-games-%s.tar.zst", e2e.Arch) // Deploy the game - stdOut, stdErr, err := e2e.ExecZarfCommand("package", "deploy", path, "--confirm") + stdOut, stdErr, _, err := e2e.ExecZarfCommand("package", "deploy", path, "--confirm") require.NoError(t, err, stdOut, stdErr) tunnel, err := cluster.NewZarfTunnel() @@ -35,7 +35,7 @@ func TestDosGames(t *testing.T) { assert.NoError(t, err, resp) assert.Equal(t, 200, resp.StatusCode) - stdOut, stdErr, err = e2e.ExecZarfCommand("package", "remove", "dos-games", "--confirm") + stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "remove", "dos-games", "--confirm") require.NoError(t, err, stdOut, stdErr) } @@ -47,10 +47,10 @@ func TestRemoteManifests(t *testing.T) { path := fmt.Sprintf("build/zarf-package-remote-manifests-%s-0.0.1.tar.zst", e2e.Arch) // Deploy the package - stdOut, stdErr, err := e2e.ExecZarfCommand("package", "deploy", path, "--confirm") + stdOut, stdErr, _, err := e2e.ExecZarfCommand("package", "deploy", path, "--confirm") require.NoError(t, err, stdOut, stdErr) // Remove the package - stdOut, stdErr, err = e2e.ExecZarfCommand("package", "remove", "remote-manifests", "--confirm") + stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "remove", "remote-manifests", "--confirm") require.NoError(t, err, stdOut, stdErr) } diff --git a/src/test/e2e/27_cosign_deploy_test.go b/src/test/e2e/27_cosign_deploy_test.go index 086ac57329..8aaf6b06a1 100644 --- a/src/test/e2e/27_cosign_deploy_test.go +++ b/src/test/e2e/27_cosign_deploy_test.go @@ -21,9 +21,9 @@ func TestCosignDeploy(t *testing.T) { // Test with command from https://zarf.dev/install/ command := fmt.Sprintf("%s package deploy sget://defenseunicorns/zarf-hello-world:$(uname -m) --confirm", e2e.ZarfBinPath) - stdOut, stdErr, err := exec.CmdWithContext(context.TODO(), exec.PrintCfg(), "sh", "-c", command) + stdOut, stdErr, _, err := exec.CmdWithContext(context.TODO(), exec.PrintCfg(), "sh", "-c", command) require.NoError(t, err, stdOut, stdErr) - stdOut, stdErr, err = e2e.ExecZarfCommand("package", "remove", "dos-games", "--confirm") + stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "remove", "dos-games", "--confirm") require.NoError(t, err, stdOut, stdErr) } diff --git a/src/test/e2e/28_wait_test.go b/src/test/e2e/28_wait_test.go index ef9aee3ed1..f1e6714ca9 100644 --- a/src/test/e2e/28_wait_test.go +++ b/src/test/e2e/28_wait_test.go @@ -25,7 +25,7 @@ type zarfCommandResult struct { } func zarfCommandWStruct(e2e test.ZarfE2ETest, path string) (result zarfCommandResult) { - result.stdOut, result.stdErr, result.err = e2e.ExecZarfCommand("package", "deploy", path, "--confirm") + result.stdOut, result.stdErr, _, result.err = e2e.ExecZarfCommand("package", "deploy", path, "--confirm") return result } @@ -62,6 +62,6 @@ func TestWait(t *testing.T) { } require.NoError(t, err, stdOut, stdErr) - stdOut, stdErr, err = e2e.ExecZarfCommand("package", "remove", "test-helm-wait", "--confirm") + stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "remove", "test-helm-wait", "--confirm") require.NoError(t, err, stdOut, stdErr) } diff --git a/src/test/e2e/29_mismatched_architectures_test.go b/src/test/e2e/29_mismatched_architectures_test.go index d01291dd4b..fda444f93a 100644 --- a/src/test/e2e/29_mismatched_architectures_test.go +++ b/src/test/e2e/29_mismatched_architectures_test.go @@ -27,23 +27,23 @@ func TestMismatchedArchitectures(t *testing.T) { ) // Build init package with different arch than the cluster arch. - stdOut, stdErr, err := e2e.ExecZarfCommand("package", "create", ".", "--architecture", mismatchedArch, "--confirm") + stdOut, stdErr, _, err := e2e.ExecZarfCommand("package", "create", ".", "--architecture", mismatchedArch, "--confirm") require.NoError(t, err, stdOut, stdErr) defer e2e.CleanFiles(mismatchedInitPackage) // Build dos-games package with different arch than the cluster arch. - stdOut, stdErr, err = e2e.ExecZarfCommand("package", "create", "examples/dos-games/", "--architecture", mismatchedArch, "--confirm") + stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "create", "examples/dos-games/", "--architecture", mismatchedArch, "--confirm") require.NoError(t, err, stdOut, stdErr) defer e2e.CleanFiles(mismatchedGamesPackage) // Ensure zarf init returns an error because of the mismatched architectures. // We need to use the --architecture flag here to force zarf to find the package. - _, stdErr, err = e2e.ExecZarfCommand("init", "--architecture", mismatchedArch, "--confirm") + _, stdErr, _, err = e2e.ExecZarfCommand("init", "--architecture", mismatchedArch, "--confirm") require.Error(t, err, stdErr) require.Contains(t, stdErr, expectedErrorMessage) // Ensure zarf package deploy returns an error because of the mismatched architectures. - _, stdErr, err = e2e.ExecZarfCommand("package", "deploy", mismatchedGamesPackage, "--confirm") + _, stdErr, _, err = e2e.ExecZarfCommand("package", "deploy", mismatchedGamesPackage, "--confirm") require.Error(t, err, stdErr) require.Contains(t, stdErr, expectedErrorMessage) } diff --git a/src/test/e2e/30_config_file_test.go b/src/test/e2e/30_config_file_test.go index beef3aff5d..f58decdf75 100644 --- a/src/test/e2e/30_config_file_test.go +++ b/src/test/e2e/30_config_file_test.go @@ -33,26 +33,26 @@ func TestConfigFile(t *testing.T) { configFileDefaultTests(t) - stdOut, stdErr, err := e2e.ExecZarfCommand("package", "remove", path, "--confirm") + stdOut, stdErr, _, err := e2e.ExecZarfCommand("package", "remove", path, "--confirm") require.NoError(t, err, stdOut, stdErr) e2e.CleanFiles(path) } func configFileTests(t *testing.T, dir, path string) { - _, stdErr, err := e2e.ExecZarfCommand("package", "create", dir, "--confirm") + _, stdErr, _, err := e2e.ExecZarfCommand("package", "create", dir, "--confirm") require.NoError(t, err) require.Contains(t, string(stdErr), "This is a zebra and they have stripes") require.Contains(t, string(stdErr), "This is a leopard and they have spots") - _, stdErr, err = e2e.ExecZarfCommand("package", "deploy", path, "--confirm") + _, stdErr, _, err = e2e.ExecZarfCommand("package", "deploy", path, "--confirm") require.NoError(t, err) require.Contains(t, string(stdErr), "📦 LION COMPONENT") require.NotContains(t, string(stdErr), "📦 LEOPARD COMPONENT") require.NotContains(t, string(stdErr), "📦 ZEBRA COMPONENT") // Verify the configmap was properly templated - kubectlOut, _, err := e2e.ExecZarfCommand("tools", "kubectl", "-n", "zarf", "get", "configmap", "simple-configmap", "-o", "jsonpath='{.data.templateme\\.properties}'") + kubectlOut, _, _, err := e2e.ExecZarfCommand("tools", "kubectl", "-n", "zarf", "get", "configmap", "simple-configmap", "-o", "jsonpath='{.data.templateme\\.properties}'") require.NoError(t, err) require.Contains(t, string(kubectlOut), "scorpion=iridescent") require.Contains(t, string(kubectlOut), "camel_spider=matte") @@ -105,25 +105,25 @@ func configFileDefaultTests(t *testing.T) { os.Setenv("ZARF_CONFIG", filepath.Join("src", "test", "zarf-config-test.toml")) // Test global flags - stdOut, _, _ := e2e.ExecZarfCommand("--help") + stdOut, _, _, _ := e2e.ExecZarfCommand("--help") for _, test := range globalFlags { require.Contains(t, string(stdOut), test) } // Test init flags - stdOut, _, _ = e2e.ExecZarfCommand("init", "--help") + stdOut, _, _, _ = e2e.ExecZarfCommand("init", "--help") for _, test := range initFlags { require.Contains(t, string(stdOut), test) } // Test package create flags - stdOut, _, _ = e2e.ExecZarfCommand("package", "create", "--help") + stdOut, _, _, _ = e2e.ExecZarfCommand("package", "create", "--help") for _, test := range packageCreateFlags { require.Contains(t, string(stdOut), test) } // Test package deploy flags - stdOut, _, _ = e2e.ExecZarfCommand("package", "deploy", "--help") + stdOut, _, _, _ = e2e.ExecZarfCommand("package", "deploy", "--help") for _, test := range packageDeployFlags { require.Contains(t, string(stdOut), test) } diff --git a/src/test/e2e/31_component_action_remove_test.go b/src/test/e2e/31_component_action_remove_test.go index 1cd02facb9..a27ffce72b 100644 --- a/src/test/e2e/31_component_action_remove_test.go +++ b/src/test/e2e/31_component_action_remove_test.go @@ -18,10 +18,10 @@ func TestComponentActionRemove(t *testing.T) { path := fmt.Sprintf("build/zarf-package-component-actions-%s.tar.zst", e2e.Arch) - stdOut, stdErr, err := e2e.ExecZarfCommand("package", "deploy", path, "--confirm", "--components=on-remove") + stdOut, stdErr, _, err := e2e.ExecZarfCommand("package", "deploy", path, "--confirm", "--components=on-remove") require.NoError(t, err, stdOut, stdErr) - stdOut, stdErr, err = e2e.ExecZarfCommand("package", "remove", path, "--confirm", "--components=on-remove") + stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "remove", path, "--confirm", "--components=on-remove") require.NoError(t, err, stdOut, stdErr) require.Contains(t, stdErr, "NAME") require.Contains(t, stdErr, "DATA") diff --git a/src/test/e2e/32_checksum_and_signature_test.go b/src/test/e2e/32_checksum_and_signature_test.go index c64824910e..05df56763e 100644 --- a/src/test/e2e/32_checksum_and_signature_test.go +++ b/src/test/e2e/32_checksum_and_signature_test.go @@ -21,28 +21,28 @@ func TestChecksumAndSignature(t *testing.T) { privateKeyFlag := "--key=src/test/test-packages/zarf-test.prv-key" publicKeyFlag := "--key=src/test/test-packages/zarf-test.pub" - stdOut, stdErr, err := e2e.ExecZarfCommand("package", "create", testPackageDirPath, privateKeyFlag, "--confirm") + stdOut, stdErr, _, err := e2e.ExecZarfCommand("package", "create", testPackageDirPath, privateKeyFlag, "--confirm") require.NoError(t, err, stdOut, stdErr) defer e2e.CleanFiles(pkgName) /* Test operations during package inspect */ // Test that we can inspect the yaml of the package without the private key - stdOut, stdErr, err = e2e.ExecZarfCommand("package", "inspect", pkgName) + stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "inspect", pkgName) require.NoError(t, err, stdOut, stdErr) // Test that we don't get an error when we remember to provide the public key - stdOut, stdErr, err = e2e.ExecZarfCommand("package", "inspect", pkgName, publicKeyFlag) + stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "inspect", pkgName, publicKeyFlag) require.NoError(t, err, stdOut, stdErr) require.Contains(t, stdErr, "Verified OK") /* Test operations during package deploy */ // Test that we get an error when trying to deploy a package without providing the public key - stdOut, stdErr, err = e2e.ExecZarfCommand("package", "deploy", pkgName, "--confirm") + stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "deploy", pkgName, "--confirm") require.Error(t, err, stdOut, stdErr) require.Contains(t, stdErr, "Failed to deploy package: package is signed but no key was provided") // Test that we don't get an error when we remember to provide the public key - stdOut, stdErr, err = e2e.ExecZarfCommand("package", "deploy", pkgName, publicKeyFlag, "--confirm") + stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "deploy", pkgName, publicKeyFlag, "--confirm") require.NoError(t, err, stdOut, stdErr) require.Contains(t, stdErr, "Zarf deployment complete") } diff --git a/src/test/e2e/40_deprecated_component_scripts_test.go b/src/test/e2e/40_deprecated_component_scripts_test.go index 001003e65d..ee8a95eda4 100644 --- a/src/test/e2e/40_deprecated_component_scripts_test.go +++ b/src/test/e2e/40_deprecated_component_scripts_test.go @@ -32,7 +32,7 @@ func TestDeprecatedComponentScripts(t *testing.T) { // 1. Try creating the package to test the create scripts testPackagePath := fmt.Sprintf("%s/zarf-package-deprecated-component-scripts-%s.tar.zst", testPackageDirPath, e2e.Arch) outputFlag := fmt.Sprintf("-o=%s", testPackageDirPath) - stdOut, stdErr, err := e2e.ExecZarfCommand("package", "create", testPackageDirPath, outputFlag, "--confirm") + stdOut, stdErr, _, err := e2e.ExecZarfCommand("package", "create", testPackageDirPath, outputFlag, "--confirm") defer e2e.CleanFiles(testPackagePath) require.NoError(t, err, stdOut, stdErr) require.Contains(t, stdErr, "Component '1-test-deprecated-prepare-scripts' is using scripts") @@ -48,7 +48,7 @@ func TestDeprecatedComponentScripts(t *testing.T) { } // 2. Deploy the simple script that should pass - stdOut, stdErr, err = e2e.ExecZarfCommand("package", "deploy", testPackagePath, "--confirm", "--components=2-test-deprecated-deploy-scripts") + stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "deploy", testPackagePath, "--confirm", "--components=2-test-deprecated-deploy-scripts") require.NoError(t, err, stdOut, stdErr) // Check that the deploy artifacts were created @@ -57,6 +57,6 @@ func TestDeprecatedComponentScripts(t *testing.T) { } // 3. Deploy the simple script that should fail the timeout - stdOut, stdErr, err = e2e.ExecZarfCommand("package", "deploy", testPackagePath, "--confirm", "--components=3-test-deprecated-timeout-scripts") + stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "deploy", testPackagePath, "--confirm", "--components=3-test-deprecated-timeout-scripts") require.Error(t, err, stdOut, stdErr) } diff --git a/src/test/e2e/41_deprecations_set_variables_test.go b/src/test/e2e/41_deprecations_set_variables_test.go index 57465e7acf..dc3631ac78 100644 --- a/src/test/e2e/41_deprecations_set_variables_test.go +++ b/src/test/e2e/41_deprecations_set_variables_test.go @@ -33,24 +33,24 @@ func TestDeprecatedSetAndPackageVariables(t *testing.T) { outputFlag := fmt.Sprintf("-o=%s", testPackageDirPath) // Check that the command still errors out - stdOut, stdErr, err := e2e.ExecZarfCommand("package", "create", testPackageDirPath, outputFlag, "--confirm") + stdOut, stdErr, _, err := e2e.ExecZarfCommand("package", "create", testPackageDirPath, outputFlag, "--confirm") require.Error(t, err, stdOut, stdErr) require.Contains(t, stdErr, "template 'ECHO' must be '--set'") // Check that the command displays a warning on create - stdOut, stdErr, err = e2e.ExecZarfCommand("package", "create", testPackageDirPath, outputFlag, "--confirm", "--set", "ECHO=Zarf-The-Axolotl") + stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "create", testPackageDirPath, outputFlag, "--confirm", "--set", "ECHO=Zarf-The-Axolotl") defer e2e.CleanFiles(testPackagePath) require.NoError(t, err, stdOut, stdErr) require.Contains(t, stdErr, "Component '1-test-deprecated-set-variable' is using setVariable") require.Contains(t, stdErr, "deprecated syntax ###ZARF_PKG_VAR_ECHO###") // 1. Deploy the setVariable action that should pass and output the variable - stdOut, stdErr, err = e2e.ExecZarfCommand("package", "deploy", testPackagePath, "--confirm", "--components=1-test-deprecated-set-variable") + stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "deploy", testPackagePath, "--confirm", "--components=1-test-deprecated-set-variable") require.NoError(t, err, stdOut, stdErr) require.Contains(t, stdErr, "Hello from: Hello Kitteh") // 2. Deploy the setVariable action that should pass and output the variable - stdOut, stdErr, err = e2e.ExecZarfCommand("package", "deploy", testPackagePath, "--confirm", "--components=2-test-deprecated-pkg-var") + stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "deploy", testPackagePath, "--confirm", "--components=2-test-deprecated-pkg-var") require.NoError(t, err, stdOut, stdErr) require.Contains(t, stdErr, "Zarf-The-Axolotl") } diff --git a/src/test/e2e/50_oci_package_test.go b/src/test/e2e/50_oci_package_test.go index 22ceb7a9fe..690c39904d 100644 --- a/src/test/e2e/50_oci_package_test.go +++ b/src/test/e2e/50_oci_package_test.go @@ -39,7 +39,7 @@ func (suite *RegistryClientTestSuite) SetupSuite() { suite.NoError(err) if !cfg.ContainsAuth() { // make a docker config file w/ some blank creds - _, _, err := e2e.ExecZarfCommand("tools", "registry", "login", "--username", "zarf", "-p", "zarf", "localhost:6000") + _, _, _, err := e2e.ExecZarfCommand("tools", "registry", "login", "--username", "zarf", "-p", "zarf", "localhost:6000") suite.NoError(err) } @@ -52,10 +52,10 @@ func (suite *RegistryClientTestSuite) TearDownSuite() { local := fmt.Sprintf("zarf-package-helm-oci-chart-%s-0.0.1.tar.zst", e2e.Arch) e2e.CleanFiles(local) - stdOut, stdErr, err := e2e.ExecZarfCommand("package", "remove", "helm-oci-chart", "--confirm") + stdOut, stdErr, _, err := e2e.ExecZarfCommand("package", "remove", "helm-oci-chart", "--confirm") suite.NoError(err, stdOut, stdErr) - _, _, err = exec.Cmd("docker", "rm", "-f", "registry") + _, _, _, err = exec.Cmd("docker", "rm", "-f", "registry") suite.NoError(err) } @@ -65,13 +65,13 @@ func (suite *RegistryClientTestSuite) Test_0_Publish() { // Publish package. example := filepath.Join(suite.PackagesDir, fmt.Sprintf("zarf-package-helm-oci-chart-%s-0.0.1.tar.zst", e2e.Arch)) ref := suite.Reference.String() - stdOut, stdErr, err := e2e.ExecZarfCommand("package", "publish", example, "oci://"+ref, "--insecure") + stdOut, stdErr, _, err := e2e.ExecZarfCommand("package", "publish", example, "oci://"+ref, "--insecure") suite.NoError(err, stdOut, stdErr) suite.Contains(stdErr, "Published "+ref) // Publish w/ package missing `metadata.version` field. example = filepath.Join(suite.PackagesDir, fmt.Sprintf("zarf-package-dos-games-%s.tar.zst", e2e.Arch)) - _, stdErr, err = e2e.ExecZarfCommand("package", "publish", example, "oci://"+ref, "--insecure") + _, stdErr, _, err = e2e.ExecZarfCommand("package", "publish", example, "oci://"+ref, "--insecure") suite.Error(err, stdErr) } @@ -86,7 +86,7 @@ func (suite *RegistryClientTestSuite) Test_1_Pull() { ref := suite.Reference.String() // Pull the package via OCI. - stdOut, stdErr, err := e2e.ExecZarfCommand("package", "pull", "oci://"+ref, "--insecure") + stdOut, stdErr, _, err := e2e.ExecZarfCommand("package", "pull", "oci://"+ref, "--insecure") suite.NoError(err, stdOut, stdErr) suite.Contains(stdErr, "Pulled "+ref) @@ -94,7 +94,7 @@ func (suite *RegistryClientTestSuite) Test_1_Pull() { suite.FileExists(out) // Test pull w/ bad ref. - stdOut, stdErr, err = e2e.ExecZarfCommand("package", "pull", "oci://"+badRef.String(), "--insecure") + stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "pull", "oci://"+badRef.String(), "--insecure") suite.Error(err, stdOut, stdErr) } @@ -107,16 +107,16 @@ func (suite *RegistryClientTestSuite) Test_2_Deploy() { ref := suite.Reference.String() // Deploy the package via OCI. - stdOut, stdErr, err := e2e.ExecZarfCommand("package", "deploy", "oci://"+ref, "--insecure", "--confirm") + stdOut, stdErr, _, err := e2e.ExecZarfCommand("package", "deploy", "oci://"+ref, "--insecure", "--confirm") suite.NoError(err, stdOut, stdErr) suite.Contains(stdErr, "Pulled "+ref) - stdOut, stdErr, err = e2e.ExecZarfCommand("tools", "kubectl", "get", "pods", "-n=helm-oci-demo", "--no-headers") + stdOut, stdErr, _, err = e2e.ExecZarfCommand("tools", "kubectl", "get", "pods", "-n=helm-oci-demo", "--no-headers") suite.NoError(err, stdErr) suite.Contains(string(stdOut), "podinfo-") // Test deploy w/ bad ref. - _, stdErr, err = e2e.ExecZarfCommand("package", "deploy", "oci://"+badRef.String(), "--insecure", "--confirm") + _, stdErr, _, err = e2e.ExecZarfCommand("package", "deploy", "oci://"+badRef.String(), "--insecure", "--confirm") suite.Error(err, stdErr) } @@ -126,12 +126,12 @@ func (suite *RegistryClientTestSuite) Test_3_Inspect() { suite.Reference.Repository = "helm-oci-chart" suite.Reference.Reference = fmt.Sprintf("0.0.1-%s", e2e.Arch) ref := suite.Reference.String() - stdOut, stdErr, err := e2e.ExecZarfCommand("package", "inspect", "oci://"+ref, "--insecure") + stdOut, stdErr, _, err := e2e.ExecZarfCommand("package", "inspect", "oci://"+ref, "--insecure") suite.NoError(err, stdOut, stdErr) suite.Contains(stdErr, "Loading Zarf Package oci://"+ref) // Test inspect w/ bad ref. - _, stdErr, err = e2e.ExecZarfCommand("package", "inspect", "oci://"+badRef.String(), "--insecure") + _, stdErr, _, err = e2e.ExecZarfCommand("package", "inspect", "oci://"+badRef.String(), "--insecure") suite.Error(err, stdErr) } @@ -144,10 +144,10 @@ func (suite *RegistryClientTestSuite) Test_4_Pull_And_Deploy() { suite.FileExists(local) // Deploy the local package. - stdOut, stdErr, err := e2e.ExecZarfCommand("package", "deploy", local, "--confirm") + stdOut, stdErr, _, err := e2e.ExecZarfCommand("package", "deploy", local, "--confirm") suite.NoError(err, stdOut, stdErr) - stdOut, stdErr, err = e2e.ExecZarfCommand("tools", "kubectl", "get", "pods", "-n=helm-oci-demo", "--no-headers") + stdOut, stdErr, _, err = e2e.ExecZarfCommand("tools", "kubectl", "get", "pods", "-n=helm-oci-demo", "--no-headers") suite.NoError(err, stdErr) suite.Contains(string(stdOut), "podinfo-") } diff --git a/src/test/e2e/99_yolo_test.go b/src/test/e2e/99_yolo_test.go index 69a3c14c55..791e7eb7c7 100644 --- a/src/test/e2e/99_yolo_test.go +++ b/src/test/e2e/99_yolo_test.go @@ -26,13 +26,13 @@ func TestYOLOMode(t *testing.T) { defer e2e.Teardown(t) // Destroy the cluster to test Zarf cleaning up after itself - stdOut, stdErr, err := e2e.ExecZarfCommand("destroy", "--confirm", "--remove-components") + stdOut, stdErr, _, err := e2e.ExecZarfCommand("destroy", "--confirm", "--remove-components") require.NoError(t, err, stdOut, stdErr) path := fmt.Sprintf("build/zarf-package-yolo-%s.tar.zst", e2e.Arch) // Deploy the YOLO package - stdOut, stdErr, err = e2e.ExecZarfCommand("package", "deploy", path, "--confirm") + stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "deploy", path, "--confirm") require.NoError(t, err, stdOut, stdErr) tunnel, err := cluster.NewZarfTunnel() @@ -45,6 +45,6 @@ func TestYOLOMode(t *testing.T) { assert.NoError(t, err, resp) assert.Equal(t, 200, resp.StatusCode) - stdOut, stdErr, err = e2e.ExecZarfCommand("package", "remove", "yolo", "--confirm") + stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "remove", "yolo", "--confirm") require.NoError(t, err, stdOut, stdErr) } diff --git a/src/test/external-test/common.go b/src/test/external-test/common.go index eee17d0ed5..67c12aa469 100644 --- a/src/test/external-test/common.go +++ b/src/test/external-test/common.go @@ -32,7 +32,7 @@ func verifyWaitSuccess(t *testing.T, timeoutMinutes time.Duration, cmd string, a // after delay, try running default: // Check information from the given command - stdOut, _, err := exec.CmdWithContext(context.TODO(), exec.PrintCfg(), cmd, args...) + stdOut, _, _, err := exec.CmdWithContext(context.TODO(), exec.PrintCfg(), cmd, args...) // Log error if err != nil { t.Log(string(stdOut), err) diff --git a/src/test/external-test/ext_in_cluster_init_test.go b/src/test/external-test/ext_in_cluster_init_test.go index 091ce34113..441c0dab95 100644 --- a/src/test/external-test/ext_in_cluster_init_test.go +++ b/src/test/external-test/ext_in_cluster_init_test.go @@ -69,6 +69,6 @@ func TestExtInClusterDeploy(t *testing.T) { success = verifyKubectlWaitSuccess(t, 2, podinfoWaitCmd, errorStr) assert.True(t, success, errorStr) - _, _, err = exec.CmdWithContext(context.TODO(), exec.PrintCfg(), zarfBinPath, "destroy", "--confirm") + _, _, _, err = exec.CmdWithContext(context.TODO(), exec.PrintCfg(), zarfBinPath, "destroy", "--confirm") require.NoError(t, err, "unable to teardown zarf") } diff --git a/src/test/nightly/ecr_publish_test.go b/src/test/nightly/ecr_publish_test.go index ec4324c100..869db096db 100644 --- a/src/test/nightly/ecr_publish_test.go +++ b/src/test/nightly/ecr_publish_test.go @@ -51,37 +51,37 @@ func TestECRPublishing(t *testing.T) { keyFlag := fmt.Sprintf("--key=%s", "./src/test/test-packages/zarf-test.pub") // Build the package with our test signature - stdOut, stdErr, err := e2e.ExecZarfCommand("package", "create", "examples/helm-oci-chart", "--key=./src/test/test-packages/zarf-test.prv-key", "--confirm", fmt.Sprintf("-o=%s", tmpDir)) + stdOut, stdErr, _, err := e2e.ExecZarfCommand("package", "create", "examples/helm-oci-chart", "--key=./src/test/test-packages/zarf-test.prv-key", "--confirm", fmt.Sprintf("-o=%s", tmpDir)) require.NoError(t, err, stdOut, stdErr) require.FileExists(t, testPackageLocation) // Validate that we can publish the package to ECR without an issue - stdOut, stdErr, err = e2e.ExecZarfCommand("package", "publish", testPackageLocation, registryURL) + stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "publish", testPackageLocation, registryURL) require.NoError(t, err, stdOut, stdErr) // Ensure we get a warning when trying to inspect the online published package - stdOut, stdErr, err = e2e.ExecZarfCommand("package", "inspect", upstreamPackageURL, keyFlag) + stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "inspect", upstreamPackageURL, keyFlag) require.NoError(t, err, stdOut, stdErr) require.Contains(t, stdErr, "Zarf is unable to validate the checksums of remote OCI packages.") require.Contains(t, stdErr, "Package signature validated!") // Ensure we get an error when trying to pull the package without providing the public key - stdOut, stdErr, err = e2e.ExecZarfCommand("package", "pull", upstreamPackageURL) + stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "pull", upstreamPackageURL) require.Error(t, err, stdOut, stdErr) //TODO: look for a specific error instead of just allowing ANY error // Validate that we can pull the package down from ECR - stdOut, stdErr, err = e2e.ExecZarfCommand("package", "pull", upstreamPackageURL, keyFlag) + stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "pull", upstreamPackageURL, keyFlag) require.NoError(t, err, stdOut, stdErr) defer e2e.CleanFiles(testPackageFileName) // Ensure we get a warning when trying to inspect the package without providing the public key - stdOut, stdErr, err = e2e.ExecZarfCommand("package", "inspect", testPackageFileName) + stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "inspect", testPackageFileName) require.NoError(t, err, stdOut, stdErr) require.Contains(t, stdErr, "The package you are inspecting has been signed but a public key was not provided.") require.Contains(t, stdErr, "All of the checksums matched!") // Validate that we get no warnings when inspecting the package while providing the public key - stdOut, stdErr, err = e2e.ExecZarfCommand("package", "inspect", testPackageFileName, keyFlag) + stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "inspect", testPackageFileName, keyFlag) require.NoError(t, err, stdOut, stdErr) require.Contains(t, stdErr, "All of the checksums matched!") require.Contains(t, stdErr, "Package signature validated!") diff --git a/src/test/upgrade-test/previously_built_test.go b/src/test/upgrade-test/previously_built_test.go index 037fd9562e..4a0edb8cb7 100644 --- a/src/test/upgrade-test/previously_built_test.go +++ b/src/test/upgrade-test/previously_built_test.go @@ -21,10 +21,10 @@ func TestPreviouslyBuiltZarfPackage(t *testing.T) { // For the upgrade test, podinfo-upgrade should already be in the cluster (version 6.3.3) (see .github/workflows/test-upgrade.yml) kubeCtlRolloutArgs := []string{"-n=podinfo-upgrade", "rollout", "status", "deployment/podinfo-upgrade"} - kubectlOut, _, _ := exec.Cmd("kubectl", kubeCtlRolloutArgs...) + kubectlOut, _, _, _ := exec.Cmd("kubectl", kubeCtlRolloutArgs...) require.Contains(t, kubectlOut, "successfully rolled out") kubeCtlGetArgs := []string{"-n=podinfo-upgrade", "get", "deployment", "podinfo-upgrade", "-o=jsonpath={.metadata.labels}}"} - kubectlOut, _, _ = exec.Cmd("kubectl", kubeCtlGetArgs...) + kubectlOut, _, _, _ = exec.Cmd("kubectl", kubeCtlGetArgs...) require.Contains(t, kubectlOut, "6.3.3") // We also expect a 6.3.4 package to have been previously built @@ -32,7 +32,7 @@ func TestPreviouslyBuiltZarfPackage(t *testing.T) { // Deploy the package. zarfDeployArgs := []string{"package", "deploy", previouslyBuiltPackage, "--confirm"} - stdOut, stdErr, err := exec.Cmd(zarfBinPath, zarfDeployArgs...) + stdOut, stdErr, _, err := exec.Cmd(zarfBinPath, zarfDeployArgs...) require.NoError(t, err, stdOut, stdErr) // [DEPRECATIONS] We expect any deprecated things to work from the old package @@ -41,21 +41,21 @@ func TestPreviouslyBuiltZarfPackage(t *testing.T) { // Verify that podinfo-upgrade successfully deploys in the cluster (version 6.3.4) kubeCtlRolloutArgs = []string{"-n=podinfo-upgrade", "rollout", "status", "deployment/podinfo-upgrade"} - kubectlOut, _, _ = exec.Cmd("kubectl", kubeCtlRolloutArgs...) + kubectlOut, _, _, _ = exec.Cmd("kubectl", kubeCtlRolloutArgs...) require.Contains(t, kubectlOut, "successfully rolled out") kubeCtlGetArgs = []string{"-n=podinfo-upgrade", "get", "deployment", "podinfo-upgrade", "-o=jsonpath={.metadata.labels}}"} - kubectlOut, _, _ = exec.Cmd("kubectl", kubeCtlGetArgs...) + kubectlOut, _, _, _ = exec.Cmd("kubectl", kubeCtlGetArgs...) require.Contains(t, kubectlOut, "6.3.4") // We also want to build a new package. zarfCreateArgs := []string{"package", "create", "../../../src/test/upgrade-test", "--set", "PODINFO_VERSION=6.3.5", "--confirm"} - stdOut, stdErr, err = exec.Cmd(zarfBinPath, zarfCreateArgs...) + stdOut, stdErr, _, err = exec.Cmd(zarfBinPath, zarfCreateArgs...) require.NoError(t, err, stdOut, stdErr) newlyBuiltPackage := "zarf-package-test-upgrade-package-amd64-6.3.5.tar.zst" // Deploy the package. zarfDeployArgs = []string{"package", "deploy", newlyBuiltPackage, "--confirm"} - stdOut, stdErr, err = exec.Cmd(zarfBinPath, zarfDeployArgs...) + stdOut, stdErr, _, err = exec.Cmd(zarfBinPath, zarfDeployArgs...) require.NoError(t, err, stdOut, stdErr) // [DEPRECATIONS] We expect any deprecated things to work from the new package @@ -64,14 +64,14 @@ func TestPreviouslyBuiltZarfPackage(t *testing.T) { // Verify that podinfo-upgrade successfully deploys in the cluster (version 6.3.5) kubeCtlRolloutArgs = []string{"-n=podinfo-upgrade", "rollout", "status", "deployment/podinfo-upgrade"} - kubectlOut, _, _ = exec.Cmd("kubectl", kubeCtlRolloutArgs...) + kubectlOut, _, _, _ = exec.Cmd("kubectl", kubeCtlRolloutArgs...) require.Contains(t, kubectlOut, "successfully rolled out") kubeCtlGetArgs = []string{"-n=podinfo-upgrade", "get", "deployment", "podinfo-upgrade", "-o=jsonpath={.metadata.labels}}"} - kubectlOut, _, _ = exec.Cmd("kubectl", kubeCtlGetArgs...) + kubectlOut, _, _, _ = exec.Cmd("kubectl", kubeCtlGetArgs...) require.Contains(t, kubectlOut, "6.3.5") // Remove the package. zarfRemoveArgs := []string{"package", "remove", "test-upgrade-package", "--confirm"} - stdOut, stdErr, err = exec.Cmd(zarfBinPath, zarfRemoveArgs...) + stdOut, stdErr, _, err = exec.Cmd(zarfBinPath, zarfRemoveArgs...) require.NoError(t, err, stdOut, stdErr) } From 0a25418b692a03e99bc067bd6e51aa22175197c2 Mon Sep 17 00:00:00 2001 From: Lucas Rodriguez Date: Mon, 1 May 2023 20:18:28 -0500 Subject: [PATCH 42/53] Revert "Check for exit code 0 when running actions" This reverts commit 17681911dda239206fa6da71328d54bf39166e9d. --- src/cmd/tools/wait.go | 4 +- src/internal/cluster/data.go | 2 +- src/internal/packager/git/clone.go | 2 +- src/pkg/packager/actions.go | 5 +-- src/pkg/utils/exec/exec.go | 16 ++++---- src/test/common.go | 2 +- src/test/e2e/00_use_cli_test.go | 24 +++++------ src/test/e2e/01_component_choice_test.go | 6 +-- src/test/e2e/02_component_actions_test.go | 18 ++++----- src/test/e2e/03_temp_directory_deploy_test.go | 2 +- src/test/e2e/04_create_templating_test.go | 6 +-- src/test/e2e/05_multi_part_test.go | 4 +- src/test/e2e/06_create_sbom_test.go | 8 ++-- src/test/e2e/07_create_git_test.go | 18 ++++----- src/test/e2e/20_zarf_init_test.go | 22 +++++----- src/test/e2e/21_connect_test.go | 4 +- src/test/e2e/22_git_and_flux_test.go | 10 ++--- src/test/e2e/23_data_injection_test.go | 6 +-- src/test/e2e/24_variables_test.go | 10 ++--- src/test/e2e/25_helm_test.go | 40 +++++++++---------- src/test/e2e/26_simple_packages_test.go | 8 ++-- src/test/e2e/27_cosign_deploy_test.go | 4 +- src/test/e2e/28_wait_test.go | 4 +- .../e2e/29_mismatched_architectures_test.go | 8 ++-- src/test/e2e/30_config_file_test.go | 16 ++++---- .../e2e/31_component_action_remove_test.go | 4 +- .../e2e/32_checksum_and_signature_test.go | 10 ++--- .../40_deprecated_component_scripts_test.go | 6 +-- .../e2e/41_deprecations_set_variables_test.go | 8 ++-- src/test/e2e/50_oci_package_test.go | 28 ++++++------- src/test/e2e/99_yolo_test.go | 6 +-- src/test/external-test/common.go | 2 +- .../external-test/ext_in_cluster_init_test.go | 2 +- src/test/nightly/ecr_publish_test.go | 14 +++---- .../upgrade-test/previously_built_test.go | 20 +++++----- 35 files changed, 173 insertions(+), 176 deletions(-) diff --git a/src/cmd/tools/wait.go b/src/cmd/tools/wait.go index 1e7a70f225..956ae26b8f 100644 --- a/src/cmd/tools/wait.go +++ b/src/cmd/tools/wait.go @@ -111,7 +111,7 @@ var waitForCmd = &cobra.Command{ spinner.Updatef(existMsg) // Check if the resource exists. args := []string{"tools", "kubectl", "get", "-n", waitNamespace, kind, identifier} - if stdout, stderr, _, err := exec.Cmd(zarfBinPath, args...); err != nil { + if stdout, stderr, err := exec.Cmd(zarfBinPath, args...); err != nil { message.Debug(stdout, stderr, err) continue } @@ -130,7 +130,7 @@ var waitForCmd = &cobra.Command{ "--timeout=" + waitTimeout} // If there is an error, log it and try again. - if stdout, stderr, _, err := exec.Cmd(zarfBinPath, args...); err != nil { + if stdout, stderr, err := exec.Cmd(zarfBinPath, args...); err != nil { message.Debug(stdout, stderr, err) continue } diff --git a/src/internal/cluster/data.go b/src/internal/cluster/data.go index 33d59a4314..d1767343c2 100644 --- a/src/internal/cluster/data.go +++ b/src/internal/cluster/data.go @@ -46,7 +46,7 @@ func (c *Cluster) HandleDataInjection(wg *sync.WaitGroup, data types.ZarfDataInj // Get the OS shell to execute commands in shell, shellArgs := exec.GetOSShell(types.ZarfComponentActionShell{Windows: "cmd"}) - if _, _, _, err := exec.Cmd(shell, shellArgs, "tar --version"); err != nil { + if _, _, err := exec.Cmd(shell, shellArgs, "tar --version"); err != nil { message.Error(err, "Unable to execute tar on this system. Please ensure it is installed and on your $PATH.") return } diff --git a/src/internal/packager/git/clone.go b/src/internal/packager/git/clone.go index 81ecb25b80..6ef4301350 100644 --- a/src/internal/packager/git/clone.go +++ b/src/internal/packager/git/clone.go @@ -87,7 +87,7 @@ func (g *Git) gitCloneFallback(gitURL string, ref plumbing.ReferenceName) error Stdout: g.Spinner, Stderr: g.Spinner, } - _, _, _, err := exec.CmdWithContext(context.TODO(), execConfig, "git", cmdArgs...) + _, _, err := exec.CmdWithContext(context.TODO(), execConfig, "git", cmdArgs...) if err != nil { return err } diff --git a/src/pkg/packager/actions.go b/src/pkg/packager/actions.go index 6c910a91d0..66887890b0 100644 --- a/src/pkg/packager/actions.go +++ b/src/pkg/packager/actions.go @@ -278,14 +278,11 @@ func actionRun(ctx context.Context, cfg types.ZarfComponentActionDefaults, cmd s execCfg.Stderr = spinner } - out, errOut, exitCode, err := exec.CmdWithContext(ctx, execCfg, shell, shellArgs, cmd) + out, errOut, err := exec.CmdWithContext(ctx, execCfg, shell, shellArgs, cmd) // Dump final complete output (respect mute to prevent sensitive values from hitting the logs). if !cfg.Mute { message.Debug(cmd, out, errOut) } - if exitCode != 0 { - return "", err - } return out, err } diff --git a/src/pkg/utils/exec/exec.go b/src/pkg/utils/exec/exec.go index 93a8fa5089..09ca2a4794 100644 --- a/src/pkg/utils/exec/exec.go +++ b/src/pkg/utils/exec/exec.go @@ -39,20 +39,20 @@ func PrintCfg() Config { } // Cmd executes a given command with given config. -func Cmd(command string, args ...string) (string, string, int, error) { +func Cmd(command string, args ...string) (string, string, error) { return CmdWithContext(context.TODO(), Config{}, command, args...) } // CmdWithPrint executes a given command with given config and prints the command. func CmdWithPrint(command string, args ...string) error { - _, _, _, err := CmdWithContext(context.TODO(), PrintCfg(), command, args...) + _, _, err := CmdWithContext(context.TODO(), PrintCfg(), command, args...) return err } // CmdWithContext executes a given command with given config. -func CmdWithContext(ctx context.Context, config Config, command string, args ...string) (string, string, int, error) { +func CmdWithContext(ctx context.Context, config Config, command string, args ...string) (string, string, error) { if command == "" { - return "", "", 0, errors.New("command is required") + return "", "", errors.New("command is required") } // Set up the command. @@ -106,7 +106,7 @@ func CmdWithContext(ctx context.Context, config Config, command string, args ... // Start the command. if err := cmd.Start(); err != nil { - return "", "", 0, err + return "", "", err } // Add to waitgroup for each goroutine. @@ -129,14 +129,14 @@ func CmdWithContext(ctx context.Context, config Config, command string, args ... // Abort if there was an error capturing the command's outputs. if errStdout != nil { - return "", "", 0, fmt.Errorf("failed to capture the stdout command output: %w", errStdout) + return "", "", fmt.Errorf("failed to capture the stdout command output: %w", errStdout) } if errStderr != nil { - return "", "", 0, fmt.Errorf("failed to capture the stderr command output: %w", errStderr) + return "", "", fmt.Errorf("failed to capture the stderr command output: %w", errStderr) } // Wait for the command to finish and return the buffered outputs, regardless of whether we printed them. - return stdoutBuf.String(), stderrBuf.String(), cmd.ProcessState.ExitCode(), cmd.Wait() + return stdoutBuf.String(), stderrBuf.String(), cmd.Wait() } // LaunchURL opens a URL in the default browser. diff --git a/src/test/common.go b/src/test/common.go index 5d4cbe253e..402e7598cf 100644 --- a/src/test/common.go +++ b/src/test/common.go @@ -66,7 +66,7 @@ func (e2e *ZarfE2ETest) Teardown(t *testing.T) { } // ExecZarfCommand executes a Zarf command. -func (e2e *ZarfE2ETest) ExecZarfCommand(commandString ...string) (string, string, int, error) { +func (e2e *ZarfE2ETest) ExecZarfCommand(commandString ...string) (string, string, error) { return exec.CmdWithContext(context.TODO(), exec.PrintCfg(), e2e.ZarfBinPath, commandString...) } diff --git a/src/test/e2e/00_use_cli_test.go b/src/test/e2e/00_use_cli_test.go index 4f61e01a87..af3e3ae05c 100644 --- a/src/test/e2e/00_use_cli_test.go +++ b/src/test/e2e/00_use_cli_test.go @@ -36,54 +36,54 @@ func TestUseCLI(t *testing.T) { err := os.WriteFile(shasumTestFilePath, []byte("random test data 🦄\n"), 0600) assert.NoError(t, err) - stdOut, stdErr, _, err := e2e.ExecZarfCommand("prepare", "sha256sum", shasumTestFilePath) + stdOut, stdErr, err := e2e.ExecZarfCommand("prepare", "sha256sum", shasumTestFilePath) assert.NoError(t, err, stdOut, stdErr) assert.Equal(t, expectedShasum, stdOut, "The expected SHASUM should equal the actual SHASUM") // Test `zarf prepare sha256sum` for a remote asset expectedShasum = "c3cdea0573ba5a058ec090b5d2683bf398e8b1614c37ec81136ed03b78167617\n" - stdOut, stdErr, _, err = e2e.ExecZarfCommand("prepare", "sha256sum", "https://zarf-public.s3-us-gov-west-1.amazonaws.com/pipelines/zarf-prepare-shasum-remote-test-file.txt") + stdOut, stdErr, err = e2e.ExecZarfCommand("prepare", "sha256sum", "https://zarf-public.s3-us-gov-west-1.amazonaws.com/pipelines/zarf-prepare-shasum-remote-test-file.txt") assert.NoError(t, err, stdOut, stdErr) assert.Contains(t, stdOut, expectedShasum, "The expected SHASUM should equal the actual SHASUM") // Test `zarf version` - stdOut, _, _, err = e2e.ExecZarfCommand("version") + stdOut, _, err = e2e.ExecZarfCommand("version") assert.NoError(t, err) assert.NotEqual(t, len(stdOut), 0, "Zarf version should not be an empty string") assert.NotEqual(t, stdOut, "UnknownVersion", "Zarf version should not be the default value") // Test `zarf prepare find-images` for a remote asset - stdOut, stdErr, _, err = e2e.ExecZarfCommand("prepare", "find-images", "examples/helm-alt-release-name") + stdOut, stdErr, err = e2e.ExecZarfCommand("prepare", "find-images", "examples/helm-alt-release-name") assert.NoError(t, err, stdOut, stdErr) assert.Contains(t, stdOut, "ghcr.io/stefanprodan/podinfo:6.1.6", "The chart image should be found by Zarf") // Test `zarf prepare find-images` for a local asset - stdOut, stdErr, _, err = e2e.ExecZarfCommand("prepare", "find-images", "examples/helm-local-chart") + stdOut, stdErr, err = e2e.ExecZarfCommand("prepare", "find-images", "examples/helm-local-chart") assert.NoError(t, err, stdOut, stdErr) assert.Contains(t, stdOut, "nginx:1.16.0", "The chart image should be found by Zarf") // Test for expected failure when given a bad component input - _, _, _, err = e2e.ExecZarfCommand("init", "--confirm", "--components=k3s,foo,logging") + _, _, err = e2e.ExecZarfCommand("init", "--confirm", "--components=k3s,foo,logging") assert.Error(t, err) // Test that changing the log level actually applies the requested level - _, stdErr, _, _ = e2e.ExecZarfCommand("version", "--log-level=debug") + _, stdErr, _ = e2e.ExecZarfCommand("version", "--log-level=debug") expectedOutString := "Log level set to debug" require.Contains(t, stdErr, expectedOutString, "The log level should be changed to 'debug'") // Test that `zarf package deploy` gives an error if deploying a remote package without the --insecure or --shasum flags - stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "deploy", "https://zarf-examples.s3.amazonaws.com/zarf-package-appliance-demo-doom-20210125.tar.zst", "--confirm") + stdOut, stdErr, err = e2e.ExecZarfCommand("package", "deploy", "https://zarf-examples.s3.amazonaws.com/zarf-package-appliance-demo-doom-20210125.tar.zst", "--confirm") assert.Error(t, err, stdOut, stdErr) pkgName := fmt.Sprintf("zarf-package-dos-games-%s.tar.zst", e2e.Arch) _ = os.Mkdir(otherTmpPath, 0750) - stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "create", "examples/dos-games", "--confirm", "--zarf-cache", cachePath, "--tmpdir", otherTmpPath, "--log-level=debug") + stdOut, stdErr, err = e2e.ExecZarfCommand("package", "create", "examples/dos-games", "--confirm", "--zarf-cache", cachePath, "--tmpdir", otherTmpPath, "--log-level=debug") require.Contains(t, stdErr, otherTmpPath, "The other tmp path should show as being created") require.NoError(t, err, stdOut, stdErr) - stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "inspect", pkgName, "--tmpdir", otherTmpPath, "--log-level=debug") + stdOut, stdErr, err = e2e.ExecZarfCommand("package", "inspect", pkgName, "--tmpdir", otherTmpPath, "--log-level=debug") require.Contains(t, stdErr, otherTmpPath, "The other tmp path should show as being created") require.NoError(t, err, stdOut, stdErr) @@ -94,7 +94,7 @@ func TestUseCLI(t *testing.T) { assert.Greater(t, len(files), 1) // Test removal of cache - stdOut, stdErr, _, err = e2e.ExecZarfCommand("tools", "clear-cache", "--zarf-cache", cachePath) + stdOut, stdErr, err = e2e.ExecZarfCommand("tools", "clear-cache", "--zarf-cache", cachePath) require.NoError(t, err, stdOut, stdErr) // Check that ReadDir returns no such file or directory for the cachePath @@ -111,7 +111,7 @@ func TestUseCLI(t *testing.T) { tlsCA := "tls.ca" tlsCert := "tls.crt" tlsKey := "tls.key" - stdOut, stdErr, _, err = e2e.ExecZarfCommand("tools", "gen-pki", "github.com", "--sub-alt-name", "google.com") + stdOut, stdErr, err = e2e.ExecZarfCommand("tools", "gen-pki", "github.com", "--sub-alt-name", "google.com") require.NoError(t, err, stdOut, stdErr) require.Contains(t, stdErr, "Successfully created a chain of trust for github.com") diff --git a/src/test/e2e/01_component_choice_test.go b/src/test/e2e/01_component_choice_test.go index 6de8906a04..e81f3f0c83 100644 --- a/src/test/e2e/01_component_choice_test.go +++ b/src/test/e2e/01_component_choice_test.go @@ -27,11 +27,11 @@ func TestComponentChoice(t *testing.T) { // Try to deploy both and expect failure due to only one component allowed at a time // We currently don't have a pattern to actually test the interactive prompt, so just testing automation for now - stdOut, stdErr, _, err := e2e.ExecZarfCommand("package", "deploy", path, "--confirm", "--components=first-choice,second-choice") + stdOut, stdErr, err := e2e.ExecZarfCommand("package", "deploy", path, "--confirm", "--components=first-choice,second-choice") require.Error(t, err, stdOut, stdErr) // Deploy a single choice and expect success - stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "deploy", path, "--confirm", "--components=first-choice") + stdOut, stdErr, err = e2e.ExecZarfCommand("package", "deploy", path, "--confirm", "--components=first-choice") require.NoError(t, err, stdOut, stdErr) // Verify the file was created @@ -40,7 +40,7 @@ func TestComponentChoice(t *testing.T) { require.NoFileExists(t, secondFile) // Deploy using default choice - stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "deploy", path, "--confirm") + stdOut, stdErr, err = e2e.ExecZarfCommand("package", "deploy", path, "--confirm") require.NoError(t, err, stdOut, stdErr) // Verify the file was created diff --git a/src/test/e2e/02_component_actions_test.go b/src/test/e2e/02_component_actions_test.go index f9631373ef..f4e56156a4 100644 --- a/src/test/e2e/02_component_actions_test.go +++ b/src/test/e2e/02_component_actions_test.go @@ -36,7 +36,7 @@ func TestComponentActions(t *testing.T) { /* Create */ // Try creating the package to test the onCreate actions. - stdOut, stdErr, _, err := e2e.ExecZarfCommand("package", "create", "examples/component-actions", "--confirm") + stdOut, stdErr, err := e2e.ExecZarfCommand("package", "create", "examples/component-actions", "--confirm") require.NoError(t, err, stdOut, stdErr) require.Contains(t, stdErr, "Completed \"touch test-create-before.txt\"") require.Contains(t, stdErr, "multiline!") @@ -57,7 +57,7 @@ func TestComponentActions(t *testing.T) { /* Deploy */ path := fmt.Sprintf("build/zarf-package-component-actions-%s.tar.zst", e2e.Arch) // Deploy the simple script that should pass. - stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "deploy", path, "--confirm", "--components=on-deploy-and-remove") + stdOut, stdErr, err = e2e.ExecZarfCommand("package", "deploy", path, "--confirm", "--components=on-deploy-and-remove") require.NoError(t, err, stdOut, stdErr) // Check that the deploy artifacts were created. @@ -66,7 +66,7 @@ func TestComponentActions(t *testing.T) { } // Remove the simple script that should pass. - stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "remove", path, "--confirm", "--components=on-deploy-and-remove") + stdOut, stdErr, err = e2e.ExecZarfCommand("package", "remove", path, "--confirm", "--components=on-deploy-and-remove") require.NoError(t, err, stdOut, stdErr) // Check that the deploy artifacts were created. @@ -75,17 +75,17 @@ func TestComponentActions(t *testing.T) { } // Deploy the simple action that should fail the timeout. - stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "deploy", path, "--confirm", "--components=on-deploy-with-timeout") + stdOut, stdErr, err = e2e.ExecZarfCommand("package", "deploy", path, "--confirm", "--components=on-deploy-with-timeout") require.Error(t, err, stdOut, stdErr) require.Contains(t, stdErr, "😭😭😭 this action failed because it took too long to run 😭😭😭") // Test using a Zarf Variable within the action - stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "deploy", path, "--confirm", "--components=on-deploy-with-variable", "-l=trace") + stdOut, stdErr, err = e2e.ExecZarfCommand("package", "deploy", path, "--confirm", "--components=on-deploy-with-variable", "-l=trace") require.NoError(t, err, stdOut, stdErr) require.Contains(t, stdErr, "the dog says ruff") // Test using dynamic and multiple-variables - stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "deploy", path, "--confirm", "--components=on-deploy-with-dynamic-variable,on-deploy-with-multiple-variables", "-l=trace") + stdOut, stdErr, err = e2e.ExecZarfCommand("package", "deploy", path, "--confirm", "--components=on-deploy-with-dynamic-variable,on-deploy-with-multiple-variables", "-l=trace") require.NoError(t, err, stdOut, stdErr) require.Contains(t, stdErr, "the cat says meow") require.Contains(t, stdErr, "the dog says ruff") @@ -93,12 +93,12 @@ func TestComponentActions(t *testing.T) { require.Contains(t, stdErr, "with a TF_VAR, the snake also says hiss") // Test using environment variables - stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "deploy", path, "--confirm", "--components=on-deploy-with-env-var") + stdOut, stdErr, err = e2e.ExecZarfCommand("package", "deploy", path, "--confirm", "--components=on-deploy-with-env-var") require.NoError(t, err, stdOut, stdErr) require.FileExists(t, deployWithEnvVarArtifact) // Test using a templated file but without dynamic variables - stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "deploy", path, "--confirm", "--components=on-deploy-with-template-use-of-variable") + stdOut, stdErr, err = e2e.ExecZarfCommand("package", "deploy", path, "--confirm", "--components=on-deploy-with-template-use-of-variable") require.NoError(t, err, stdOut, stdErr) outTemplated, err := os.ReadFile("templated.txt") require.NoError(t, err) @@ -110,7 +110,7 @@ func TestComponentActions(t *testing.T) { e2e.CleanFiles("templated.txt") // Test using a templated file with dynamic variables - stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "deploy", path, "--confirm", "--components=on-deploy-with-template-use-of-variable,on-deploy-with-dynamic-variable,on-deploy-with-multiple-variables") + stdOut, stdErr, err = e2e.ExecZarfCommand("package", "deploy", path, "--confirm", "--components=on-deploy-with-template-use-of-variable,on-deploy-with-dynamic-variable,on-deploy-with-multiple-variables") require.NoError(t, err, stdOut, stdErr) outTemplated, err = os.ReadFile("templated.txt") require.NoError(t, err) diff --git a/src/test/e2e/03_temp_directory_deploy_test.go b/src/test/e2e/03_temp_directory_deploy_test.go index dbafb20996..7e9fd4fc5d 100644 --- a/src/test/e2e/03_temp_directory_deploy_test.go +++ b/src/test/e2e/03_temp_directory_deploy_test.go @@ -32,7 +32,7 @@ func TestTempDirectoryDeploy(t *testing.T) { _ = os.Mkdir(otherTmpPath, 0750) - stdOut, stdErr, _, err := e2e.ExecZarfCommand("package", "deploy", path, "--confirm", "--tmpdir", otherTmpPath, "--log-level=debug") + stdOut, stdErr, err := e2e.ExecZarfCommand("package", "deploy", path, "--confirm", "--tmpdir", otherTmpPath, "--log-level=debug") require.Contains(t, stdErr, otherTmpPath, "The other tmp path should show as being created") require.NoError(t, err, stdOut, stdErr) diff --git a/src/test/e2e/04_create_templating_test.go b/src/test/e2e/04_create_templating_test.go index 61e1747ce8..f70da2fdbc 100644 --- a/src/test/e2e/04_create_templating_test.go +++ b/src/test/e2e/04_create_templating_test.go @@ -28,15 +28,15 @@ func TestCreateTemplating(t *testing.T) { pkgName := fmt.Sprintf("zarf-package-variables-%s.tar.zst", e2e.Arch) // Test that not specifying a package variable results in an error - _, stdErr, _, _ := e2e.ExecZarfCommand("package", "create", "examples/variables", "--confirm", "--zarf-cache", cachePath) + _, stdErr, _ := e2e.ExecZarfCommand("package", "create", "examples/variables", "--confirm", "--zarf-cache", cachePath) expectedOutString := "variable 'NGINX_VERSION' must be '--set' when using the '--confirm' flag" require.Contains(t, stdErr, "", expectedOutString) // Test a simple package variable example with `--set` (will fail to pull an image if this is not set correctly) - stdOut, stdErr, _, err := e2e.ExecZarfCommand("package", "create", "examples/variables", "--set", "NGINX_VERSION=1.23.3", "--confirm", "--zarf-cache", cachePath) + stdOut, stdErr, err := e2e.ExecZarfCommand("package", "create", "examples/variables", "--set", "NGINX_VERSION=1.23.3", "--confirm", "--zarf-cache", cachePath) require.NoError(t, err, stdOut, stdErr) - stdOut, stdErr, _, err = e2e.ExecZarfCommand("t", "archiver", "decompress", pkgName, decompressPath, "--decompress-all", "-l=trace") + stdOut, stdErr, err = e2e.ExecZarfCommand("t", "archiver", "decompress", pkgName, decompressPath, "--decompress-all", "-l=trace") require.NoError(t, err, stdOut, stdErr) // Check that the constant in the zarf.yaml is replaced correctly diff --git a/src/test/e2e/05_multi_part_test.go b/src/test/e2e/05_multi_part_test.go index a0e8c5d7f1..661fe742af 100644 --- a/src/test/e2e/05_multi_part_test.go +++ b/src/test/e2e/05_multi_part_test.go @@ -27,7 +27,7 @@ func TestMultiPartPackage(t *testing.T) { e2e.CleanFiles(deployPath, outputFile) // Create the package with a max size of 1MB - stdOut, stdErr, _, err := e2e.ExecZarfCommand("package", "create", createPath, "--confirm", "--max-package-size=1") + stdOut, stdErr, err := e2e.ExecZarfCommand("package", "create", createPath, "--confirm", "--max-package-size=1") require.NoError(t, err, stdOut, stdErr) list, err := filepath.Glob("zarf-package-multi-part-*") @@ -35,7 +35,7 @@ func TestMultiPartPackage(t *testing.T) { // Length is 7 because there are 6 parts and 1 manifest require.Len(t, list, 7) - stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "deploy", deployPath, "--confirm") + stdOut, stdErr, err = e2e.ExecZarfCommand("package", "deploy", deployPath, "--confirm") require.NoError(t, err, stdOut, stdErr) // Verify the package was deployed diff --git a/src/test/e2e/06_create_sbom_test.go b/src/test/e2e/06_create_sbom_test.go index 5d4f9be60c..d64d06c396 100644 --- a/src/test/e2e/06_create_sbom_test.go +++ b/src/test/e2e/06_create_sbom_test.go @@ -22,7 +22,7 @@ func TestCreateSBOM(t *testing.T) { pkgName := fmt.Sprintf("zarf-package-dos-games-%s.tar.zst", e2e.Arch) - stdOut, stdErr, _, err := e2e.ExecZarfCommand("package", "create", "examples/dos-games", "--confirm", "--zarf-cache", cachePath, "--sbom-out", sbomPath) + stdOut, stdErr, err := e2e.ExecZarfCommand("package", "create", "examples/dos-games", "--confirm", "--zarf-cache", cachePath, "--sbom-out", sbomPath) require.NoError(t, err, stdOut, stdErr) require.Contains(t, stdErr, "Creating SBOMs for 1 images and 0 components with files.") // Test that the game package generates the SBOMs we expect (images only) @@ -36,7 +36,7 @@ func TestCreateSBOM(t *testing.T) { // Clean the SBOM path so it is force to be recreated e2e.CleanFiles(sbomPath) - stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "inspect", pkgName, "--sbom-out", sbomPath) + stdOut, stdErr, err = e2e.ExecZarfCommand("package", "inspect", pkgName, "--sbom-out", sbomPath) require.NoError(t, err, stdOut, stdErr) // Test that the game package generates the SBOMs we expect (images only) _, err = os.ReadFile(filepath.Join(sbomPath, "dos-games", "sbom-viewer-defenseunicorns_zarf-game_multi-tile-dark.html")) @@ -47,12 +47,12 @@ func TestCreateSBOM(t *testing.T) { require.NoError(t, err) // Pull the current zarf binary version to find the corresponding init package - version, stdErr, _, err := e2e.ExecZarfCommand("version") + version, stdErr, err := e2e.ExecZarfCommand("version") require.NoError(t, err, version, stdErr) initName := fmt.Sprintf("build/zarf-init-%s-%s.tar.zst", e2e.Arch, strings.TrimSpace(version)) - stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "inspect", initName, "--sbom-out", sbomPath) + stdOut, stdErr, err = e2e.ExecZarfCommand("package", "inspect", initName, "--sbom-out", sbomPath) require.NoError(t, err, stdOut, stdErr) // Test that we preserve the filepath _, err = os.ReadFile(filepath.Join(sbomPath, "dos-games", "sbom-viewer-defenseunicorns_zarf-game_multi-tile-dark.html")) diff --git a/src/test/e2e/07_create_git_test.go b/src/test/e2e/07_create_git_test.go index 36f66b8199..16a0c08948 100644 --- a/src/test/e2e/07_create_git_test.go +++ b/src/test/e2e/07_create_git_test.go @@ -22,13 +22,13 @@ func TestCreateGit(t *testing.T) { // Extract the test package. path := fmt.Sprintf("build/zarf-package-git-data-%s-v1.0.0.tar.zst", e2e.Arch) - stdOut, stdErr, _, err := e2e.ExecZarfCommand("tools", "archiver", "decompress", path, extractDir, "--decompress-all") + stdOut, stdErr, err := e2e.ExecZarfCommand("tools", "archiver", "decompress", path, extractDir, "--decompress-all") require.NoError(t, err, stdOut, stdErr) defer e2e.CleanFiles(extractDir) // Verify the full-repo component. gitDirFlag := fmt.Sprintf("--git-dir=%s/components/full-repo/repos/nocode-953829860/.git", extractDir) - stdOut, stdErr, _, err = exec.Cmd("git", gitDirFlag, "log", "--oneline", "--decorate") + stdOut, stdErr, err = exec.Cmd("git", gitDirFlag, "log", "--oneline", "--decorate") require.NoError(t, err, stdOut, stdErr) require.Contains(t, stdOut, "c46f06e add no code") require.Contains(t, stdOut, "(tag: 1.0.0)") @@ -36,40 +36,40 @@ func TestCreateGit(t *testing.T) { // Verify a repo with a shorthand tag. gitDirFlag = fmt.Sprintf("--git-dir=%s/components/specific-tag/repos/zarf-4023393304/.git", extractDir) - stdOut, stdErr, _, err = exec.Cmd("git", gitDirFlag, "log", "HEAD^..HEAD", "--oneline", "--decorate") + stdOut, stdErr, err = exec.Cmd("git", gitDirFlag, "log", "HEAD^..HEAD", "--oneline", "--decorate") require.NoError(t, err, stdOut, stdErr) require.Contains(t, stdOut, "(HEAD -> zarf-ref-v0.15.0, tag: v0.15.0) Normalize --confirm behavior in the CLI (#297)") // Verify a repo with a shorthand tag only has one tag. - stdOut, stdErr, _, err = exec.Cmd("git", gitDirFlag, "tag") + stdOut, stdErr, err = exec.Cmd("git", gitDirFlag, "tag") require.NoError(t, err, stdOut, stdErr) require.Equal(t, "v0.15.0\n", stdOut) // Verify a repo with a full git refspec tag. gitDirFlag = fmt.Sprintf("--git-dir=%s/components/specific-tag/repos/zarf-2175050463/.git", extractDir) - stdOut, stdErr, _, err = exec.Cmd("git", gitDirFlag, "log", "HEAD^..HEAD", "--oneline", "--decorate") + stdOut, stdErr, err = exec.Cmd("git", gitDirFlag, "log", "HEAD^..HEAD", "--oneline", "--decorate") require.NoError(t, err, stdOut, stdErr) require.Contains(t, stdOut, "(HEAD -> zarf-ref-v0.16.0, tag: v0.16.0) slightly re-arrange zarf arch diagram layout (#383)") // Verify a repo with a full git refspec tag only has one tag. - stdOut, stdErr, _, err = exec.Cmd("git", gitDirFlag, "tag") + stdOut, stdErr, err = exec.Cmd("git", gitDirFlag, "tag") require.NoError(t, err, stdOut, stdErr) require.Equal(t, "v0.16.0\n", stdOut) // Verify a repo with a branch. gitDirFlag = fmt.Sprintf("--git-dir=%s/components/specific-branch/repos/big-bang-2705706079/.git", extractDir) - stdOut, stdErr, _, err = exec.Cmd("git", gitDirFlag, "log", "HEAD^..HEAD", "--oneline", "--decorate") + stdOut, stdErr, err = exec.Cmd("git", gitDirFlag, "log", "HEAD^..HEAD", "--oneline", "--decorate") require.NoError(t, err, stdOut, stdErr) require.Contains(t, stdOut, "(HEAD -> release-1.54.x, tag: 1.54.0-rc.0, tag: 1.54.0, online-upstream/release-1.54.x)") // Verify a repo with a branch only has one branch. - stdOut, stdErr, _, err = exec.Cmd("git", gitDirFlag, "branch") + stdOut, stdErr, err = exec.Cmd("git", gitDirFlag, "branch") require.NoError(t, err, stdOut, stdErr) require.Equal(t, "* release-1.54.x\n", stdOut) // Verify a repo with a commit hash. gitDirFlag = fmt.Sprintf("--git-dir=%s/components/specific-hash/repos/zarf-1356873667/.git", extractDir) - stdOut, stdErr, _, err = exec.Cmd("git", gitDirFlag, "log", "HEAD^..HEAD", "--oneline", "--decorate") + stdOut, stdErr, err = exec.Cmd("git", gitDirFlag, "log", "HEAD^..HEAD", "--oneline", "--decorate") require.NoError(t, err, stdOut, stdErr) require.Contains(t, stdOut, "(HEAD -> zarf-ref-c74e2e9626da0400e0a41e78319b3054c53a5d4e, tag: v0.21.3) Re-add docker buildx for release pipeilne") } diff --git a/src/test/e2e/20_zarf_init_test.go b/src/test/e2e/20_zarf_init_test.go index 4d92544bdb..f4558e6c1a 100644 --- a/src/test/e2e/20_zarf_init_test.go +++ b/src/test/e2e/20_zarf_init_test.go @@ -35,48 +35,48 @@ func TestZarfInit(t *testing.T) { ) // Build init package with different arch than the cluster arch. - stdOut, stdErr, _, err := e2e.ExecZarfCommand("package", "create", ".", "--architecture", mismatchedArch, "--confirm") + stdOut, stdErr, err := e2e.ExecZarfCommand("package", "create", ".", "--architecture", mismatchedArch, "--confirm") require.NoError(t, err, stdOut, stdErr) defer e2e.CleanFiles(mismatchedInitPackage) // Check that `zarf init` fails in appliance mode when we try to initialize a k3s cluster // on a machine with a different architecture than the package architecture. // We need to use the --architecture flag here to force zarf to find the package. - _, stdErr, _, err = e2e.ExecZarfCommand("init", "--architecture", mismatchedArch, "--components=k3s", "--confirm") + _, stdErr, err = e2e.ExecZarfCommand("init", "--architecture", mismatchedArch, "--components=k3s", "--confirm") require.Error(t, err, stdErr) // run `zarf init` - _, stdErr, _, err = exec.CmdWithContext(ctx, exec.PrintCfg(), e2e.ZarfBinPath, "init", "--components="+initComponents, "--confirm", "--nodeport", "31337") + _, stdErr, err = exec.CmdWithContext(ctx, exec.PrintCfg(), e2e.ZarfBinPath, "init", "--components="+initComponents, "--confirm", "--nodeport", "31337") require.Contains(t, stdErr, "artifacts with software bill-of-materials (SBOM) included") require.NoError(t, err) // Check that gitea is actually running and healthy - stdOut, _, _, err = e2e.ExecZarfCommand("tools", "kubectl", "get", "pods", "-l", "app in (gitea)", "-n", "zarf", "-o", "jsonpath={.items[*].status.phase}") + stdOut, _, err = e2e.ExecZarfCommand("tools", "kubectl", "get", "pods", "-l", "app in (gitea)", "-n", "zarf", "-o", "jsonpath={.items[*].status.phase}") require.NoError(t, err) require.Contains(t, stdOut, "Running") // Check that the logging stack is actually running and healthy - stdOut, _, _, err = e2e.ExecZarfCommand("tools", "kubectl", "get", "pods", "-l", "app in (loki)", "-n", "zarf", "-o", "jsonpath={.items[*].status.phase}") + stdOut, _, err = e2e.ExecZarfCommand("tools", "kubectl", "get", "pods", "-l", "app in (loki)", "-n", "zarf", "-o", "jsonpath={.items[*].status.phase}") require.NoError(t, err) require.Contains(t, stdOut, "Running") - stdOut, _, _, err = e2e.ExecZarfCommand("tools", "kubectl", "get", "pods", "-l", "app.kubernetes.io/name in (grafana)", "-n", "zarf", "-o", "jsonpath={.items[*].status.phase}") + stdOut, _, err = e2e.ExecZarfCommand("tools", "kubectl", "get", "pods", "-l", "app.kubernetes.io/name in (grafana)", "-n", "zarf", "-o", "jsonpath={.items[*].status.phase}") require.NoError(t, err) require.Contains(t, stdOut, "Running") - stdOut, _, _, err = e2e.ExecZarfCommand("tools", "kubectl", "get", "pods", "-l", "app.kubernetes.io/name in (promtail)", "-n", "zarf", "-o", "jsonpath={.items[*].status.phase}") + stdOut, _, err = e2e.ExecZarfCommand("tools", "kubectl", "get", "pods", "-l", "app.kubernetes.io/name in (promtail)", "-n", "zarf", "-o", "jsonpath={.items[*].status.phase}") require.NoError(t, err) require.Contains(t, stdOut, "Running") // Check that the registry is running on the correct NodePort - stdOut, _, _, err = e2e.ExecZarfCommand("tools", "kubectl", "get", "service", "-n", "zarf", "zarf-docker-registry", "-o=jsonpath='{.spec.ports[*].nodePort}'") + stdOut, _, err = e2e.ExecZarfCommand("tools", "kubectl", "get", "service", "-n", "zarf", "zarf-docker-registry", "-o=jsonpath='{.spec.ports[*].nodePort}'") require.NoError(t, err) require.Contains(t, stdOut, "31337") // Check that the registry is running with the correct scale down policy - stdOut, _, _, err = e2e.ExecZarfCommand("tools", "kubectl", "get", "hpa", "-n", "zarf", "zarf-docker-registry", "-o=jsonpath='{.spec.behavior.scaleDown.selectPolicy}'") + stdOut, _, err = e2e.ExecZarfCommand("tools", "kubectl", "get", "hpa", "-n", "zarf", "zarf-docker-registry", "-o=jsonpath='{.spec.behavior.scaleDown.selectPolicy}'") require.NoError(t, err) require.Contains(t, stdOut, "Min") // Special sizing-hacking for reducing resources where Kind + CI eats a lot of free cycles (ignore errors) - _, _, _, _ = e2e.ExecZarfCommand("tools", "kubectl", "scale", "deploy", "-n", "kube-system", "coredns", "--replicas=1") - _, _, _, _ = e2e.ExecZarfCommand("tools", "kubectl", "scale", "deploy", "-n", "zarf", "agent-hook", "--replicas=1") + _, _, _ = e2e.ExecZarfCommand("tools", "kubectl", "scale", "deploy", "-n", "kube-system", "coredns", "--replicas=1") + _, _, _ = e2e.ExecZarfCommand("tools", "kubectl", "scale", "deploy", "-n", "zarf", "agent-hook", "--replicas=1") } diff --git a/src/test/e2e/21_connect_test.go b/src/test/e2e/21_connect_test.go index 6dab1718e4..74e7d5f73e 100644 --- a/src/test/e2e/21_connect_test.go +++ b/src/test/e2e/21_connect_test.go @@ -24,7 +24,7 @@ func TestConnect(t *testing.T) { defer e2e.Teardown(t) // Make the Registry contains the images we expect - stdOut, stdErr, _, err := e2e.ExecZarfCommand("tools", "registry", "catalog") + stdOut, stdErr, err := e2e.ExecZarfCommand("tools", "registry", "catalog") assert.NoError(t, err, stdOut, stdErr) registryList := strings.Split(strings.Trim(stdOut, "\n "), "\n") @@ -55,6 +55,6 @@ func TestConnect(t *testing.T) { assert.NoError(t, err) assert.Equal(t, 200, respLog.StatusCode) - stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "remove", "init", "--components=logging", "--confirm") + stdOut, stdErr, err = e2e.ExecZarfCommand("package", "remove", "init", "--components=logging", "--confirm") require.NoError(t, err, stdOut, stdErr) } diff --git a/src/test/e2e/22_git_and_flux_test.go b/src/test/e2e/22_git_and_flux_test.go index 25fdfb7f0a..89fc9223cb 100644 --- a/src/test/e2e/22_git_and_flux_test.go +++ b/src/test/e2e/22_git_and_flux_test.go @@ -25,7 +25,7 @@ func TestGitAndFlux(t *testing.T) { path := fmt.Sprintf("build/zarf-package-git-data-%s-v1.0.0.tar.zst", e2e.Arch) // Deploy the gitops example - stdOut, stdErr, _, err := e2e.ExecZarfCommand("package", "deploy", path, "--confirm") + stdOut, stdErr, err := e2e.ExecZarfCommand("package", "deploy", path, "--confirm") require.NoError(t, err, stdOut, stdErr) tunnel, err := cluster.NewZarfTunnel() @@ -38,10 +38,10 @@ func TestGitAndFlux(t *testing.T) { testGitServerTagAndHash(t, tunnel.HTTPEndpoint()) waitFluxPodInfoDeployment(t) - stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "remove", "flux-test", "--confirm") + stdOut, stdErr, err = e2e.ExecZarfCommand("package", "remove", "flux-test", "--confirm") require.NoError(t, err, stdOut, stdErr) - stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "remove", "init", "--components=git-server", "--confirm") + stdOut, stdErr, err = e2e.ExecZarfCommand("package", "remove", "init", "--components=git-server", "--confirm") require.NoError(t, err, stdOut, stdErr) } @@ -104,9 +104,9 @@ func testGitServerTagAndHash(t *testing.T, gitURL string) { func waitFluxPodInfoDeployment(t *testing.T) { // Deploy the flux example and verify that it works path := fmt.Sprintf("build/zarf-package-flux-test-%s.tar.zst", e2e.Arch) - stdOut, stdErr, _, err := e2e.ExecZarfCommand("package", "deploy", path, "--confirm") + stdOut, stdErr, err := e2e.ExecZarfCommand("package", "deploy", path, "--confirm") require.NoError(t, err, stdOut, stdErr) - kubectlOut, _, _, _ := e2e.ExecZarfCommand("tools", "kubectl", "-n=podinfo", "rollout", "status", "deployment/podinfo") + kubectlOut, _, _ := e2e.ExecZarfCommand("tools", "kubectl", "-n=podinfo", "rollout", "status", "deployment/podinfo") assert.Contains(t, string(kubectlOut), "successfully rolled out") } diff --git a/src/test/e2e/23_data_injection_test.go b/src/test/e2e/23_data_injection_test.go index 70e810068e..740d8d0fdb 100644 --- a/src/test/e2e/23_data_injection_test.go +++ b/src/test/e2e/23_data_injection_test.go @@ -28,12 +28,12 @@ func TestDataInjection(t *testing.T) { } // Verify the file and injection marker were created - stdOut, stdErr, _, err := exec.CmdWithContext(context.TODO(), exec.PrintCfg(), "kubectl", "--namespace=demo", "logs", "--tail=5", "--selector=app=data-injection", "-c=data-injection") + stdOut, stdErr, err := exec.CmdWithContext(context.TODO(), exec.PrintCfg(), "kubectl", "--namespace=demo", "logs", "--tail=5", "--selector=app=data-injection", "-c=data-injection") require.NoError(t, err, stdOut, stdErr) assert.Contains(t, stdOut, "this-is-an-example-file.txt") assert.Contains(t, stdOut, ".zarf-injection-") - stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "remove", "data-injection-demo", "--confirm") + stdOut, stdErr, err = e2e.ExecZarfCommand("package", "remove", "data-injection-demo", "--confirm") require.NoError(t, err, stdOut, stdErr) } @@ -43,6 +43,6 @@ func runDataInjection(t *testing.T, path string) { defer cancel() // Deploy the data injection example - stdOut, stdErr, _, err := exec.CmdWithContext(ctx, exec.PrintCfg(), e2e.ZarfBinPath, "package", "deploy", path, "--confirm") + stdOut, stdErr, err := exec.CmdWithContext(ctx, exec.PrintCfg(), e2e.ZarfBinPath, "package", "deploy", path, "--confirm") require.NoError(t, err, stdOut, stdErr) } diff --git a/src/test/e2e/24_variables_test.go b/src/test/e2e/24_variables_test.go index c94fbd57a9..686a083a8c 100644 --- a/src/test/e2e/24_variables_test.go +++ b/src/test/e2e/24_variables_test.go @@ -24,12 +24,12 @@ func TestVariables(t *testing.T) { e2e.CleanFiles(tfPath) // Test that not specifying a prompted variable results in an error - _, stdErr, _, _ := e2e.ExecZarfCommand("package", "deploy", path, "--confirm") + _, stdErr, _ := e2e.ExecZarfCommand("package", "deploy", path, "--confirm") expectedOutString := "variable 'SITE_NAME' must be '--set' when using the '--confirm' flag" require.Contains(t, stdErr, "", expectedOutString) // Deploy nginx - stdOut, stdErr, _, err := e2e.ExecZarfCommand("package", "deploy", path, "--confirm", "--set", "SITE_NAME=Lula Web", "--set", "AWS_REGION=unicorn-land", "-l", "trace") + stdOut, stdErr, err := e2e.ExecZarfCommand("package", "deploy", path, "--confirm", "--set", "SITE_NAME=Lula Web", "--set", "AWS_REGION=unicorn-land", "-l", "trace") require.NoError(t, err, stdOut, stdErr) // Verify that unicorn-land was not included in the log require.NotContains(t, stdErr, "unicorn-land") @@ -40,7 +40,7 @@ func TestVariables(t *testing.T) { require.Contains(t, string(outputTF), "unicorn-land") // Verify the configmap was properly templated - kubectlOut, _, _, _ := e2e.ExecZarfCommand("tools", "kubectl", "-n", "nginx", "get", "configmap", "nginx-configmap", "-o", "jsonpath='{.data.index\\.html}' ") + kubectlOut, _, _ := e2e.ExecZarfCommand("tools", "kubectl", "-n", "nginx", "get", "configmap", "nginx-configmap", "-o", "jsonpath='{.data.index\\.html}' ") // OPTIONAL_FOOTER should remain unset because it was not set during deploy assert.Contains(t, string(kubectlOut), "\n \n ") // STYLE should take the default value @@ -53,11 +53,11 @@ func TestVariables(t *testing.T) { assert.Contains(t, string(kubectlOut), "unicorn-land") // Verify that the nginx deployment was successful (the NGINX_VERSION constant templated the image correctly) - kubectlOut, _, _, err = e2e.ExecZarfCommand("tools", "kubectl", "get", "pods", "-l", "app in (nginx)", "-n", "nginx", "-o", "jsonpath={.items[*].status.phase}") + kubectlOut, _, err = e2e.ExecZarfCommand("tools", "kubectl", "get", "pods", "-l", "app in (nginx)", "-n", "nginx", "-o", "jsonpath={.items[*].status.phase}") require.NoError(t, err) require.Contains(t, kubectlOut, "Running") - stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "remove", path, "--confirm") + stdOut, stdErr, err = e2e.ExecZarfCommand("package", "remove", path, "--confirm") require.NoError(t, err, stdOut, stdErr) e2e.CleanFiles(tfPath) diff --git a/src/test/e2e/25_helm_test.go b/src/test/e2e/25_helm_test.go index ac10ff8dba..e5a49c14df 100644 --- a/src/test/e2e/25_helm_test.go +++ b/src/test/e2e/25_helm_test.go @@ -37,7 +37,7 @@ func testHelmReleaseName(t *testing.T) { path := fmt.Sprintf("build/zarf-package-test-helm-releasename-%s.tar.zst", e2e.Arch) // Deploy the package. - stdOut, stdErr, _, err := e2e.ExecZarfCommand("package", "deploy", path, "--confirm") + stdOut, stdErr, err := e2e.ExecZarfCommand("package", "deploy", path, "--confirm") require.NoError(t, err, stdOut, stdErr) // Verify multiple helm installs of different release names were deployed. @@ -45,7 +45,7 @@ func testHelmReleaseName(t *testing.T) { assert.Contains(t, string(kubectlOut), "cool-name-podinfo") // Remove the package. - stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "remove", "test-helm-releasename", "--confirm") + stdOut, stdErr, err = e2e.ExecZarfCommand("package", "remove", "test-helm-releasename", "--confirm") require.NoError(t, err, stdOut, stdErr) } @@ -55,15 +55,15 @@ func testHelmLocalChart(t *testing.T) { path := fmt.Sprintf("build/zarf-package-test-helm-local-chart-%s.tar.zst", e2e.Arch) // Deploy the package. - stdOut, stdErr, _, err := e2e.ExecZarfCommand("package", "deploy", path, "--confirm") + stdOut, stdErr, err := e2e.ExecZarfCommand("package", "deploy", path, "--confirm") require.NoError(t, err, stdOut, stdErr) // Verify that nginx successfully deploys in the cluster - kubectlOut, _, _, _ := e2e.ExecZarfCommand("tools", "kubectl", "-n=local-chart", "rollout", "status", "deployment/local-demo") + kubectlOut, _, _ := e2e.ExecZarfCommand("tools", "kubectl", "-n=local-chart", "rollout", "status", "deployment/local-demo") assert.Contains(t, string(kubectlOut), "successfully rolled out") // Remove the package. - stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "remove", "test-helm-local-chart", "--confirm") + stdOut, stdErr, err = e2e.ExecZarfCommand("package", "remove", "test-helm-local-chart", "--confirm") require.NoError(t, err, stdOut, stdErr) } @@ -71,13 +71,13 @@ func testHelmEscaping(t *testing.T) { t.Log("E2E: Helm chart escaping") // Create the package. - stdOut, stdErr, _, err := e2e.ExecZarfCommand("package", "create", "src/test/test-packages/25-evil-templates/", "--confirm") + stdOut, stdErr, err := e2e.ExecZarfCommand("package", "create", "src/test/test-packages/25-evil-templates/", "--confirm") require.NoError(t, err, stdOut, stdErr) path := fmt.Sprintf("zarf-package-evil-templates-%s.tar.zst", e2e.Arch) // Deploy the package. - stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "deploy", path, "--confirm") + stdOut, stdErr, err = e2e.ExecZarfCommand("package", "deploy", path, "--confirm") require.NoError(t, err, stdOut, stdErr) // Verify the configmap was deployed and escaped. @@ -88,7 +88,7 @@ func testHelmEscaping(t *testing.T) { assert.Contains(t, string(kubectlOut), `description: Pod {{$labels.pod}} in {{$labels.namespace}} got OOMKilled`) // Remove the package. - stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "remove", "evil-templates", "--confirm") + stdOut, stdErr, err = e2e.ExecZarfCommand("package", "remove", "evil-templates", "--confirm") require.NoError(t, err, stdOut, stdErr) } @@ -98,17 +98,17 @@ func testHelmOCIChart(t *testing.T) { path := fmt.Sprintf("build/zarf-package-helm-oci-chart-%s-0.0.1.tar.zst", e2e.Arch) // Deploy the package. - stdOut, stdErr, _, err := e2e.ExecZarfCommand("package", "deploy", path, "--confirm") + stdOut, stdErr, err := e2e.ExecZarfCommand("package", "deploy", path, "--confirm") require.NoError(t, err, stdOut, stdErr) // Verify that podinfo successfully deploys in the cluster - kubectlOut, _, _, _ := e2e.ExecZarfCommand("tools", "kubectl", "-n=helm-oci-demo", "rollout", "status", "deployment/podinfo") + kubectlOut, _, _ := e2e.ExecZarfCommand("tools", "kubectl", "-n=helm-oci-demo", "rollout", "status", "deployment/podinfo") assert.Contains(t, string(kubectlOut), "successfully rolled out") - kubectlOut, _, _, _ = e2e.ExecZarfCommand("tools", "kubectl", "-n=helm-oci-demo", "get", "deployment", "podinfo", "-o=jsonpath={.metadata.labels}") + kubectlOut, _, _ = e2e.ExecZarfCommand("tools", "kubectl", "-n=helm-oci-demo", "get", "deployment", "podinfo", "-o=jsonpath={.metadata.labels}") assert.Contains(t, string(kubectlOut), "6.3.3") // Remove the package. - stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "remove", "helm-oci-chart", "--confirm") + stdOut, stdErr, err = e2e.ExecZarfCommand("package", "remove", "helm-oci-chart", "--confirm") require.NoError(t, err, stdOut, stdErr) } @@ -119,11 +119,11 @@ func testHelmUninstallRollback(t *testing.T) { evilPath := fmt.Sprintf("zarf-package-dos-games-%s.tar.zst", e2e.Arch) // Create the evil package (with the bad configmap). - stdOut, stdErr, _, err := e2e.ExecZarfCommand("package", "create", "src/test/test-packages/25-evil-dos-games/", "--confirm") + stdOut, stdErr, err := e2e.ExecZarfCommand("package", "create", "src/test/test-packages/25-evil-dos-games/", "--confirm") require.NoError(t, err, stdOut, stdErr) // Deploy the evil package. - stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "deploy", evilPath, "--confirm") + stdOut, stdErr, err = e2e.ExecZarfCommand("package", "deploy", evilPath, "--confirm") require.Error(t, err, stdOut, stdErr) // Ensure that this does not leave behind a dos-games chart @@ -132,7 +132,7 @@ func testHelmUninstallRollback(t *testing.T) { assert.NotContains(t, string(helmOut), "zarf-f53a99d4a4dd9a3575bedf59cd42d48d751ae866") // Deploy the good package. - stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "deploy", goodPath, "--confirm") + stdOut, stdErr, err = e2e.ExecZarfCommand("package", "deploy", goodPath, "--confirm") require.NoError(t, err, stdOut, stdErr) // Ensure that this does create a dos-games chart @@ -141,7 +141,7 @@ func testHelmUninstallRollback(t *testing.T) { assert.Contains(t, string(helmOut), "zarf-f53a99d4a4dd9a3575bedf59cd42d48d751ae866") // Deploy the evil package. - stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "deploy", evilPath, "--confirm") + stdOut, stdErr, err = e2e.ExecZarfCommand("package", "deploy", evilPath, "--confirm") require.Error(t, err, stdOut, stdErr) // Ensure that the dos-games chart was not uninstalled @@ -150,7 +150,7 @@ func testHelmUninstallRollback(t *testing.T) { assert.Contains(t, string(helmOut), "zarf-f53a99d4a4dd9a3575bedf59cd42d48d751ae866") // Remove the package. - stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "remove", "dos-games", "--confirm") + stdOut, stdErr, err = e2e.ExecZarfCommand("package", "remove", "dos-games", "--confirm") require.NoError(t, err, stdOut, stdErr) } @@ -161,11 +161,11 @@ func testHelmAdoption(t *testing.T) { deploymentManifest := "src/test/test-packages/25-manifest-adoption/deployment.yaml" // Deploy dos-games manually into the cluster without Zarf - kubectlOut, _, _, _ := e2e.ExecZarfCommand("tools", "kubectl", "apply", "-f", deploymentManifest) + kubectlOut, _, _ := e2e.ExecZarfCommand("tools", "kubectl", "apply", "-f", deploymentManifest) assert.Contains(t, string(kubectlOut), "deployment.apps/game created") // Deploy dos-games into the cluster with Zarf - stdOut, stdErr, _, err := e2e.ExecZarfCommand("package", "deploy", packagePath, "--confirm", "--adopt-existing-resources") + stdOut, stdErr, err := e2e.ExecZarfCommand("package", "deploy", packagePath, "--confirm", "--adopt-existing-resources") require.NoError(t, err, stdOut, stdErr) // Ensure that this does create a dos-games chart @@ -174,6 +174,6 @@ func testHelmAdoption(t *testing.T) { assert.Contains(t, string(helmOut), "zarf-f53a99d4a4dd9a3575bedf59cd42d48d751ae866") // Remove the package. - stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "remove", "dos-games", "--confirm") + stdOut, stdErr, err = e2e.ExecZarfCommand("package", "remove", "dos-games", "--confirm") require.NoError(t, err, stdOut, stdErr) } diff --git a/src/test/e2e/26_simple_packages_test.go b/src/test/e2e/26_simple_packages_test.go index 651ade182b..063d93b514 100644 --- a/src/test/e2e/26_simple_packages_test.go +++ b/src/test/e2e/26_simple_packages_test.go @@ -22,7 +22,7 @@ func TestDosGames(t *testing.T) { path := fmt.Sprintf("build/zarf-package-dos-games-%s.tar.zst", e2e.Arch) // Deploy the game - stdOut, stdErr, _, err := e2e.ExecZarfCommand("package", "deploy", path, "--confirm") + stdOut, stdErr, err := e2e.ExecZarfCommand("package", "deploy", path, "--confirm") require.NoError(t, err, stdOut, stdErr) tunnel, err := cluster.NewZarfTunnel() @@ -35,7 +35,7 @@ func TestDosGames(t *testing.T) { assert.NoError(t, err, resp) assert.Equal(t, 200, resp.StatusCode) - stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "remove", "dos-games", "--confirm") + stdOut, stdErr, err = e2e.ExecZarfCommand("package", "remove", "dos-games", "--confirm") require.NoError(t, err, stdOut, stdErr) } @@ -47,10 +47,10 @@ func TestRemoteManifests(t *testing.T) { path := fmt.Sprintf("build/zarf-package-remote-manifests-%s-0.0.1.tar.zst", e2e.Arch) // Deploy the package - stdOut, stdErr, _, err := e2e.ExecZarfCommand("package", "deploy", path, "--confirm") + stdOut, stdErr, err := e2e.ExecZarfCommand("package", "deploy", path, "--confirm") require.NoError(t, err, stdOut, stdErr) // Remove the package - stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "remove", "remote-manifests", "--confirm") + stdOut, stdErr, err = e2e.ExecZarfCommand("package", "remove", "remote-manifests", "--confirm") require.NoError(t, err, stdOut, stdErr) } diff --git a/src/test/e2e/27_cosign_deploy_test.go b/src/test/e2e/27_cosign_deploy_test.go index 8aaf6b06a1..086ac57329 100644 --- a/src/test/e2e/27_cosign_deploy_test.go +++ b/src/test/e2e/27_cosign_deploy_test.go @@ -21,9 +21,9 @@ func TestCosignDeploy(t *testing.T) { // Test with command from https://zarf.dev/install/ command := fmt.Sprintf("%s package deploy sget://defenseunicorns/zarf-hello-world:$(uname -m) --confirm", e2e.ZarfBinPath) - stdOut, stdErr, _, err := exec.CmdWithContext(context.TODO(), exec.PrintCfg(), "sh", "-c", command) + stdOut, stdErr, err := exec.CmdWithContext(context.TODO(), exec.PrintCfg(), "sh", "-c", command) require.NoError(t, err, stdOut, stdErr) - stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "remove", "dos-games", "--confirm") + stdOut, stdErr, err = e2e.ExecZarfCommand("package", "remove", "dos-games", "--confirm") require.NoError(t, err, stdOut, stdErr) } diff --git a/src/test/e2e/28_wait_test.go b/src/test/e2e/28_wait_test.go index f1e6714ca9..ef9aee3ed1 100644 --- a/src/test/e2e/28_wait_test.go +++ b/src/test/e2e/28_wait_test.go @@ -25,7 +25,7 @@ type zarfCommandResult struct { } func zarfCommandWStruct(e2e test.ZarfE2ETest, path string) (result zarfCommandResult) { - result.stdOut, result.stdErr, _, result.err = e2e.ExecZarfCommand("package", "deploy", path, "--confirm") + result.stdOut, result.stdErr, result.err = e2e.ExecZarfCommand("package", "deploy", path, "--confirm") return result } @@ -62,6 +62,6 @@ func TestWait(t *testing.T) { } require.NoError(t, err, stdOut, stdErr) - stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "remove", "test-helm-wait", "--confirm") + stdOut, stdErr, err = e2e.ExecZarfCommand("package", "remove", "test-helm-wait", "--confirm") require.NoError(t, err, stdOut, stdErr) } diff --git a/src/test/e2e/29_mismatched_architectures_test.go b/src/test/e2e/29_mismatched_architectures_test.go index fda444f93a..d01291dd4b 100644 --- a/src/test/e2e/29_mismatched_architectures_test.go +++ b/src/test/e2e/29_mismatched_architectures_test.go @@ -27,23 +27,23 @@ func TestMismatchedArchitectures(t *testing.T) { ) // Build init package with different arch than the cluster arch. - stdOut, stdErr, _, err := e2e.ExecZarfCommand("package", "create", ".", "--architecture", mismatchedArch, "--confirm") + stdOut, stdErr, err := e2e.ExecZarfCommand("package", "create", ".", "--architecture", mismatchedArch, "--confirm") require.NoError(t, err, stdOut, stdErr) defer e2e.CleanFiles(mismatchedInitPackage) // Build dos-games package with different arch than the cluster arch. - stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "create", "examples/dos-games/", "--architecture", mismatchedArch, "--confirm") + stdOut, stdErr, err = e2e.ExecZarfCommand("package", "create", "examples/dos-games/", "--architecture", mismatchedArch, "--confirm") require.NoError(t, err, stdOut, stdErr) defer e2e.CleanFiles(mismatchedGamesPackage) // Ensure zarf init returns an error because of the mismatched architectures. // We need to use the --architecture flag here to force zarf to find the package. - _, stdErr, _, err = e2e.ExecZarfCommand("init", "--architecture", mismatchedArch, "--confirm") + _, stdErr, err = e2e.ExecZarfCommand("init", "--architecture", mismatchedArch, "--confirm") require.Error(t, err, stdErr) require.Contains(t, stdErr, expectedErrorMessage) // Ensure zarf package deploy returns an error because of the mismatched architectures. - _, stdErr, _, err = e2e.ExecZarfCommand("package", "deploy", mismatchedGamesPackage, "--confirm") + _, stdErr, err = e2e.ExecZarfCommand("package", "deploy", mismatchedGamesPackage, "--confirm") require.Error(t, err, stdErr) require.Contains(t, stdErr, expectedErrorMessage) } diff --git a/src/test/e2e/30_config_file_test.go b/src/test/e2e/30_config_file_test.go index f58decdf75..beef3aff5d 100644 --- a/src/test/e2e/30_config_file_test.go +++ b/src/test/e2e/30_config_file_test.go @@ -33,26 +33,26 @@ func TestConfigFile(t *testing.T) { configFileDefaultTests(t) - stdOut, stdErr, _, err := e2e.ExecZarfCommand("package", "remove", path, "--confirm") + stdOut, stdErr, err := e2e.ExecZarfCommand("package", "remove", path, "--confirm") require.NoError(t, err, stdOut, stdErr) e2e.CleanFiles(path) } func configFileTests(t *testing.T, dir, path string) { - _, stdErr, _, err := e2e.ExecZarfCommand("package", "create", dir, "--confirm") + _, stdErr, err := e2e.ExecZarfCommand("package", "create", dir, "--confirm") require.NoError(t, err) require.Contains(t, string(stdErr), "This is a zebra and they have stripes") require.Contains(t, string(stdErr), "This is a leopard and they have spots") - _, stdErr, _, err = e2e.ExecZarfCommand("package", "deploy", path, "--confirm") + _, stdErr, err = e2e.ExecZarfCommand("package", "deploy", path, "--confirm") require.NoError(t, err) require.Contains(t, string(stdErr), "📦 LION COMPONENT") require.NotContains(t, string(stdErr), "📦 LEOPARD COMPONENT") require.NotContains(t, string(stdErr), "📦 ZEBRA COMPONENT") // Verify the configmap was properly templated - kubectlOut, _, _, err := e2e.ExecZarfCommand("tools", "kubectl", "-n", "zarf", "get", "configmap", "simple-configmap", "-o", "jsonpath='{.data.templateme\\.properties}'") + kubectlOut, _, err := e2e.ExecZarfCommand("tools", "kubectl", "-n", "zarf", "get", "configmap", "simple-configmap", "-o", "jsonpath='{.data.templateme\\.properties}'") require.NoError(t, err) require.Contains(t, string(kubectlOut), "scorpion=iridescent") require.Contains(t, string(kubectlOut), "camel_spider=matte") @@ -105,25 +105,25 @@ func configFileDefaultTests(t *testing.T) { os.Setenv("ZARF_CONFIG", filepath.Join("src", "test", "zarf-config-test.toml")) // Test global flags - stdOut, _, _, _ := e2e.ExecZarfCommand("--help") + stdOut, _, _ := e2e.ExecZarfCommand("--help") for _, test := range globalFlags { require.Contains(t, string(stdOut), test) } // Test init flags - stdOut, _, _, _ = e2e.ExecZarfCommand("init", "--help") + stdOut, _, _ = e2e.ExecZarfCommand("init", "--help") for _, test := range initFlags { require.Contains(t, string(stdOut), test) } // Test package create flags - stdOut, _, _, _ = e2e.ExecZarfCommand("package", "create", "--help") + stdOut, _, _ = e2e.ExecZarfCommand("package", "create", "--help") for _, test := range packageCreateFlags { require.Contains(t, string(stdOut), test) } // Test package deploy flags - stdOut, _, _, _ = e2e.ExecZarfCommand("package", "deploy", "--help") + stdOut, _, _ = e2e.ExecZarfCommand("package", "deploy", "--help") for _, test := range packageDeployFlags { require.Contains(t, string(stdOut), test) } diff --git a/src/test/e2e/31_component_action_remove_test.go b/src/test/e2e/31_component_action_remove_test.go index a27ffce72b..1cd02facb9 100644 --- a/src/test/e2e/31_component_action_remove_test.go +++ b/src/test/e2e/31_component_action_remove_test.go @@ -18,10 +18,10 @@ func TestComponentActionRemove(t *testing.T) { path := fmt.Sprintf("build/zarf-package-component-actions-%s.tar.zst", e2e.Arch) - stdOut, stdErr, _, err := e2e.ExecZarfCommand("package", "deploy", path, "--confirm", "--components=on-remove") + stdOut, stdErr, err := e2e.ExecZarfCommand("package", "deploy", path, "--confirm", "--components=on-remove") require.NoError(t, err, stdOut, stdErr) - stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "remove", path, "--confirm", "--components=on-remove") + stdOut, stdErr, err = e2e.ExecZarfCommand("package", "remove", path, "--confirm", "--components=on-remove") require.NoError(t, err, stdOut, stdErr) require.Contains(t, stdErr, "NAME") require.Contains(t, stdErr, "DATA") diff --git a/src/test/e2e/32_checksum_and_signature_test.go b/src/test/e2e/32_checksum_and_signature_test.go index 05df56763e..c64824910e 100644 --- a/src/test/e2e/32_checksum_and_signature_test.go +++ b/src/test/e2e/32_checksum_and_signature_test.go @@ -21,28 +21,28 @@ func TestChecksumAndSignature(t *testing.T) { privateKeyFlag := "--key=src/test/test-packages/zarf-test.prv-key" publicKeyFlag := "--key=src/test/test-packages/zarf-test.pub" - stdOut, stdErr, _, err := e2e.ExecZarfCommand("package", "create", testPackageDirPath, privateKeyFlag, "--confirm") + stdOut, stdErr, err := e2e.ExecZarfCommand("package", "create", testPackageDirPath, privateKeyFlag, "--confirm") require.NoError(t, err, stdOut, stdErr) defer e2e.CleanFiles(pkgName) /* Test operations during package inspect */ // Test that we can inspect the yaml of the package without the private key - stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "inspect", pkgName) + stdOut, stdErr, err = e2e.ExecZarfCommand("package", "inspect", pkgName) require.NoError(t, err, stdOut, stdErr) // Test that we don't get an error when we remember to provide the public key - stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "inspect", pkgName, publicKeyFlag) + stdOut, stdErr, err = e2e.ExecZarfCommand("package", "inspect", pkgName, publicKeyFlag) require.NoError(t, err, stdOut, stdErr) require.Contains(t, stdErr, "Verified OK") /* Test operations during package deploy */ // Test that we get an error when trying to deploy a package without providing the public key - stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "deploy", pkgName, "--confirm") + stdOut, stdErr, err = e2e.ExecZarfCommand("package", "deploy", pkgName, "--confirm") require.Error(t, err, stdOut, stdErr) require.Contains(t, stdErr, "Failed to deploy package: package is signed but no key was provided") // Test that we don't get an error when we remember to provide the public key - stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "deploy", pkgName, publicKeyFlag, "--confirm") + stdOut, stdErr, err = e2e.ExecZarfCommand("package", "deploy", pkgName, publicKeyFlag, "--confirm") require.NoError(t, err, stdOut, stdErr) require.Contains(t, stdErr, "Zarf deployment complete") } diff --git a/src/test/e2e/40_deprecated_component_scripts_test.go b/src/test/e2e/40_deprecated_component_scripts_test.go index ee8a95eda4..001003e65d 100644 --- a/src/test/e2e/40_deprecated_component_scripts_test.go +++ b/src/test/e2e/40_deprecated_component_scripts_test.go @@ -32,7 +32,7 @@ func TestDeprecatedComponentScripts(t *testing.T) { // 1. Try creating the package to test the create scripts testPackagePath := fmt.Sprintf("%s/zarf-package-deprecated-component-scripts-%s.tar.zst", testPackageDirPath, e2e.Arch) outputFlag := fmt.Sprintf("-o=%s", testPackageDirPath) - stdOut, stdErr, _, err := e2e.ExecZarfCommand("package", "create", testPackageDirPath, outputFlag, "--confirm") + stdOut, stdErr, err := e2e.ExecZarfCommand("package", "create", testPackageDirPath, outputFlag, "--confirm") defer e2e.CleanFiles(testPackagePath) require.NoError(t, err, stdOut, stdErr) require.Contains(t, stdErr, "Component '1-test-deprecated-prepare-scripts' is using scripts") @@ -48,7 +48,7 @@ func TestDeprecatedComponentScripts(t *testing.T) { } // 2. Deploy the simple script that should pass - stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "deploy", testPackagePath, "--confirm", "--components=2-test-deprecated-deploy-scripts") + stdOut, stdErr, err = e2e.ExecZarfCommand("package", "deploy", testPackagePath, "--confirm", "--components=2-test-deprecated-deploy-scripts") require.NoError(t, err, stdOut, stdErr) // Check that the deploy artifacts were created @@ -57,6 +57,6 @@ func TestDeprecatedComponentScripts(t *testing.T) { } // 3. Deploy the simple script that should fail the timeout - stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "deploy", testPackagePath, "--confirm", "--components=3-test-deprecated-timeout-scripts") + stdOut, stdErr, err = e2e.ExecZarfCommand("package", "deploy", testPackagePath, "--confirm", "--components=3-test-deprecated-timeout-scripts") require.Error(t, err, stdOut, stdErr) } diff --git a/src/test/e2e/41_deprecations_set_variables_test.go b/src/test/e2e/41_deprecations_set_variables_test.go index dc3631ac78..57465e7acf 100644 --- a/src/test/e2e/41_deprecations_set_variables_test.go +++ b/src/test/e2e/41_deprecations_set_variables_test.go @@ -33,24 +33,24 @@ func TestDeprecatedSetAndPackageVariables(t *testing.T) { outputFlag := fmt.Sprintf("-o=%s", testPackageDirPath) // Check that the command still errors out - stdOut, stdErr, _, err := e2e.ExecZarfCommand("package", "create", testPackageDirPath, outputFlag, "--confirm") + stdOut, stdErr, err := e2e.ExecZarfCommand("package", "create", testPackageDirPath, outputFlag, "--confirm") require.Error(t, err, stdOut, stdErr) require.Contains(t, stdErr, "template 'ECHO' must be '--set'") // Check that the command displays a warning on create - stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "create", testPackageDirPath, outputFlag, "--confirm", "--set", "ECHO=Zarf-The-Axolotl") + stdOut, stdErr, err = e2e.ExecZarfCommand("package", "create", testPackageDirPath, outputFlag, "--confirm", "--set", "ECHO=Zarf-The-Axolotl") defer e2e.CleanFiles(testPackagePath) require.NoError(t, err, stdOut, stdErr) require.Contains(t, stdErr, "Component '1-test-deprecated-set-variable' is using setVariable") require.Contains(t, stdErr, "deprecated syntax ###ZARF_PKG_VAR_ECHO###") // 1. Deploy the setVariable action that should pass and output the variable - stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "deploy", testPackagePath, "--confirm", "--components=1-test-deprecated-set-variable") + stdOut, stdErr, err = e2e.ExecZarfCommand("package", "deploy", testPackagePath, "--confirm", "--components=1-test-deprecated-set-variable") require.NoError(t, err, stdOut, stdErr) require.Contains(t, stdErr, "Hello from: Hello Kitteh") // 2. Deploy the setVariable action that should pass and output the variable - stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "deploy", testPackagePath, "--confirm", "--components=2-test-deprecated-pkg-var") + stdOut, stdErr, err = e2e.ExecZarfCommand("package", "deploy", testPackagePath, "--confirm", "--components=2-test-deprecated-pkg-var") require.NoError(t, err, stdOut, stdErr) require.Contains(t, stdErr, "Zarf-The-Axolotl") } diff --git a/src/test/e2e/50_oci_package_test.go b/src/test/e2e/50_oci_package_test.go index 690c39904d..22ceb7a9fe 100644 --- a/src/test/e2e/50_oci_package_test.go +++ b/src/test/e2e/50_oci_package_test.go @@ -39,7 +39,7 @@ func (suite *RegistryClientTestSuite) SetupSuite() { suite.NoError(err) if !cfg.ContainsAuth() { // make a docker config file w/ some blank creds - _, _, _, err := e2e.ExecZarfCommand("tools", "registry", "login", "--username", "zarf", "-p", "zarf", "localhost:6000") + _, _, err := e2e.ExecZarfCommand("tools", "registry", "login", "--username", "zarf", "-p", "zarf", "localhost:6000") suite.NoError(err) } @@ -52,10 +52,10 @@ func (suite *RegistryClientTestSuite) TearDownSuite() { local := fmt.Sprintf("zarf-package-helm-oci-chart-%s-0.0.1.tar.zst", e2e.Arch) e2e.CleanFiles(local) - stdOut, stdErr, _, err := e2e.ExecZarfCommand("package", "remove", "helm-oci-chart", "--confirm") + stdOut, stdErr, err := e2e.ExecZarfCommand("package", "remove", "helm-oci-chart", "--confirm") suite.NoError(err, stdOut, stdErr) - _, _, _, err = exec.Cmd("docker", "rm", "-f", "registry") + _, _, err = exec.Cmd("docker", "rm", "-f", "registry") suite.NoError(err) } @@ -65,13 +65,13 @@ func (suite *RegistryClientTestSuite) Test_0_Publish() { // Publish package. example := filepath.Join(suite.PackagesDir, fmt.Sprintf("zarf-package-helm-oci-chart-%s-0.0.1.tar.zst", e2e.Arch)) ref := suite.Reference.String() - stdOut, stdErr, _, err := e2e.ExecZarfCommand("package", "publish", example, "oci://"+ref, "--insecure") + stdOut, stdErr, err := e2e.ExecZarfCommand("package", "publish", example, "oci://"+ref, "--insecure") suite.NoError(err, stdOut, stdErr) suite.Contains(stdErr, "Published "+ref) // Publish w/ package missing `metadata.version` field. example = filepath.Join(suite.PackagesDir, fmt.Sprintf("zarf-package-dos-games-%s.tar.zst", e2e.Arch)) - _, stdErr, _, err = e2e.ExecZarfCommand("package", "publish", example, "oci://"+ref, "--insecure") + _, stdErr, err = e2e.ExecZarfCommand("package", "publish", example, "oci://"+ref, "--insecure") suite.Error(err, stdErr) } @@ -86,7 +86,7 @@ func (suite *RegistryClientTestSuite) Test_1_Pull() { ref := suite.Reference.String() // Pull the package via OCI. - stdOut, stdErr, _, err := e2e.ExecZarfCommand("package", "pull", "oci://"+ref, "--insecure") + stdOut, stdErr, err := e2e.ExecZarfCommand("package", "pull", "oci://"+ref, "--insecure") suite.NoError(err, stdOut, stdErr) suite.Contains(stdErr, "Pulled "+ref) @@ -94,7 +94,7 @@ func (suite *RegistryClientTestSuite) Test_1_Pull() { suite.FileExists(out) // Test pull w/ bad ref. - stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "pull", "oci://"+badRef.String(), "--insecure") + stdOut, stdErr, err = e2e.ExecZarfCommand("package", "pull", "oci://"+badRef.String(), "--insecure") suite.Error(err, stdOut, stdErr) } @@ -107,16 +107,16 @@ func (suite *RegistryClientTestSuite) Test_2_Deploy() { ref := suite.Reference.String() // Deploy the package via OCI. - stdOut, stdErr, _, err := e2e.ExecZarfCommand("package", "deploy", "oci://"+ref, "--insecure", "--confirm") + stdOut, stdErr, err := e2e.ExecZarfCommand("package", "deploy", "oci://"+ref, "--insecure", "--confirm") suite.NoError(err, stdOut, stdErr) suite.Contains(stdErr, "Pulled "+ref) - stdOut, stdErr, _, err = e2e.ExecZarfCommand("tools", "kubectl", "get", "pods", "-n=helm-oci-demo", "--no-headers") + stdOut, stdErr, err = e2e.ExecZarfCommand("tools", "kubectl", "get", "pods", "-n=helm-oci-demo", "--no-headers") suite.NoError(err, stdErr) suite.Contains(string(stdOut), "podinfo-") // Test deploy w/ bad ref. - _, stdErr, _, err = e2e.ExecZarfCommand("package", "deploy", "oci://"+badRef.String(), "--insecure", "--confirm") + _, stdErr, err = e2e.ExecZarfCommand("package", "deploy", "oci://"+badRef.String(), "--insecure", "--confirm") suite.Error(err, stdErr) } @@ -126,12 +126,12 @@ func (suite *RegistryClientTestSuite) Test_3_Inspect() { suite.Reference.Repository = "helm-oci-chart" suite.Reference.Reference = fmt.Sprintf("0.0.1-%s", e2e.Arch) ref := suite.Reference.String() - stdOut, stdErr, _, err := e2e.ExecZarfCommand("package", "inspect", "oci://"+ref, "--insecure") + stdOut, stdErr, err := e2e.ExecZarfCommand("package", "inspect", "oci://"+ref, "--insecure") suite.NoError(err, stdOut, stdErr) suite.Contains(stdErr, "Loading Zarf Package oci://"+ref) // Test inspect w/ bad ref. - _, stdErr, _, err = e2e.ExecZarfCommand("package", "inspect", "oci://"+badRef.String(), "--insecure") + _, stdErr, err = e2e.ExecZarfCommand("package", "inspect", "oci://"+badRef.String(), "--insecure") suite.Error(err, stdErr) } @@ -144,10 +144,10 @@ func (suite *RegistryClientTestSuite) Test_4_Pull_And_Deploy() { suite.FileExists(local) // Deploy the local package. - stdOut, stdErr, _, err := e2e.ExecZarfCommand("package", "deploy", local, "--confirm") + stdOut, stdErr, err := e2e.ExecZarfCommand("package", "deploy", local, "--confirm") suite.NoError(err, stdOut, stdErr) - stdOut, stdErr, _, err = e2e.ExecZarfCommand("tools", "kubectl", "get", "pods", "-n=helm-oci-demo", "--no-headers") + stdOut, stdErr, err = e2e.ExecZarfCommand("tools", "kubectl", "get", "pods", "-n=helm-oci-demo", "--no-headers") suite.NoError(err, stdErr) suite.Contains(string(stdOut), "podinfo-") } diff --git a/src/test/e2e/99_yolo_test.go b/src/test/e2e/99_yolo_test.go index 791e7eb7c7..69a3c14c55 100644 --- a/src/test/e2e/99_yolo_test.go +++ b/src/test/e2e/99_yolo_test.go @@ -26,13 +26,13 @@ func TestYOLOMode(t *testing.T) { defer e2e.Teardown(t) // Destroy the cluster to test Zarf cleaning up after itself - stdOut, stdErr, _, err := e2e.ExecZarfCommand("destroy", "--confirm", "--remove-components") + stdOut, stdErr, err := e2e.ExecZarfCommand("destroy", "--confirm", "--remove-components") require.NoError(t, err, stdOut, stdErr) path := fmt.Sprintf("build/zarf-package-yolo-%s.tar.zst", e2e.Arch) // Deploy the YOLO package - stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "deploy", path, "--confirm") + stdOut, stdErr, err = e2e.ExecZarfCommand("package", "deploy", path, "--confirm") require.NoError(t, err, stdOut, stdErr) tunnel, err := cluster.NewZarfTunnel() @@ -45,6 +45,6 @@ func TestYOLOMode(t *testing.T) { assert.NoError(t, err, resp) assert.Equal(t, 200, resp.StatusCode) - stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "remove", "yolo", "--confirm") + stdOut, stdErr, err = e2e.ExecZarfCommand("package", "remove", "yolo", "--confirm") require.NoError(t, err, stdOut, stdErr) } diff --git a/src/test/external-test/common.go b/src/test/external-test/common.go index 67c12aa469..eee17d0ed5 100644 --- a/src/test/external-test/common.go +++ b/src/test/external-test/common.go @@ -32,7 +32,7 @@ func verifyWaitSuccess(t *testing.T, timeoutMinutes time.Duration, cmd string, a // after delay, try running default: // Check information from the given command - stdOut, _, _, err := exec.CmdWithContext(context.TODO(), exec.PrintCfg(), cmd, args...) + stdOut, _, err := exec.CmdWithContext(context.TODO(), exec.PrintCfg(), cmd, args...) // Log error if err != nil { t.Log(string(stdOut), err) diff --git a/src/test/external-test/ext_in_cluster_init_test.go b/src/test/external-test/ext_in_cluster_init_test.go index 441c0dab95..091ce34113 100644 --- a/src/test/external-test/ext_in_cluster_init_test.go +++ b/src/test/external-test/ext_in_cluster_init_test.go @@ -69,6 +69,6 @@ func TestExtInClusterDeploy(t *testing.T) { success = verifyKubectlWaitSuccess(t, 2, podinfoWaitCmd, errorStr) assert.True(t, success, errorStr) - _, _, _, err = exec.CmdWithContext(context.TODO(), exec.PrintCfg(), zarfBinPath, "destroy", "--confirm") + _, _, err = exec.CmdWithContext(context.TODO(), exec.PrintCfg(), zarfBinPath, "destroy", "--confirm") require.NoError(t, err, "unable to teardown zarf") } diff --git a/src/test/nightly/ecr_publish_test.go b/src/test/nightly/ecr_publish_test.go index 869db096db..ec4324c100 100644 --- a/src/test/nightly/ecr_publish_test.go +++ b/src/test/nightly/ecr_publish_test.go @@ -51,37 +51,37 @@ func TestECRPublishing(t *testing.T) { keyFlag := fmt.Sprintf("--key=%s", "./src/test/test-packages/zarf-test.pub") // Build the package with our test signature - stdOut, stdErr, _, err := e2e.ExecZarfCommand("package", "create", "examples/helm-oci-chart", "--key=./src/test/test-packages/zarf-test.prv-key", "--confirm", fmt.Sprintf("-o=%s", tmpDir)) + stdOut, stdErr, err := e2e.ExecZarfCommand("package", "create", "examples/helm-oci-chart", "--key=./src/test/test-packages/zarf-test.prv-key", "--confirm", fmt.Sprintf("-o=%s", tmpDir)) require.NoError(t, err, stdOut, stdErr) require.FileExists(t, testPackageLocation) // Validate that we can publish the package to ECR without an issue - stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "publish", testPackageLocation, registryURL) + stdOut, stdErr, err = e2e.ExecZarfCommand("package", "publish", testPackageLocation, registryURL) require.NoError(t, err, stdOut, stdErr) // Ensure we get a warning when trying to inspect the online published package - stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "inspect", upstreamPackageURL, keyFlag) + stdOut, stdErr, err = e2e.ExecZarfCommand("package", "inspect", upstreamPackageURL, keyFlag) require.NoError(t, err, stdOut, stdErr) require.Contains(t, stdErr, "Zarf is unable to validate the checksums of remote OCI packages.") require.Contains(t, stdErr, "Package signature validated!") // Ensure we get an error when trying to pull the package without providing the public key - stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "pull", upstreamPackageURL) + stdOut, stdErr, err = e2e.ExecZarfCommand("package", "pull", upstreamPackageURL) require.Error(t, err, stdOut, stdErr) //TODO: look for a specific error instead of just allowing ANY error // Validate that we can pull the package down from ECR - stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "pull", upstreamPackageURL, keyFlag) + stdOut, stdErr, err = e2e.ExecZarfCommand("package", "pull", upstreamPackageURL, keyFlag) require.NoError(t, err, stdOut, stdErr) defer e2e.CleanFiles(testPackageFileName) // Ensure we get a warning when trying to inspect the package without providing the public key - stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "inspect", testPackageFileName) + stdOut, stdErr, err = e2e.ExecZarfCommand("package", "inspect", testPackageFileName) require.NoError(t, err, stdOut, stdErr) require.Contains(t, stdErr, "The package you are inspecting has been signed but a public key was not provided.") require.Contains(t, stdErr, "All of the checksums matched!") // Validate that we get no warnings when inspecting the package while providing the public key - stdOut, stdErr, _, err = e2e.ExecZarfCommand("package", "inspect", testPackageFileName, keyFlag) + stdOut, stdErr, err = e2e.ExecZarfCommand("package", "inspect", testPackageFileName, keyFlag) require.NoError(t, err, stdOut, stdErr) require.Contains(t, stdErr, "All of the checksums matched!") require.Contains(t, stdErr, "Package signature validated!") diff --git a/src/test/upgrade-test/previously_built_test.go b/src/test/upgrade-test/previously_built_test.go index 4a0edb8cb7..037fd9562e 100644 --- a/src/test/upgrade-test/previously_built_test.go +++ b/src/test/upgrade-test/previously_built_test.go @@ -21,10 +21,10 @@ func TestPreviouslyBuiltZarfPackage(t *testing.T) { // For the upgrade test, podinfo-upgrade should already be in the cluster (version 6.3.3) (see .github/workflows/test-upgrade.yml) kubeCtlRolloutArgs := []string{"-n=podinfo-upgrade", "rollout", "status", "deployment/podinfo-upgrade"} - kubectlOut, _, _, _ := exec.Cmd("kubectl", kubeCtlRolloutArgs...) + kubectlOut, _, _ := exec.Cmd("kubectl", kubeCtlRolloutArgs...) require.Contains(t, kubectlOut, "successfully rolled out") kubeCtlGetArgs := []string{"-n=podinfo-upgrade", "get", "deployment", "podinfo-upgrade", "-o=jsonpath={.metadata.labels}}"} - kubectlOut, _, _, _ = exec.Cmd("kubectl", kubeCtlGetArgs...) + kubectlOut, _, _ = exec.Cmd("kubectl", kubeCtlGetArgs...) require.Contains(t, kubectlOut, "6.3.3") // We also expect a 6.3.4 package to have been previously built @@ -32,7 +32,7 @@ func TestPreviouslyBuiltZarfPackage(t *testing.T) { // Deploy the package. zarfDeployArgs := []string{"package", "deploy", previouslyBuiltPackage, "--confirm"} - stdOut, stdErr, _, err := exec.Cmd(zarfBinPath, zarfDeployArgs...) + stdOut, stdErr, err := exec.Cmd(zarfBinPath, zarfDeployArgs...) require.NoError(t, err, stdOut, stdErr) // [DEPRECATIONS] We expect any deprecated things to work from the old package @@ -41,21 +41,21 @@ func TestPreviouslyBuiltZarfPackage(t *testing.T) { // Verify that podinfo-upgrade successfully deploys in the cluster (version 6.3.4) kubeCtlRolloutArgs = []string{"-n=podinfo-upgrade", "rollout", "status", "deployment/podinfo-upgrade"} - kubectlOut, _, _, _ = exec.Cmd("kubectl", kubeCtlRolloutArgs...) + kubectlOut, _, _ = exec.Cmd("kubectl", kubeCtlRolloutArgs...) require.Contains(t, kubectlOut, "successfully rolled out") kubeCtlGetArgs = []string{"-n=podinfo-upgrade", "get", "deployment", "podinfo-upgrade", "-o=jsonpath={.metadata.labels}}"} - kubectlOut, _, _, _ = exec.Cmd("kubectl", kubeCtlGetArgs...) + kubectlOut, _, _ = exec.Cmd("kubectl", kubeCtlGetArgs...) require.Contains(t, kubectlOut, "6.3.4") // We also want to build a new package. zarfCreateArgs := []string{"package", "create", "../../../src/test/upgrade-test", "--set", "PODINFO_VERSION=6.3.5", "--confirm"} - stdOut, stdErr, _, err = exec.Cmd(zarfBinPath, zarfCreateArgs...) + stdOut, stdErr, err = exec.Cmd(zarfBinPath, zarfCreateArgs...) require.NoError(t, err, stdOut, stdErr) newlyBuiltPackage := "zarf-package-test-upgrade-package-amd64-6.3.5.tar.zst" // Deploy the package. zarfDeployArgs = []string{"package", "deploy", newlyBuiltPackage, "--confirm"} - stdOut, stdErr, _, err = exec.Cmd(zarfBinPath, zarfDeployArgs...) + stdOut, stdErr, err = exec.Cmd(zarfBinPath, zarfDeployArgs...) require.NoError(t, err, stdOut, stdErr) // [DEPRECATIONS] We expect any deprecated things to work from the new package @@ -64,14 +64,14 @@ func TestPreviouslyBuiltZarfPackage(t *testing.T) { // Verify that podinfo-upgrade successfully deploys in the cluster (version 6.3.5) kubeCtlRolloutArgs = []string{"-n=podinfo-upgrade", "rollout", "status", "deployment/podinfo-upgrade"} - kubectlOut, _, _, _ = exec.Cmd("kubectl", kubeCtlRolloutArgs...) + kubectlOut, _, _ = exec.Cmd("kubectl", kubeCtlRolloutArgs...) require.Contains(t, kubectlOut, "successfully rolled out") kubeCtlGetArgs = []string{"-n=podinfo-upgrade", "get", "deployment", "podinfo-upgrade", "-o=jsonpath={.metadata.labels}}"} - kubectlOut, _, _, _ = exec.Cmd("kubectl", kubeCtlGetArgs...) + kubectlOut, _, _ = exec.Cmd("kubectl", kubeCtlGetArgs...) require.Contains(t, kubectlOut, "6.3.5") // Remove the package. zarfRemoveArgs := []string{"package", "remove", "test-upgrade-package", "--confirm"} - stdOut, stdErr, _, err = exec.Cmd(zarfBinPath, zarfRemoveArgs...) + stdOut, stdErr, err = exec.Cmd(zarfBinPath, zarfRemoveArgs...) require.NoError(t, err, stdOut, stdErr) } From f5891c4d29df51e7f4fcbd7387900db013de83f9 Mon Sep 17 00:00:00 2001 From: Lucas Rodriguez Date: Thu, 4 May 2023 14:34:36 -0500 Subject: [PATCH 43/53] Fix arch check in k3s package Wrap arch command substitution in double quotes Add proper error message in echo statement Add description to zarf actions --- packages/distros/k3s/zarf.yaml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/distros/k3s/zarf.yaml b/packages/distros/k3s/zarf.yaml index 3e14237220..63754bf789 100644 --- a/packages/distros/k3s/zarf.yaml +++ b/packages/distros/k3s/zarf.yaml @@ -30,7 +30,8 @@ components: actions: onDeploy: before: - - cmd: if [[ $(arch) != "x86_64" ]]; then echo \"I failed\" && exit 1; fi + - cmd: if [ "$(arch)" != "x86_64" ]; then echo "this package architecture is amd64, but the target cluster has the arm64 architecture. These architectures must be the same" && exit 1; fi + description: Check that the host architecture matches the package architecture maxRetries: 0 # ARM-64 version of the K3s stack @@ -59,5 +60,6 @@ components: actions: onDeploy: before: - - cmd: if [[ $(arch) != "arm64" ]]; then echo \"I failed\" && exit 1; fi + - cmd: if [ "$(arch)" != "arm64" ]; then echo "this package architecture is arm64, but the target cluster has the amd64 architecture. These architectures must be the same" && exit 1; fi + description: Check that the host architecture matches the package architecture maxRetries: 0 \ No newline at end of file From 51945c5a63f52c1871c2b8eb14703dfc6420ecb8 Mon Sep 17 00:00:00 2001 From: Lucas Rodriguez Date: Mon, 8 May 2023 11:04:04 -0500 Subject: [PATCH 44/53] Use target system instead of target cluster in k3s package error message Co-authored-by: Wayne Starr --- packages/distros/k3s/zarf.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/distros/k3s/zarf.yaml b/packages/distros/k3s/zarf.yaml index 63754bf789..2553848361 100644 --- a/packages/distros/k3s/zarf.yaml +++ b/packages/distros/k3s/zarf.yaml @@ -30,7 +30,7 @@ components: actions: onDeploy: before: - - cmd: if [ "$(arch)" != "x86_64" ]; then echo "this package architecture is amd64, but the target cluster has the arm64 architecture. These architectures must be the same" && exit 1; fi + - cmd: if [ "$(arch)" != "x86_64" ]; then echo "this package architecture is amd64, but the target system has a different architecture. These architectures must be the same" && exit 1; fi description: Check that the host architecture matches the package architecture maxRetries: 0 From 7f50d0ce6f1b98dcca81c7f2b0effbe821f10b99 Mon Sep 17 00:00:00 2001 From: Lucas Rodriguez Date: Mon, 8 May 2023 11:06:19 -0500 Subject: [PATCH 45/53] Remove MismatchedArch field from ZarfE2ETest struct Co-authored-by: Wayne Starr --- src/test/common.go | 1 - 1 file changed, 1 deletion(-) diff --git a/src/test/common.go b/src/test/common.go index 402e7598cf..29052142e1 100644 --- a/src/test/common.go +++ b/src/test/common.go @@ -17,7 +17,6 @@ import ( type ZarfE2ETest struct { ZarfBinPath string Arch string - MismatchedArch string ApplianceMode bool RunClusterTests bool } From 3b843371cceae643d333ac62ff470dc3cedbc24a Mon Sep 17 00:00:00 2001 From: Lucas Rodriguez Date: Mon, 8 May 2023 11:09:08 -0500 Subject: [PATCH 46/53] Update SetMismatchedArch test helper function to GetMismatchedArch Use switch statement instead of if statement and return the opposite arch string Co-authored-by: Wayne Starr --- src/test/common.go | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/test/common.go b/src/test/common.go index 29052142e1..c42b5a070b 100644 --- a/src/test/common.go +++ b/src/test/common.go @@ -76,14 +76,13 @@ func (e2e *ZarfE2ETest) CleanFiles(files ...string) { } } -// SetMismatchedArch determines what architecture our tests are running on, -// and sets e2e.MismatchedArch to the opposite architecture. -func (e2e *ZarfE2ETest) SetMismatchedArch() string { - if e2e.Arch == "amd64" { - e2e.MismatchedArch = "arm64" +// GetMismatchedArch determines what architecture our tests are running on, +// and returns the opposite architecture. +func (e2e *ZarfE2ETest) GetMismatchedArch() string { + switch e2e.Arch { + case "arm64": + return "amd64" + default: + return"arm64" } - if e2e.Arch == "arm64" { - e2e.MismatchedArch = "amd64" - } - return e2e.MismatchedArch } From 2662ff41e87eee529733b105b0e5e5b4030c12c9 Mon Sep 17 00:00:00 2001 From: Lucas Rodriguez Date: Mon, 8 May 2023 11:10:20 -0500 Subject: [PATCH 47/53] Update function name when setting mismatchedArch var in init test Co-authored-by: Wayne Starr --- src/test/e2e/20_zarf_init_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/e2e/20_zarf_init_test.go b/src/test/e2e/20_zarf_init_test.go index f4558e6c1a..a2bb24273b 100644 --- a/src/test/e2e/20_zarf_init_test.go +++ b/src/test/e2e/20_zarf_init_test.go @@ -29,7 +29,7 @@ func TestZarfInit(t *testing.T) { defer cancel() var ( - mismatchedArch = e2e.SetMismatchedArch() + mismatchedArch = e2e.GetMismatchedArch() initPackageVersion = "UnknownVersion" mismatchedInitPackage = fmt.Sprintf("zarf-init-%s-%s.tar.zst", mismatchedArch, initPackageVersion) ) From 547cac8ab1d7c837e5f0d0814773d1b366d7f9cb Mon Sep 17 00:00:00 2001 From: Lucas Rodriguez Date: Mon, 8 May 2023 11:11:45 -0500 Subject: [PATCH 48/53] Use NewCluster function to check if for access to k8s cluster Co-authored-by: Wayne Starr --- src/pkg/packager/common.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pkg/packager/common.go b/src/pkg/packager/common.go index b16451ff36..15c202a48a 100644 --- a/src/pkg/packager/common.go +++ b/src/pkg/packager/common.go @@ -447,7 +447,7 @@ func (p *Packager) validatePackageChecksums() error { // validatePackageArchitecture validates that the package architecture matches the target cluster architecture. func (p *Packager) validatePackageArchitecture() error { // Attempt to connect to a cluster to get the architecture. - if cluster, err := cluster.NewClusterWithWait(cluster.DefaultTimeout, false); err == nil { + if cluster, err := cluster.NewCluster(); err == nil { clusterArch, err := cluster.Kube.GetArchitecture() if err != nil { return err From 99a20b53e27c88bf1847e995eef527055af04d70 Mon Sep 17 00:00:00 2001 From: Lucas Rodriguez Date: Mon, 8 May 2023 11:12:35 -0500 Subject: [PATCH 49/53] Swap CmdWithContext function with ExecZarfCommand function in init test Co-authored-by: Wayne Starr --- src/test/e2e/20_zarf_init_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/e2e/20_zarf_init_test.go b/src/test/e2e/20_zarf_init_test.go index a2bb24273b..af4862ced3 100644 --- a/src/test/e2e/20_zarf_init_test.go +++ b/src/test/e2e/20_zarf_init_test.go @@ -46,7 +46,7 @@ func TestZarfInit(t *testing.T) { require.Error(t, err, stdErr) // run `zarf init` - _, stdErr, err = exec.CmdWithContext(ctx, exec.PrintCfg(), e2e.ZarfBinPath, "init", "--components="+initComponents, "--confirm", "--nodeport", "31337") + _, stdErr, err = e2e.ExecZarfCommand("init", "--components="+initComponents, "--confirm", "--nodeport", "31337") require.Contains(t, stdErr, "artifacts with software bill-of-materials (SBOM) included") require.NoError(t, err) From 049f2a6a8428c2464d7cdb4e4656834a9f9db958 Mon Sep 17 00:00:00 2001 From: Lucas Rodriguez Date: Mon, 8 May 2023 11:16:49 -0500 Subject: [PATCH 50/53] Update function name for getting mismatched arch in mismatched arch test --- src/test/e2e/29_mismatched_architectures_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/e2e/29_mismatched_architectures_test.go b/src/test/e2e/29_mismatched_architectures_test.go index d01291dd4b..f3e897a720 100644 --- a/src/test/e2e/29_mismatched_architectures_test.go +++ b/src/test/e2e/29_mismatched_architectures_test.go @@ -19,7 +19,7 @@ func TestMismatchedArchitectures(t *testing.T) { defer e2e.Teardown(t) var ( - mismatchedArch = e2e.SetMismatchedArch() + mismatchedArch = e2e.GetMismatchedArch() mismatchedGamesPackage = fmt.Sprintf("zarf-package-dos-games-%s.tar.zst", mismatchedArch) initPackageVersion = "UnknownVersion" mismatchedInitPackage = fmt.Sprintf("zarf-init-%s-%s.tar.zst", mismatchedArch, initPackageVersion) From ffce5dc4130d44e3ad481c158ff67e21a0bfd46f Mon Sep 17 00:00:00 2001 From: Lucas Rodriguez Date: Mon, 8 May 2023 11:19:10 -0500 Subject: [PATCH 51/53] Remove context.WithTimeout function from init test --- src/test/e2e/20_zarf_init_test.go | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/test/e2e/20_zarf_init_test.go b/src/test/e2e/20_zarf_init_test.go index af4862ced3..c056693d67 100644 --- a/src/test/e2e/20_zarf_init_test.go +++ b/src/test/e2e/20_zarf_init_test.go @@ -5,12 +5,9 @@ package test import ( - "context" "fmt" "testing" - "time" - "github.com/defenseunicorns/zarf/src/pkg/utils/exec" "github.com/stretchr/testify/require" ) @@ -25,9 +22,6 @@ func TestZarfInit(t *testing.T) { initComponents = "k3s,logging,git-server" } - ctx, cancel := context.WithTimeout(context.TODO(), 10*time.Minute) - defer cancel() - var ( mismatchedArch = e2e.GetMismatchedArch() initPackageVersion = "UnknownVersion" From 4dbdf1a13c291a39ed7eff79a0578eb6eba16119 Mon Sep 17 00:00:00 2001 From: Lucas Rodriguez Date: Mon, 8 May 2023 11:21:26 -0500 Subject: [PATCH 52/53] Check that mismatched arch test return expected error message --- src/test/e2e/20_zarf_init_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/test/e2e/20_zarf_init_test.go b/src/test/e2e/20_zarf_init_test.go index c056693d67..37114d12a9 100644 --- a/src/test/e2e/20_zarf_init_test.go +++ b/src/test/e2e/20_zarf_init_test.go @@ -26,6 +26,7 @@ func TestZarfInit(t *testing.T) { mismatchedArch = e2e.GetMismatchedArch() initPackageVersion = "UnknownVersion" mismatchedInitPackage = fmt.Sprintf("zarf-init-%s-%s.tar.zst", mismatchedArch, initPackageVersion) + expectedErrorMessage = fmt.Sprintf("this package architecture is %s", mismatchedArch) ) // Build init package with different arch than the cluster arch. @@ -38,6 +39,7 @@ func TestZarfInit(t *testing.T) { // We need to use the --architecture flag here to force zarf to find the package. _, stdErr, err = e2e.ExecZarfCommand("init", "--architecture", mismatchedArch, "--components=k3s", "--confirm") require.Error(t, err, stdErr) + require.Contains(t, stdErr, expectedErrorMessage) // run `zarf init` _, stdErr, err = e2e.ExecZarfCommand("init", "--components="+initComponents, "--confirm", "--nodeport", "31337") From 283ea08855854529407a913d10651a821ed3c2c6 Mon Sep 17 00:00:00 2001 From: Lucas Rodriguez Date: Mon, 8 May 2023 13:15:25 -0500 Subject: [PATCH 53/53] Update error message in k3s package --- packages/distros/k3s/zarf.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/distros/k3s/zarf.yaml b/packages/distros/k3s/zarf.yaml index 2553848361..4cfb478d7b 100644 --- a/packages/distros/k3s/zarf.yaml +++ b/packages/distros/k3s/zarf.yaml @@ -60,6 +60,6 @@ components: actions: onDeploy: before: - - cmd: if [ "$(arch)" != "arm64" ]; then echo "this package architecture is arm64, but the target cluster has the amd64 architecture. These architectures must be the same" && exit 1; fi + - cmd: if [ "$(arch)" != "arm64" ]; then echo "this package architecture is arm64, but the target system has a different architecture. These architectures must be the same" && exit 1; fi description: Check that the host architecture matches the package architecture maxRetries: 0 \ No newline at end of file