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: ensures partial pkgs are correct and adds smoke test to workflows #643

Merged
merged 5 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
14 changes: 3 additions & 11 deletions .github/workflows/nightly-uds-core.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,10 @@ jobs:
run: |
chmod +x build/uds

- name: install-k3d
- name: Install-k3d
run: "curl -s https://raw.githubusercontent.com/k3d-io/k3d/main/install.sh | bash"
shell: bash

- name: Deploy UDS Core bundle
# renovate: datasource=github-tags depName=defenseunicorns/uds-core versioning=semver
run: build/uds deploy k3d-core-istio-dev:0.16.1 --confirm
shell: bash

- name: Validate UDS Core deployment
run: |
build/uds zarf tools wait-for gateway admin-gateway -n istio-admin-gateway --timeout 10s
build/uds zarf tools wait-for gateway passthrough-gateway -n istio-passthrough-gateway --timeout 10s
build/uds zarf tools wait-for gateway tenant-gateway -n istio-tenant-gateway --timeout 10s
- name: Run UDS Core smoke test
run: build/uds run test:ci-uds-core-smoke-test
shell: bash
4 changes: 4 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ jobs:
env:
GITHUB_TOKEN: secrets.GITHUB_TOKEN

- name: Run UDS Core smoke test
run: build/uds run test:ci-uds-core-smoke-test
shell: bash

- name: Save logs
if: always()
uses: ./.github/actions/save-logs
Expand Down
11 changes: 11 additions & 0 deletions src/pkg/sources/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package sources

import (
"github.com/defenseunicorns/zarf/src/pkg/packager/filters"
zarfTypes "github.com/defenseunicorns/zarf/src/types"
)

Expand Down Expand Up @@ -33,3 +34,13 @@ func setAsYOLO(pkg *zarfTypes.ZarfPackage) {
pkg.Components[idx].Repos = []string{}
}
}

// handleFilter filters components and checks if a package is a partial package by checking its number of components
func handleFilter(pkg zarfTypes.ZarfPackage, filter filters.ComponentFilterStrategy) ([]zarfTypes.ZarfComponent, bool, error) {
numComponents := len(pkg.Components)
filteredComps, err := filter.Apply(pkg)
if err != nil {
return nil, false, err
}
return filteredComps, numComponents > len(filteredComps), nil
}
8 changes: 4 additions & 4 deletions src/pkg/sources/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ func (r *RemoteBundle) LoadPackage(dst *layout.PackagePaths, filter filters.Comp
return zarfTypes.ZarfPackage{}, nil, nil
}

pkg.Components, err = filter.Apply(pkg)
// filter pkg components and determine if its a partial pkg
filteredComps, isPartialPkg, err := handleFilter(pkg, filter)
if err != nil {
return pkg, nil, err
return zarfTypes.ZarfPackage{}, nil, err
}
pkg.Components = filteredComps

dst.SetFromLayers(layers)

isPartialPkg := r.PkgOpts.OptionalComponents != ""

err = sources.ValidatePackageIntegrity(dst, pkg.Metadata.AggregateChecksum, isPartialPkg)
if err != nil {
return zarfTypes.ZarfPackage{}, nil, err
Expand Down
8 changes: 4 additions & 4 deletions src/pkg/sources/tarball.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ func (t *TarballBundle) LoadPackage(dst *layout.PackagePaths, filter filters.Com
return zarfTypes.ZarfPackage{}, nil, nil
}

pkg.Components, err = filter.Apply(pkg)
// filter pkg components and determine if its a partial pkg
filteredComps, isPartialPkg, err := handleFilter(pkg, filter)
if err != nil {
return pkg, nil, err
return zarfTypes.ZarfPackage{}, nil, err
}
pkg.Components = filteredComps

dst.SetFromPaths(files)

isPartialPkg := t.PkgOpts.OptionalComponents != ""

if err := sources.ValidatePackageIntegrity(dst, pkg.Metadata.AggregateChecksum, isPartialPkg); err != nil {
return zarfTypes.ZarfPackage{}, nil, err
}
Expand Down
11 changes: 9 additions & 2 deletions src/test/bundles/14-optional-components/uds-bundle.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,21 @@ metadata:
version: 0.0.1

packages:
- name: init
repository: ghcr.io/defenseunicorns/packages/init
# renovate: datasource=github-tags depName=defenseunicorns/zarf
ref: v0.34.0

# deploys prometheus as a required component and upload-image as an optional component (with noOptionalComponents key)
- name: prometheus
repository: localhost:888/prometheus
ref: 0.0.1
optionalComponents:
- upload-image

- name: podinfo-and-nginx
path: ../../packages/podinfo-and-nginx
# deploys podinfo as an optional component and apache as a required component
- name: podinfo-nginx-apache
path: ../../packages/podinfo-nginx
ref: 0.0.1
optionalComponents:
- podinfo
11 changes: 5 additions & 6 deletions src/test/e2e/optional_bundle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@ import (
)

func TestBundleOptionalComponents(t *testing.T) {
deployZarfInit(t)
e2e.SetupDockerRegistry(t, 888)
defer e2e.TeardownRegistry(t, 888)

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

zarfPkgPath = "src/test/packages/prometheus"
Expand Down Expand Up @@ -90,8 +89,8 @@ func introspectOptionalComponentsBundle(t *testing.T) {
err = json.Unmarshal(rootManifesBytes, &bundleRootManifest)
require.NoError(t, err)

// grab the first pkg (note that it came from a remote source)
pkgManifestBytes, err := os.ReadFile(filepath.Join(blobsDir, bundleRootManifest.Layers[0].Digest.Encoded()))
// grab the second pkg (note that it came from a remote source)
pkgManifestBytes, err := os.ReadFile(filepath.Join(blobsDir, bundleRootManifest.Layers[1].Digest.Encoded()))
require.NoError(t, err)
remotePkgManifest := ocispec.Manifest{}
err = json.Unmarshal(pkgManifestBytes, &remotePkgManifest)
Expand All @@ -112,8 +111,8 @@ func introspectOptionalComponentsBundle(t *testing.T) {
}
require.True(t, verifyComponentNotIncluded)

// grab the second pkg (note that it came from a local source)
pkgManifestBytes, err = os.ReadFile(filepath.Join(blobsDir, bundleRootManifest.Layers[1].Digest.Encoded()))
// grab the third pkg (note that it came from a local source)
pkgManifestBytes, err = os.ReadFile(filepath.Join(blobsDir, bundleRootManifest.Layers[2].Digest.Encoded()))
require.NoError(t, err)
localPkgManifest := ocispec.Manifest{}
err = json.Unmarshal(pkgManifestBytes, &localPkgManifest)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
kind: ZarfPackageConfig
metadata:
name: podinfo-and-nginx
name: podinfo-nginx-apache
description: used to test bundles with optional components
version: 0.0.1

Expand Down
9 changes: 9 additions & 0 deletions tasks/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,12 @@ tasks:
description: removes bundles and zarf packages that have been created from previous test runs
actions:
- cmd: find src/test -type f -name '*.tar.zst' -delete

- name: ci-uds-core-smoke-test
description: deploy UDS Core and runs a couple of validations
actions:
- cmd: build/uds deploy k3d-core-istio-dev:0.16.1 --confirm
- cmd: |
build/uds zarf tools wait-for gateway admin-gateway -n istio-admin-gateway --timeout 10s
build/uds zarf tools wait-for gateway admin-gateway -n istio-admin-gateway --timeout 10s
build/uds zarf tools wait-for gateway admin-gateway -n istio-admin-gateway --timeout 10s
Loading