Skip to content

Commit

Permalink
feat!: filter package components with strategy interface (#2321)
Browse files Browse the repository at this point in the history
## Description

Consolidate component filtering logic into a `filters` package. Each
filter is an implementation of

```go
// ComponentFilterStrategy is a strategy interface for filtering components.
type ComponentFilterStrategy interface {
	Apply(types.ZarfPackage) ([]types.ZarfComponent, error)
}
```

Public construction functions return instances of this interface _not_
instances of their underlying structs. Consumers should be fully
cognizant of which filter they are using, and should not be making a
common wrapper function (eg. `NewFilter(args...)` to dynamically return
a filter.

ex:

```go
func Empty() ComponentFilterStrategy {
	return &emptyFilter{}
}

// emptyFilter is a filter that does nothing.
type emptyFilter struct{}

// Apply returns the components unchanged.
func (f *emptyFilter) Apply(pkg types.ZarfPackage) ([]types.ZarfComponent, error) {
	return pkg.Components, nil
}
```

BREAKING CHANGES: This changes the interface signatures on
`sources.PackageSource` to reflect the new behavior whereupon the
`zarf.yaml` is loaded into memory within the sources load operations.
This allows for `filter`ing to take place during load and for the
`zarf.yaml` in memory to reflect these filter operations.

## Related Issue

Fixes #2320 

## Type of change

- [x] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Other (security config, docs update, etc)

## Checklist before merging

- [x] Test, docs, adr added or updated as needed
- [x] [Contributor Guide
Steps](https://github.com/defenseunicorns/zarf/blob/main/CONTRIBUTING.md#developer-workflow)
followed

---------

Signed-off-by: razzle <harry@razzle.cloud>
Co-authored-by: Wayne Starr <Racer159@users.noreply.github.com>
Co-authored-by: Lucas Rodriguez <lucas.rodriguez@defenseunicorns.com>
Co-authored-by: Lucas Rodriguez <lucas.rodriguez9616@gmail.com>
  • Loading branch information
4 people committed Mar 21, 2024
1 parent 6d2378d commit 95c42ff
Show file tree
Hide file tree
Showing 57 changed files with 1,530 additions and 823 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/nightly-eks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:

- name: Deploy the eks package
run: |
./build/zarf package deploy build/zarf-package-distro-eks-multi-0.0.3.tar.zst \
./build/zarf package deploy build/zarf-package-distro-eks-amd64-0.0.3.tar.zst \
--components=deploy-eks-cluster \
--set=EKS_CLUSTER_NAME=${{ inputs.cluster_name || 'zarf-nightly-eks-e2e-test' }} \
--set=EKS_INSTANCE_TYPE=${{ inputs.instance_type || 't3.medium' }} \
Expand All @@ -60,7 +60,7 @@ jobs:
- name: Teardown the cluster
if: always()
run: |
./build/zarf package deploy build/zarf-package-distro-eks-multi-0.0.3.tar.zst \
./build/zarf package deploy build/zarf-package-distro-eks-amd64-0.0.3.tar.zst \
--components=teardown-eks-cluster \
--set=EKS_CLUSTER_NAME=${{ inputs.cluster_name || 'zarf-nightly-eks-e2e-test' }} \
--confirm
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
<b class="YEL">Saving log file to
/var/folders/bk/rz1xx2sd5zn134c0_j1s2n5r0000gp/T/zarf-2023-03-23-13-18-54-4086179855.log</b>
<b class="BOLD" style="color:#55ff55;">? </b><b class="BOLD">Choose or type the package file </b><b class="WHI">zarf-package-helm-oci-chart-arm64-0.0.1.tar.zst</b><b class=CYN>[</b><b class=CYN>tab for suggestions]</b>
<b class=WHI> zarf-package-distro-eks-multi.tar.zst</b>
<b class=WHI> zarf-package-distro-eks-amd64.tar.zst</b>
<b class=CYN>> zarf-package-wordpress-amd64-16.0.4.tar.zst</b>
</pre>
</body>
Expand Down

0 comments on commit 95c42ff

Please sign in to comment.