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: ensure we are pulling all components #543

Merged
merged 2 commits into from
Apr 2, 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
1 change: 1 addition & 0 deletions src/pkg/bundler/fetcher/fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ func NewPkgFetcher(pkg types.Package, fetcherConfig Config) (Fetcher, error) {
if err != nil {
return nil, err
}

fetcher = &remoteFetcher{
pkg: pkg,
cfg: fetcherConfig,
Expand Down
2 changes: 1 addition & 1 deletion src/pkg/bundler/fetcher/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func (f *remoteFetcher) Fetch() ([]ocispec.Descriptor, error) {
func (f *remoteFetcher) layersToLocalBundle(spinner *message.Spinner, currentPackageIter int, totalPackages int) ([]ocispec.Descriptor, error) {
spinner.Updatef("Fetching %s package layer metadata (package %d of %d)", f.pkg.Name, currentPackageIter, totalPackages)
// get only the layers that are required by the components
layersToCopy, err := utils.GetZarfLayers(*f.remote, f.pkgRootManifest)
layersToCopy, err := utils.GetZarfLayers(*f.remote, f.pkgRootManifest, f.pkg.OptionalComponents)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion src/pkg/bundler/pusher/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func (p *RemotePusher) PushManifest() (ocispec.Descriptor, error) {
func (p *RemotePusher) LayersToRemoteBundle(spinner *message.Spinner, currentPackageIter int, totalPackages int) ([]ocispec.Descriptor, error) {
spinner.Updatef("Fetching %s package layer metadata (package %d of %d)", p.pkg.Name, currentPackageIter, totalPackages)
// get only the layers that are required by the components
layersToCopy, err := utils.GetZarfLayers(p.cfg.RemoteSrc, p.cfg.PkgRootManifest)
layersToCopy, err := utils.GetZarfLayers(p.cfg.RemoteSrc, p.cfg.PkgRootManifest, p.pkg.OptionalComponents)
if err != nil {
return nil, err
}
Expand Down
21 changes: 11 additions & 10 deletions src/pkg/utils/oci.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,24 +261,25 @@ func EnsureOCIPrefix(source string) string {
}

// GetZarfLayers grabs the necessary Zarf pkg layers from a remote OCI registry
func GetZarfLayers(remote zoci.Remote, pkgRootManifest *oci.Manifest) ([]ocispec.Descriptor, error) {
// todo: ensure we are only pulling non-optional components
func GetZarfLayers(remote zoci.Remote, pkgRootManifest *oci.Manifest, optionalComponents []string) ([]ocispec.Descriptor, error) {
ctx := context.TODO()
zarfPkg, err := remote.FetchZarfYAML(ctx)
if err != nil {
return nil, err
}

// ensure we're only pulling required components and optional components
var components []zarfTypes.ZarfComponent
for _, layer := range pkgRootManifest.Layers {
// infer component name from layer title annotation
titleAnnotation := layer.Annotations[ocispec.AnnotationTitle]
isComponent := strings.HasPrefix(titleAnnotation, "components/") && strings.HasSuffix(titleAnnotation, ".tar")
if isComponent {
afterComponents := strings.Split(titleAnnotation, "components/")[1]
componentName := strings.Split(afterComponents, ".tar")[0]
components = append(components, zarfTypes.ZarfComponent{Name: componentName})
for _, c := range zarfPkg.Components {
if c.Required != nil || slices.Contains(optionalComponents, c.Name) {
components = append(components, c)
}
}
layersFromComponents, err := remote.LayersFromRequestedComponents(ctx, components)
if err != nil {
return nil, err
}

// get the layers that are always pulled
var metadataLayers []ocispec.Descriptor
for _, path := range zoci.PackageAlwaysPull {
Expand Down
14 changes: 14 additions & 0 deletions src/test/bundles/13-composable-component/uds-bundle.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
kind: UDSBundle
metadata:
name: with-composed
description: |
test bundle with a remote pkg with a:
- docker distribution manifest media type (quay images)
- composed component with only images
version: 0.0.1

packages:
- name: prometheus
# remote pkg ensures we're testing pulling composed components from OCI
repository: localhost:888/prometheus
ref: 0.0.1
16 changes: 16 additions & 0 deletions src/test/e2e/bundle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,22 @@ func validateMultiArchIndex(t *testing.T, index ocispec.Index) {
require.True(t, checkedARM)
}

func TestBundleWithComposedPkgComponent(t *testing.T) {
e2e.SetupDockerRegistry(t, 888)
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)
zarfPublish(t, pkg, "localhost:888")

bundleDir := "src/test/bundles/13-composable-component"
bundleName := "with-composed"
bundlePath := filepath.Join(bundleDir, fmt.Sprintf("uds-bundle-%s-%s-0.0.1.tar.zst", bundleName, e2e.Arch))
createLocal(t, bundleDir, e2e.Arch)
deploy(t, bundlePath)
remove(t, bundlePath)
}

func TestBundleTmpDir(t *testing.T) {
deployZarfInit(t)
e2e.CreateZarfPkg(t, "src/test/packages/podinfo", false)
Expand Down
13 changes: 13 additions & 0 deletions src/test/packages/prometheus/images/zarf.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
kind: ZarfPackageConfig
metadata:
name: prometheus-images
description: |
testing pkg component composition
version: 0.0.1

components:
- name: upload
required: true
description: Push quay image to the zarf registry
images:
- quay.io/prometheus/node-exporter:v1.7.0
21 changes: 21 additions & 0 deletions src/test/packages/prometheus/zarf.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
kind: ZarfPackageConfig
metadata:
name: prometheus
description: |
test pkg with a docker distribution manifest media type (quay images) and a component with only images
version: 0.0.1

components:
- name: upload-image
required: true
description: test composition
import:
path: images
name: upload
- name: deploy
required: true
charts:
- name: prometheus-node-exporter
url: https://prometheus-community.github.io/helm-charts
version: 4.32.0
namespace: prometheus
Loading