diff --git a/.github/workflows/nightly-uds-core.yaml b/.github/workflows/nightly-uds-core.yaml index 57de7c1b..e626d477 100644 --- a/.github/workflows/nightly-uds-core.yaml +++ b/.github/workflows/nightly-uds-core.yaml @@ -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 diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 3e1e6738..2cf61a11 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -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 diff --git a/src/pkg/sources/common.go b/src/pkg/sources/common.go index 7f47b252..d302af2a 100644 --- a/src/pkg/sources/common.go +++ b/src/pkg/sources/common.go @@ -5,6 +5,7 @@ package sources import ( + "github.com/defenseunicorns/zarf/src/pkg/packager/filters" zarfTypes "github.com/defenseunicorns/zarf/src/types" ) @@ -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 +} diff --git a/src/pkg/sources/remote.go b/src/pkg/sources/remote.go index 825bc616..7dc30537 100644 --- a/src/pkg/sources/remote.go +++ b/src/pkg/sources/remote.go @@ -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 diff --git a/src/pkg/sources/tarball.go b/src/pkg/sources/tarball.go index 0917aa5a..051c3256 100644 --- a/src/pkg/sources/tarball.go +++ b/src/pkg/sources/tarball.go @@ -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 } diff --git a/src/test/bundles/14-optional-components/uds-bundle.yaml b/src/test/bundles/14-optional-components/uds-bundle.yaml index e9486981..d41549af 100644 --- a/src/test/bundles/14-optional-components/uds-bundle.yaml +++ b/src/test/bundles/14-optional-components/uds-bundle.yaml @@ -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 diff --git a/src/test/e2e/optional_bundle_test.go b/src/test/e2e/optional_bundle_test.go index 4f53ceb1..13a52f2f 100644 --- a/src/test/e2e/optional_bundle_test.go +++ b/src/test/e2e/optional_bundle_test.go @@ -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" @@ -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) @@ -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) diff --git a/src/test/packages/podinfo-and-nginx/zarf.yaml b/src/test/packages/podinfo-nginx/zarf.yaml similarity index 92% rename from src/test/packages/podinfo-and-nginx/zarf.yaml rename to src/test/packages/podinfo-nginx/zarf.yaml index 09c8c62e..eb0dd34a 100644 --- a/src/test/packages/podinfo-and-nginx/zarf.yaml +++ b/src/test/packages/podinfo-nginx/zarf.yaml @@ -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 diff --git a/tasks/tests.yaml b/tasks/tests.yaml index 606c967b..647c7411 100644 --- a/tasks/tests.yaml +++ b/tasks/tests.yaml @@ -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