Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: arch check in PreDeployValidation #657

Merged
merged 7 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,16 @@ This means that setting the `--architecture` flag takes precedence over all othe

UDS CLI supports multi-arch bundles. This means you can push bundles with different architectures to the same remote OCI repository, at the same tag. For example, you can push both an `amd64` and `arm64` bundle to `ghcr.io/<org>/<bundle name>:0.0.1`.

### Architecture Validation
When deploying a local bundle, the bundle's architecture will be used for comparison against the cluster architecture to ensure compatability. If deploying a remote bundle, by default the bundle is pulled based on system architecture, which is then checked against the cluster.

> [!NOTE]
> It is possible to override the bundle architecture used at validation time by using the `--architecture` / `-a` flag.

If, for example, you have a multi-arch remote bundle that you want to deploy from an arm64 machine to an amd64 cluster, the validation with fail because the system arch does not match the cluster arch. However, you can pull the correct bundle version by specificying the arch with the command line architecture flag.

e.g.
`uds deploy -a amd64 <remote-multi-arch-bundle.tar.zst> --confirm`

## Configuration
The UDS CLI can be configured with a `uds-config.yaml` file. This file can be placed in the current working directory or specified with an environment variable called `UDS_CONFIG`. The basic structure of the `uds-config.yaml` is as follows:
Expand Down
12 changes: 6 additions & 6 deletions src/pkg/bundle/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,12 +285,6 @@ func (b *Bundle) PreDeployValidation() (string, string, string, error) {
}
b.cfg.DeployOpts.Source = source

// validate config's arch against cluster
err = ValidateArch(config.GetArch())
if err != nil {
return "", "", "", err
}

// create a new provider
provider, err := NewBundleProvider(b.cfg.DeployOpts.Source, b.tmp)
if err != nil {
Expand Down Expand Up @@ -320,6 +314,12 @@ func (b *Bundle) PreDeployValidation() (string, string, string, error) {
return "", "", "", err
}

// validate bundle's arch against cluster
err = ValidateArch(config.GetArch(b.bundle.Build.Architecture))
if err != nil {
return "", "", "", err
}

bundleName := b.bundle.Metadata.Name
return bundleName, string(bundleYAML), source, err
}
Expand Down
4 changes: 2 additions & 2 deletions src/test/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,9 @@ func (e2e *UDSE2ETest) DownloadZarfInitPkg(t *testing.T, zarfVersion string) {
}

