From 4d61aec6325b1061c8411dafd36b1cad98b81825 Mon Sep 17 00:00:00 2001 From: UncleGedd <42304551+UncleGedd@users.noreply.github.com> Date: Wed, 25 Oct 2023 11:05:48 -0500 Subject: [PATCH] adds architecture flag and renames test dirs (#131) --- src/cmd/root.go | 1 + src/config/lang/lang.go | 1 + src/pkg/bundle/common.go | 4 +- .../01-uds-bundle/uds-bundle.yaml | 0 .../02-simple-vars/uds-bundle.yaml | 0 .../02-simple-vars/uds-config.yaml | 0 .../03-local-and-remote/uds-bundle.yaml | 2 +- .../04-local-init/uds-bundle.yaml | 2 +- src/test/common.go | 2 +- src/test/e2e/bundle_test.go | 38 +++++++++---------- .../no-cluster/output-var/zarf.yaml | 0 .../no-cluster/receive-var/zarf.yaml | 0 .../packages/{zarf => }/podinfo/zarf.yaml | 0 13 files changed, 25 insertions(+), 25 deletions(-) rename src/test/{packages => bundles}/01-uds-bundle/uds-bundle.yaml (100%) rename src/test/{packages => bundles}/02-simple-vars/uds-bundle.yaml (100%) rename src/test/{packages => bundles}/02-simple-vars/uds-config.yaml (100%) rename src/test/{packages => bundles}/03-local-and-remote/uds-bundle.yaml (89%) rename src/test/{packages => bundles}/04-local-init/uds-bundle.yaml (88%) rename src/test/packages/{zarf => }/no-cluster/output-var/zarf.yaml (100%) rename src/test/packages/{zarf => }/no-cluster/receive-var/zarf.yaml (100%) rename src/test/packages/{zarf => }/podinfo/zarf.yaml (100%) diff --git a/src/cmd/root.go b/src/cmd/root.go index c9d44c45..5656ecd0 100644 --- a/src/cmd/root.go +++ b/src/cmd/root.go @@ -87,6 +87,7 @@ func init() { v.SetDefault(V_TMP_DIR, "") rootCmd.PersistentFlags().StringVarP(&logLevel, "log-level", "l", v.GetString(V_LOG_LEVEL), lang.RootCmdFlagLogLevel) + rootCmd.PersistentFlags().StringVarP(&config.CLIArch, "architecture", "a", v.GetString(common.VArchitecture), lang.RootCmdFlagArch) rootCmd.PersistentFlags().BoolVar(&config.SkipLogFile, "no-log-file", v.GetBool(V_NO_LOG_FILE), lang.RootCmdFlagSkipLogFile) rootCmd.PersistentFlags().BoolVar(&message.NoProgress, "no-progress", v.GetBool(V_NO_PROGRESS), lang.RootCmdFlagNoProgress) rootCmd.PersistentFlags().StringVar(&config.CommonOptions.CachePath, "zarf-cache", v.GetString(V_ZARF_CACHE), lang.RootCmdFlagCachePath) diff --git a/src/config/lang/lang.go b/src/config/lang/lang.go index 87be4ff6..09daf712 100644 --- a/src/config/lang/lang.go +++ b/src/config/lang/lang.go @@ -14,6 +14,7 @@ const ( RootCmdFlagInsecure = "Allow access to insecure registries and disable other recommended security enforcements such as package checksum and signature validation. This flag should only be used if you have a specific reason and accept the reduced security posture." RootCmdFlagLogLevel = "Log level when running UDS-CLI. Valid options are: warn, info, debug, trace" RootCmdErrInvalidLogLevel = "Invalid log level. Valid options are: warn, info, debug, trace." + RootCmdFlagArch = "Architecture for UDS bundles and Zarf packages" // bundle CmdBundleShort = "Commands for creating, deploying, removing, pulling, and inspecting bundles" diff --git a/src/pkg/bundle/common.go b/src/pkg/bundle/common.go index 163140c7..60b5d29f 100644 --- a/src/pkg/bundle/common.go +++ b/src/pkg/bundle/common.go @@ -228,8 +228,6 @@ func validateBundleVars(packages []types.BundleZarfPackage) error { } // CalculateBuildInfo calculates the build info for the bundle -// -// this is mainly mirrored from packager.writeYaml() func (b *Bundler) CalculateBuildInfo() error { now := time.Now() b.bundle.Build.User = os.Getenv("USER") @@ -240,7 +238,7 @@ func (b *Bundler) CalculateBuildInfo() error { } b.bundle.Build.Terminal = hostname - // --architecture flag > metadata.arch > build.arch / runtime.GOARCH (default) + // --architecture flag > metadata.arch > build.arch > runtime.GOARCH (default) b.bundle.Build.Architecture = config.GetArch(b.bundle.Metadata.Architecture, b.bundle.Build.Architecture) b.bundle.Metadata.Architecture = b.bundle.Build.Architecture diff --git a/src/test/packages/01-uds-bundle/uds-bundle.yaml b/src/test/bundles/01-uds-bundle/uds-bundle.yaml similarity index 100% rename from src/test/packages/01-uds-bundle/uds-bundle.yaml rename to src/test/bundles/01-uds-bundle/uds-bundle.yaml diff --git a/src/test/packages/02-simple-vars/uds-bundle.yaml b/src/test/bundles/02-simple-vars/uds-bundle.yaml similarity index 100% rename from src/test/packages/02-simple-vars/uds-bundle.yaml rename to src/test/bundles/02-simple-vars/uds-bundle.yaml diff --git a/src/test/packages/02-simple-vars/uds-config.yaml b/src/test/bundles/02-simple-vars/uds-config.yaml similarity index 100% rename from src/test/packages/02-simple-vars/uds-config.yaml rename to src/test/bundles/02-simple-vars/uds-config.yaml diff --git a/src/test/packages/03-local-and-remote/uds-bundle.yaml b/src/test/bundles/03-local-and-remote/uds-bundle.yaml similarity index 89% rename from src/test/packages/03-local-and-remote/uds-bundle.yaml rename to src/test/bundles/03-local-and-remote/uds-bundle.yaml index 169a520a..25edf758 100644 --- a/src/test/packages/03-local-and-remote/uds-bundle.yaml +++ b/src/test/bundles/03-local-and-remote/uds-bundle.yaml @@ -11,5 +11,5 @@ zarf-packages: optional-components: - git-server - name: podinfo - path: "../zarf/podinfo" + path: "../../packages/podinfo" ref: 0.0.1 diff --git a/src/test/packages/04-local-init/uds-bundle.yaml b/src/test/bundles/04-local-init/uds-bundle.yaml similarity index 88% rename from src/test/packages/04-local-init/uds-bundle.yaml rename to src/test/bundles/04-local-init/uds-bundle.yaml index c7712e41..a2b7432b 100644 --- a/src/test/packages/04-local-init/uds-bundle.yaml +++ b/src/test/bundles/04-local-init/uds-bundle.yaml @@ -6,7 +6,7 @@ metadata: zarf-packages: - name: init - path: "../zarf" + path: "../../packages" ref: v0.30.1 optional-components: - git-server \ No newline at end of file diff --git a/src/test/common.go b/src/test/common.go index 8cbd15f5..2e959a30 100644 --- a/src/test/common.go +++ b/src/test/common.go @@ -117,7 +117,7 @@ func (e2e *UDSE2ETest) GetUdsVersion(t *testing.T) string { func (e2e *UDSE2ETest) DownloadZarfInitPkg(t *testing.T, zarfVersion string) { filename := fmt.Sprintf("zarf-init-%s-%s.tar.zst", e2e.Arch, zarfVersion) zarfReleaseURL := fmt.Sprintf("https://github.com/defenseunicorns/zarf/releases/download/%s/%s", zarfVersion, filename) - outputDir := "src/test/packages/zarf" + outputDir := "src/test/packages" // Check if the file already exists if _, err := os.Stat(outputDir + "/" + filename); err == nil { diff --git a/src/test/e2e/bundle_test.go b/src/test/e2e/bundle_test.go index ce9053e5..5cb18657 100644 --- a/src/test/e2e/bundle_test.go +++ b/src/test/e2e/bundle_test.go @@ -34,8 +34,8 @@ func zarfPublish(t *testing.T, path string, reg string) { const zarfVersion = "v0.30.1" func TestCreateWithNoPath(t *testing.T) { - zarfPkgPath1 := "src/test/packages/zarf/no-cluster/output-var" - zarfPkgPath2 := "src/test/packages/zarf/no-cluster/receive-var" + zarfPkgPath1 := "src/test/packages/no-cluster/output-var" + zarfPkgPath2 := "src/test/packages/no-cluster/receive-var" e2e.CreateZarfPkg(t, zarfPkgPath1) e2e.CreateZarfPkg(t, zarfPkgPath2) @@ -48,7 +48,7 @@ func TestCreateWithNoPath(t *testing.T) { pkg = filepath.Join(zarfPkgPath2, fmt.Sprintf("zarf-package-receive-var-%s-0.0.1.tar.zst", e2e.Arch)) zarfPublish(t, pkg, "localhost:888") - err := os.Link(fmt.Sprintf("src/test/packages/02-simple-vars/%s", config.BundleYAML), config.BundleYAML) + err := os.Link(fmt.Sprintf("src/test/bundles/02-simple-vars/%s", config.BundleYAML), config.BundleYAML) require.NoError(t, err) defer os.Remove(config.BundleYAML) defer os.Remove(fmt.Sprintf("uds-bundle-simple-vars-%s-0.0.1.tar.zst", e2e.Arch)) @@ -60,8 +60,8 @@ func TestCreateWithNoPath(t *testing.T) { } func TestBundleVariables(t *testing.T) { - zarfPkgPath1 := "src/test/packages/zarf/no-cluster/output-var" - zarfPkgPath2 := "src/test/packages/zarf/no-cluster/receive-var" + zarfPkgPath1 := "src/test/packages/no-cluster/output-var" + zarfPkgPath2 := "src/test/packages/no-cluster/receive-var" e2e.CreateZarfPkg(t, zarfPkgPath1) e2e.CreateZarfPkg(t, zarfPkgPath2) @@ -74,10 +74,10 @@ func TestBundleVariables(t *testing.T) { pkg = filepath.Join(zarfPkgPath2, fmt.Sprintf("zarf-package-receive-var-%s-0.0.1.tar.zst", e2e.Arch)) zarfPublish(t, pkg, "localhost:888") - bundleDir := "src/test/packages/02-simple-vars" + bundleDir := "src/test/bundles/02-simple-vars" bundlePath := filepath.Join(bundleDir, fmt.Sprintf("uds-bundle-simple-vars-%s-0.0.1.tar.zst", e2e.Arch)) - os.Setenv("UDS_CONFIG", filepath.Join("src/test/packages/02-simple-vars", "uds-config.yaml")) + os.Setenv("UDS_CONFIG", filepath.Join("src/test/bundles/02-simple-vars", "uds-config.yaml")) create(t, bundleDir) createRemote(t, bundleDir, "localhost:888") @@ -93,7 +93,7 @@ func TestBundleWithLocalInitPkg(t *testing.T) { e2e.DownloadZarfInitPkg(t, zarfVersion) - bundleDir := "src/test/packages/04-local-init" + bundleDir := "src/test/bundles/04-local-init" bundlePath := filepath.Join(bundleDir, fmt.Sprintf("uds-bundle-local-init-%s-0.0.1.tar.zst", e2e.Arch)) create(t, bundleDir) @@ -106,9 +106,9 @@ func TestBundleWithLocalAndRemotePkgs(t *testing.T) { e2e.SetupWithCluster(t) e2e.SetupDockerRegistry(t, 888) defer e2e.TeardownRegistry(t, 888) - e2e.CreateZarfPkg(t, "src/test/packages/zarf/podinfo") + e2e.CreateZarfPkg(t, "src/test/packages/podinfo") - bundleDir := "src/test/packages/03-local-and-remote" + bundleDir := "src/test/bundles/03-local-and-remote" bundlePath := filepath.Join(bundleDir, fmt.Sprintf("uds-bundle-local-and-remote-%s-0.0.1.tar.zst", e2e.Arch)) tarballPath := filepath.Join("build", fmt.Sprintf("uds-bundle-local-and-remote-%s-0.0.1.tar.zst", e2e.Arch)) @@ -130,20 +130,20 @@ func TestBundle(t *testing.T) { e2e.SetupWithCluster(t) e2e.DownloadZarfInitPkg(t, zarfVersion) - e2e.CreateZarfPkg(t, "src/test/packages/zarf/podinfo") + e2e.CreateZarfPkg(t, "src/test/packages/podinfo") e2e.SetupDockerRegistry(t, 888) defer e2e.TeardownRegistry(t, 888) e2e.SetupDockerRegistry(t, 889) defer e2e.TeardownRegistry(t, 889) - pkg := fmt.Sprintf("src/test/packages/zarf/zarf-init-%s-%s.tar.zst", e2e.Arch, zarfVersion) + pkg := fmt.Sprintf("src/test/packages/zarf-init-%s-%s.tar.zst", e2e.Arch, zarfVersion) zarfPublish(t, pkg, "localhost:888") - pkg = fmt.Sprintf("src/test/packages/zarf/podinfo/zarf-package-podinfo-%s-0.0.1.tar.zst", e2e.Arch) + pkg = fmt.Sprintf("src/test/packages/podinfo/zarf-package-podinfo-%s-0.0.1.tar.zst", e2e.Arch) zarfPublish(t, pkg, "localhost:889") - bundleDir := "src/test/packages/01-uds-bundle" + bundleDir := "src/test/bundles/01-uds-bundle" bundlePath := filepath.Join(bundleDir, fmt.Sprintf("uds-bundle-example-%s-0.0.1.tar.zst", e2e.Arch)) create(t, bundleDir) // todo: allow creating from both the folder containing and direct reference to uds-bundle.yaml @@ -157,17 +157,17 @@ func TestRemoteBundle(t *testing.T) { e2e.SetupWithCluster(t) e2e.DownloadZarfInitPkg(t, zarfVersion) - e2e.CreateZarfPkg(t, "src/test/packages/zarf/podinfo") + e2e.CreateZarfPkg(t, "src/test/packages/podinfo") e2e.SetupDockerRegistry(t, 888) defer e2e.TeardownRegistry(t, 888) e2e.SetupDockerRegistry(t, 889) defer e2e.TeardownRegistry(t, 889) - pkg := fmt.Sprintf("src/test/packages/zarf/zarf-init-%s-%s.tar.zst", e2e.Arch, zarfVersion) + pkg := fmt.Sprintf("src/test/packages/zarf-init-%s-%s.tar.zst", e2e.Arch, zarfVersion) zarfPublish(t, pkg, "localhost:888") - pkg = fmt.Sprintf("src/test/packages/zarf/podinfo/zarf-package-podinfo-%s-0.0.1.tar.zst", e2e.Arch) + pkg = fmt.Sprintf("src/test/packages/podinfo/zarf-package-podinfo-%s-0.0.1.tar.zst", e2e.Arch) zarfPublish(t, pkg, "localhost:889") bundleRef := registry.Reference{ @@ -178,7 +178,7 @@ func TestRemoteBundle(t *testing.T) { } tarballPath := filepath.Join("build", fmt.Sprintf("uds-bundle-example-%s-0.0.1.tar.zst", e2e.Arch)) - bundlePath := "src/test/packages/01-uds-bundle" + bundlePath := "src/test/bundles/01-uds-bundle" createRemote(t, bundlePath, bundleRef.Registry) pull(t, bundleRef.String(), tarballPath) @@ -194,7 +194,7 @@ func create(t *testing.T, bundlePath string) { } func createSecure(t *testing.T, bundlePath string) { - cmd := strings.Split(fmt.Sprintf("create %s --confirm", bundlePath), " ") + cmd := strings.Split(fmt.Sprintf("create %s --confirm -a %s", bundlePath, e2e.Arch), " ") _, _, err := e2e.UDS(cmd...) require.NoError(t, err) } diff --git a/src/test/packages/zarf/no-cluster/output-var/zarf.yaml b/src/test/packages/no-cluster/output-var/zarf.yaml similarity index 100% rename from src/test/packages/zarf/no-cluster/output-var/zarf.yaml rename to src/test/packages/no-cluster/output-var/zarf.yaml diff --git a/src/test/packages/zarf/no-cluster/receive-var/zarf.yaml b/src/test/packages/no-cluster/receive-var/zarf.yaml similarity index 100% rename from src/test/packages/zarf/no-cluster/receive-var/zarf.yaml rename to src/test/packages/no-cluster/receive-var/zarf.yaml diff --git a/src/test/packages/zarf/podinfo/zarf.yaml b/src/test/packages/podinfo/zarf.yaml similarity index 100% rename from src/test/packages/zarf/podinfo/zarf.yaml rename to src/test/packages/podinfo/zarf.yaml