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 6 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
15 changes: 15 additions & 0 deletions src/test/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,21 @@ func (e2e *UDSE2ETest) CreateZarfPkg(t *testing.T, path string, forceCreate bool
require.NoError(t, err)
}

// CreateZarfPkgWithArch creates a Zarf package of a user specified arch in the given path
func (e2e *UDSE2ETest) CreateZarfPkgWithArch(t *testing.T, path string, forceCreate bool, arch string) {
// check if pkg already exists
pattern := fmt.Sprintf("%s/*-%s-*.tar.zst", path, arch)
matches, err := filepath.Glob(pattern)
require.NoError(t, err)
if !forceCreate && len(matches) > 0 {
fmt.Println("Zarf pkg already exists, skipping create")
return
}
args := strings.Split(fmt.Sprintf("zarf package create %s -o %s -a %s --confirm", path, path, arch), " ")
_, _, err = e2e.UDS(args...)
require.NoError(t, err)
}

// DeleteZarfPkg deletes a Zarf package from the given path
func (e2e *UDSE2ETest) DeleteZarfPkg(t *testing.T, path string) {
// check if pkg already exists
Expand Down
13 changes: 13 additions & 0 deletions src/test/e2e/bundle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -624,3 +624,16 @@ func TestInvalidBundle(t *testing.T) {
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.CreateZarfPkgWithArch(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]")
}
Loading