// CreateZarfPkg creates a Zarf package in the given path
func (e2e *UDSE2ETest) CreateZarfPkg(t *testing.T, path string, forceCreate bool) {
func (e2e *UDSE2ETest) CreateZarfPkg(t *testing.T, path string, forceCreate bool, arch string) {
TristanHoladay marked this conversation as resolved.
Show resolved Hide resolved
// check if pkg already exists
pattern := fmt.Sprintf("%s/*-%s-*.tar.zst", path, e2e.Arch)
pattern := fmt.Sprintf("%s/*-%s-*.tar.zst", path, arch)
matches, err := filepath.Glob(pattern)
require.NoError(t, err)
if !forceCreate && len(matches) > 0 {
Expand Down
47 changes: 30 additions & 17 deletions src/test/e2e/bundle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func TestUDSLogs(t *testing.T) {

func TestSimpleBundleWithZarfAction(t *testing.T) {
zarfPkgPath := "src/test/packages/no-cluster/real-simple"
e2e.CreateZarfPkg(t, zarfPkgPath, false)
e2e.CreateZarfPkg(t, zarfPkgPath, false, e2e.Arch)
os.Setenv("UDS_LOG_LEVEL", "debug")
createLocal(t, "src/test/bundles/11-real-simple", e2e.Arch)
_, stderr := deploy(t, fmt.Sprintf("src/test/bundles/11-real-simple/uds-bundle-real-simple-%s-0.0.1.tar.zst", e2e.Arch))
Expand All @@ -46,8 +46,8 @@ func TestCreateWithNoPath(t *testing.T) {
// need to use remote pkgs because we move the uds-bundle.yaml to the current directory
zarfPkgPath1 := "src/test/packages/no-cluster/output-var"
zarfPkgPath2 := "src/test/packages/no-cluster/receive-var"
e2e.CreateZarfPkg(t, zarfPkgPath1, false)
e2e.CreateZarfPkg(t, zarfPkgPath2, false)
e2e.CreateZarfPkg(t, zarfPkgPath1, false, e2e.Arch)
e2e.CreateZarfPkg(t, zarfPkgPath2, false, e2e.Arch)

e2e.SetupDockerRegistry(t, 888)
defer e2e.TeardownRegistry(t, 888)
Expand Down Expand Up @@ -76,7 +76,7 @@ func TestBundleWithLocalAndRemotePkgs(t *testing.T) {
defer e2e.TeardownRegistry(t, 888)
e2e.SetupDockerRegistry(t, 889)
defer e2e.TeardownRegistry(t, 889)
e2e.CreateZarfPkg(t, "src/test/packages/podinfo", false)
e2e.CreateZarfPkg(t, "src/test/packages/podinfo", false, e2e.Arch)

bundleDir := "src/test/bundles/03-local-and-remote"
bundleTarballName := fmt.Sprintf("uds-bundle-test-local-and-remote-%s-0.0.1.tar.zst", e2e.Arch)
Expand Down Expand Up @@ -112,8 +112,8 @@ func TestBundleWithLocalAndRemotePkgs(t *testing.T) {
func TestLocalBundleWithRemotePkgs(t *testing.T) {
deployZarfInit(t)

e2e.CreateZarfPkg(t, "src/test/packages/nginx", false)
e2e.CreateZarfPkg(t, "src/test/packages/podinfo", false)
e2e.CreateZarfPkg(t, "src/test/packages/nginx", false, e2e.Arch)
e2e.CreateZarfPkg(t, "src/test/packages/podinfo", false, e2e.Arch)

e2e.SetupDockerRegistry(t, 888)
defer e2e.TeardownRegistry(t, 888)
Expand All @@ -138,7 +138,7 @@ func TestLocalBundleWithRemotePkgs(t *testing.T) {

func TestPackagesFlag(t *testing.T) {
deployZarfInit(t)
e2e.CreateZarfPkg(t, "src/test/packages/podinfo", false)
e2e.CreateZarfPkg(t, "src/test/packages/podinfo", false, e2e.Arch)
bundleDir := "src/test/bundles/03-local-and-remote"
bundlePath := filepath.Join(bundleDir, fmt.Sprintf("uds-bundle-test-local-and-remote-%s-0.0.1.tar.zst", e2e.Arch))

Expand Down Expand Up @@ -193,7 +193,7 @@ func TestPackagesFlag(t *testing.T) {

func TestResumeFlag(t *testing.T) {
deployZarfInit(t)
e2e.CreateZarfPkg(t, "src/test/packages/podinfo", false)
e2e.CreateZarfPkg(t, "src/test/packages/podinfo", false, e2e.Arch)
bundleDir := "src/test/bundles/03-local-and-remote"
bundlePath := filepath.Join(bundleDir, fmt.Sprintf("uds-bundle-test-local-and-remote-%s-0.0.1.tar.zst", e2e.Arch))

Expand Down Expand Up @@ -248,8 +248,8 @@ func TestResumeFlag(t *testing.T) {

func TestRemoteBundleWithRemotePkgs(t *testing.T) {
deployZarfInit(t)
e2e.CreateZarfPkg(t, "src/test/packages/nginx", false)
e2e.CreateZarfPkg(t, "src/test/packages/podinfo", false)
e2e.CreateZarfPkg(t, "src/test/packages/nginx", false, e2e.Arch)
e2e.CreateZarfPkg(t, "src/test/packages/podinfo", false, e2e.Arch)

e2e.SetupDockerRegistry(t, 888)
defer e2e.TeardownRegistry(t, 888)
Expand Down Expand Up @@ -292,7 +292,7 @@ func TestRemoteBundleWithRemotePkgs(t *testing.T) {

func TestBundleWithGitRepo(t *testing.T) {
deployZarfInit(t)
e2e.CreateZarfPkg(t, "src/test/packages/gitrepo", false)
e2e.CreateZarfPkg(t, "src/test/packages/gitrepo", false, e2e.Arch)
bundleDir := "src/test/bundles/05-gitrepo"
bundlePath := filepath.Join(bundleDir, fmt.Sprintf("uds-bundle-gitrepo-%s-0.0.1.tar.zst", e2e.Arch))

Expand All @@ -303,7 +303,7 @@ func TestBundleWithGitRepo(t *testing.T) {

func TestBundleWithYmlFile(t *testing.T) {
deployZarfInit(t)
e2e.CreateZarfPkg(t, "src/test/packages/nginx", true)
e2e.CreateZarfPkg(t, "src/test/packages/nginx", true, e2e.Arch)

bundleDir := "src/test/bundles/09-uds-bundle-yml"
bundlePath := filepath.Join(bundleDir, fmt.Sprintf("uds-bundle-yml-example-%s-0.0.1.tar.zst", e2e.Arch))
Expand Down Expand Up @@ -372,8 +372,8 @@ func TestRemoteBundleWithNoSBOM(t *testing.T) {
func TestPackageNaming(t *testing.T) {
deployZarfInit(t)

e2e.CreateZarfPkg(t, "src/test/packages/nginx", false)
e2e.CreateZarfPkg(t, "src/test/packages/podinfo", false)
e2e.CreateZarfPkg(t, "src/test/packages/nginx", false, e2e.Arch)
e2e.CreateZarfPkg(t, "src/test/packages/podinfo", false, e2e.Arch)

e2e.SetupDockerRegistry(t, 888)
defer e2e.TeardownRegistry(t, 888)
Expand Down Expand Up @@ -504,7 +504,7 @@ func TestBundleWithComposedPkgComponent(t *testing.T) {
defer e2e.TeardownRegistry(t, 888)
zarfPkgPath := "src/test/packages/prometheus"
pkg := filepath.Join(zarfPkgPath, fmt.Sprintf("zarf-package-prometheus-%s-0.0.1.tar.zst", e2e.Arch))
e2e.CreateZarfPkg(t, zarfPkgPath, false)
e2e.CreateZarfPkg(t, zarfPkgPath, false, e2e.Arch)
zarfPublish(t, pkg, "localhost:888")

bundleDir := "src/test/bundles/13-composable-component"
Expand All @@ -517,7 +517,7 @@ func TestBundleWithComposedPkgComponent(t *testing.T) {

func TestBundleTmpDir(t *testing.T) {
deployZarfInit(t)
e2e.CreateZarfPkg(t, "src/test/packages/podinfo", false)
e2e.CreateZarfPkg(t, "src/test/packages/podinfo", false, e2e.Arch)

bundleDir := "src/test/bundles/03-local-and-remote"
bundlePath := filepath.Join(bundleDir, fmt.Sprintf("uds-bundle-test-local-and-remote-%s-0.0.1.tar.zst", e2e.Arch))
Expand Down Expand Up @@ -619,8 +619,21 @@ func TestInvalidBundle(t *testing.T) {
deployZarfInit(t)
zarfPkgPath := "src/test/packages/helm"
e2e.HelmDepUpdate(t, fmt.Sprintf("%s/unicorn-podinfo", zarfPkgPath))
e2e.CreateZarfPkg(t, zarfPkgPath, false)
e2e.CreateZarfPkg(t, zarfPkgPath, false, e2e.Arch)
bundleDir := "src/test/bundles/07-helm-overrides/invalid"
stderr := createLocalError(bundleDir, e2e.Arch)
require.Contains(t, stderr, "unknown field")
}

func TestArchCheck(t *testing.T) {
UncleGedd marked this conversation as resolved.
Show resolved Hide resolved
deployZarfInit(t)
zarfPkgPath := "src/test/packages/helm"
e2e.HelmDepUpdate(t, fmt.Sprintf("%s/unicorn-podinfo", zarfPkgPath))
e2e.CreateZarfPkg(t, zarfPkgPath, false, "arm64")
bundleDir := "src/test/bundles/07-helm-overrides"
bundlePath := filepath.Join(bundleDir, fmt.Sprintf("uds-bundle-helm-overrides-%s-0.0.1.tar.zst", "arm64"))
createLocal(t, bundleDir, "arm64")
cmd := strings.Split(fmt.Sprintf("deploy %s --confirm", bundlePath), " ")
_, stderr, _ := e2e.UDS(cmd...)
require.Contains(t, stderr, "arch arm64 does not match cluster arch, [amd64]")
}
2 changes: 1 addition & 1 deletion src/test/e2e/dev_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestDevDeploy(t *testing.T) {

t.Run("Test dev deploy with local and remote pkgs", func(t *testing.T) {

e2e.CreateZarfPkg(t, "src/test/packages/podinfo", false)
e2e.CreateZarfPkg(t, "src/test/packages/podinfo", false, e2e.Arch)

bundleDir := "src/test/bundles/03-local-and-remote"
bundlePath := filepath.Join(bundleDir, fmt.Sprintf("uds-bundle-test-local-and-remote-%s-0.0.1.tar.zst", e2e.Arch))
Expand Down
4 changes: 2 additions & 2 deletions src/test/e2e/optional_bundle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ func TestBundleOptionalComponents(t *testing.T) {

// create 2 Zarf pkgs to be bundled
zarfPkgPath := "src/test/packages/podinfo-nginx"
e2e.CreateZarfPkg(t, zarfPkgPath, false)
e2e.CreateZarfPkg(t, zarfPkgPath, false, e2e.Arch)

zarfPkgPath = "src/test/packages/prometheus"
pkg := filepath.Join(zarfPkgPath, fmt.Sprintf("zarf-package-prometheus-%s-0.0.1.tar.zst", e2e.Arch))
e2e.CreateZarfPkg(t, zarfPkgPath, false)
e2e.CreateZarfPkg(t, zarfPkgPath, false, e2e.Arch)
zarfPublish(t, pkg, "localhost:888")

// create bundle and publish
Expand Down
22 changes: 11 additions & 11 deletions src/test/e2e/variable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import (
)

func TestBundleVariables(t *testing.T) {
e2e.CreateZarfPkg(t, "src/test/packages/no-cluster/output-var", false)
e2e.CreateZarfPkg(t, "src/test/packages/no-cluster/receive-var", false)
e2e.CreateZarfPkg(t, "src/test/packages/no-cluster/output-var", false, e2e.Arch)
e2e.CreateZarfPkg(t, "src/test/packages/no-cluster/receive-var", false, e2e.Arch)
os.Setenv("UDS_ANIMAL", "Unicorns")
os.Setenv("UDS_CONFIG", filepath.Join("src/test/bundles/02-variables", "uds-config.yaml"))

Expand All @@ -35,7 +35,7 @@ func TestBundleVariables(t *testing.T) {
})

t.Run("var name collision with exported vars", func(t *testing.T) {
e2e.CreateZarfPkg(t, "src/test/packages/no-cluster/output-var-collision", false)
e2e.CreateZarfPkg(t, "src/test/packages/no-cluster/output-var-collision", false, e2e.Arch)
bundleDir := "src/test/bundles/02-variables/export-name-collision"
bundleTarballPath := filepath.Join(bundleDir, fmt.Sprintf("uds-bundle-export-name-collision-%s-0.0.1.tar.zst", e2e.Arch))
createLocal(t, bundleDir, e2e.Arch)
Expand Down Expand Up @@ -72,7 +72,7 @@ func bundleVariablesTestChecks(t *testing.T, stderr string, bundleTarballPath st
func TestBundleWithHelmOverrides(t *testing.T) {
deployZarfInit(t)
e2e.HelmDepUpdate(t, "src/test/packages/helm/unicorn-podinfo")
e2e.CreateZarfPkg(t, "src/test/packages/helm", false)
e2e.CreateZarfPkg(t, "src/test/packages/helm", false, e2e.Arch)
bundleDir := "src/test/bundles/07-helm-overrides"
bundlePath := filepath.Join(bundleDir, fmt.Sprintf("uds-bundle-helm-overrides-%s-0.0.1.tar.zst", e2e.Arch))
err := os.Setenv("UDS_CONFIG", filepath.Join("src/test/bundles/07-helm-overrides", "uds-config.yaml"))
Expand Down Expand Up @@ -160,7 +160,7 @@ func TestBundleWithHelmOverrides(t *testing.T) {
func TestBundleWithHelmOverridesValuesFile(t *testing.T) {
deployZarfInit(t)
e2e.HelmDepUpdate(t, "src/test/packages/helm/unicorn-podinfo")
e2e.CreateZarfPkg(t, "src/test/packages/helm", false)
e2e.CreateZarfPkg(t, "src/test/packages/helm", false, e2e.Arch)
bundleDir := "src/test/bundles/07-helm-overrides/values-file"
bundlePath := filepath.Join(bundleDir, fmt.Sprintf("uds-bundle-helm-values-file-%s-0.0.1.tar.zst", e2e.Arch))
err := os.Setenv("UDS_CONFIG", filepath.Join("src/test/bundles/07-helm-overrides", "uds-config.yaml"))
Expand Down Expand Up @@ -202,7 +202,7 @@ func TestBundleWithDupPkgs(t *testing.T) {
defer e2e.TeardownRegistry(t, 888)
zarfPkgPath := "src/test/packages/helm"
e2e.HelmDepUpdate(t, fmt.Sprintf("%s/unicorn-podinfo", zarfPkgPath))
e2e.CreateZarfPkg(t, zarfPkgPath, false)
e2e.CreateZarfPkg(t, zarfPkgPath, false, e2e.Arch)
name := "duplicates"
pkg := filepath.Join(zarfPkgPath, fmt.Sprintf("zarf-package-helm-overrides-%s-0.0.1.tar.zst", e2e.Arch))
zarfPublish(t, pkg, "localhost:888")
Expand Down Expand Up @@ -244,7 +244,7 @@ func TestBundleWithEnvVarHelmOverrides(t *testing.T) {
// set up configs and env vars
deployZarfInit(t)
e2e.HelmDepUpdate(t, "src/test/packages/helm/unicorn-podinfo")
e2e.CreateZarfPkg(t, "src/test/packages/helm", false)
e2e.CreateZarfPkg(t, "src/test/packages/helm", false, e2e.Arch)
color := "purple"
b64Secret := "dGhhdCBhaW50IG15IHRydWNr"
err := os.Setenv("UDS_CONFIG", filepath.Join("src/test/bundles/07-helm-overrides", "uds-config.yaml"))
Expand Down Expand Up @@ -299,8 +299,8 @@ func TestVariablePrecedence(t *testing.T) {
// precedence rules: env var > uds-config.variables > uds-config.shared > default
deployZarfInit(t)
e2e.HelmDepUpdate(t, "src/test/packages/helm/unicorn-podinfo")
e2e.CreateZarfPkg(t, "src/test/packages/helm", false)
e2e.CreateZarfPkg(t, "src/test/packages/no-cluster/output-var", false)
e2e.CreateZarfPkg(t, "src/test/packages/helm", false, e2e.Arch)
e2e.CreateZarfPkg(t, "src/test/packages/no-cluster/output-var", false, e2e.Arch)
bundleDir := "src/test/bundles/08-var-precedence"
bundlePath := filepath.Join(bundleDir, fmt.Sprintf("uds-bundle-var-precedence-%s-0.0.1.tar.zst", e2e.Arch))
err := os.Setenv("UDS_CONFIG", filepath.Join("src/test/bundles/08-var-precedence", "uds-config.yaml"))
Expand Down Expand Up @@ -338,9 +338,9 @@ func TestVariablePrecedence(t *testing.T) {

func TestExportVarsAsGlobalVars(t *testing.T) {
deployZarfInit(t)
e2e.CreateZarfPkg(t, "src/test/packages/no-cluster/output-var", false)
e2e.CreateZarfPkg(t, "src/test/packages/no-cluster/output-var", false, e2e.Arch)
e2e.HelmDepUpdate(t, "src/test/packages/helm/unicorn-podinfo")
e2e.CreateZarfPkg(t, "src/test/packages/helm", false)
e2e.CreateZarfPkg(t, "src/test/packages/helm", false, e2e.Arch)
bundleDir := "src/test/bundles/12-exported-pkg-vars"
bundlePath := filepath.Join(bundleDir, fmt.Sprintf("uds-bundle-export-vars-%s-0.0.1.tar.zst", e2e.Arch))

Expand Down
Loading