-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: introduce the
only.flavor
key to allow building of package va…
…riants (#2105) ## Description This implements the `only.flavor` filter as a replacement for component groups to allow the feature to be more declarative when building package variants. ## Related Issue Fixes #2101 ## Type of change - [ ] 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 - [ ] 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 <[email protected]> Co-authored-by: razzle <[email protected]>
- Loading branch information
Showing
20 changed files
with
351 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import ExampleYAML from "@site/src/components/ExampleYAML"; | ||
|
||
# Package Flavors | ||
|
||
This example demonstrates how to define variants of packages within the same package definition. This can be combined with [Composable Packages](../composable-packages/README.md) to build up packages and include the necessary [merge overrides](../composable-packages/README.md#merge-strategies) for each variant. | ||
|
||
Given package flavors are built by specifying the `--flavor` flag on `zarf package create`. This will include any components that match that flavor or that do not specify a flavor. | ||
|
||
## `zarf.yaml` {#zarf.yaml} | ||
|
||
:::info | ||
|
||
To view the example in its entirety, select the `Edit this page` link below the article and select the parent folder. | ||
|
||
::: | ||
|
||
<ExampleYAML src={require('./zarf.yaml')} showLink={false} /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
apiVersion: v1 | ||
kind: Pod | ||
metadata: | ||
name: enterprise-linux | ||
labels: | ||
app: enterprise-linux | ||
spec: | ||
containers: | ||
- name: enterprise-linux-container | ||
image: "###ZARF_VAR_IMAGE###" | ||
command: [ "sh", "-c", "while true; do ls; sleep 1; done"] | ||
resources: | ||
requests: | ||
memory: "32Mi" | ||
cpu: "50m" | ||
limits: | ||
memory: "128Mi" | ||
cpu: "250m" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
kind: ZarfPackageConfig | ||
metadata: | ||
name: package-flavors | ||
description: Simple example to show how to use the `only.flavor` key to build package variants. | ||
|
||
components: | ||
- name: image | ||
required: true | ||
description: "Sets the Enterprise Linux flavor to Rocky Linux" | ||
only: | ||
flavor: rocky-road | ||
images: | ||
- rockylinux:9-minimal | ||
actions: | ||
onDeploy: | ||
before: | ||
- cmd: echo "rockylinux:9-minimal" | ||
setVariables: | ||
- name: IMAGE | ||
|
||
- name: image | ||
required: true | ||
description: "Sets the Enterprise Linux flavor to Oracle Linux" | ||
only: | ||
flavor: oracle-cookie-crunch | ||
images: | ||
- oraclelinux:9-slim | ||
actions: | ||
onDeploy: | ||
before: | ||
- cmd: echo "oraclelinux:9-slim" | ||
setVariables: | ||
- name: IMAGE | ||
|
||
- name: image | ||
required: true | ||
description: "Sets the Enterprise Linux flavor to Alma Linux" | ||
only: | ||
flavor: vanilla-alma-nd | ||
images: | ||
- almalinux:9-minimal | ||
actions: | ||
onDeploy: | ||
before: | ||
- cmd: echo "almalinux:9-minimal" | ||
setVariables: | ||
- name: IMAGE | ||
|
||
- name: image | ||
required: true | ||
description: "Sets the Enterprise Linux flavor to OpenSUSE" | ||
only: | ||
flavor: strawberry-suse | ||
images: | ||
- opensuse/leap:15 | ||
actions: | ||
onDeploy: | ||
before: | ||
- cmd: echo "opensuse/leap:15" | ||
setVariables: | ||
- name: IMAGE | ||
|
||
- name: pod | ||
description: "The pod that runs the specified flavor of Enterprise Linux" | ||
required: true | ||
manifests: | ||
- name: enterprise-linux | ||
namespace: enterprise-linux | ||
files: | ||
- pod.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// SPDX-FileCopyrightText: 2021-Present The Zarf Authors | ||
|
||
// Package test provides e2e tests for Zarf. | ||
package test | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
"github.com/stretchr/testify/suite" | ||
) | ||
|
||
type FlavorSuite struct { | ||
suite.Suite | ||
*require.Assertions | ||
} | ||
|
||
var ( | ||
flavorExample = filepath.Join("examples", "package-flavors") | ||
flavorTest = filepath.Join("src", "test", "packages", "10-package-flavors") | ||
flavorExamplePath string | ||
flavorTestAMDPath = filepath.Join("build", "zarf-package-test-package-flavors-amd64.tar.zst") | ||
flavorTestARMPath = filepath.Join("build", "zarf-package-test-package-flavors-arm64.tar.zst") | ||
) | ||
|
||
func (suite *FlavorSuite) SetupSuite() { | ||
suite.Assertions = require.New(suite.T()) | ||
|
||
// Setup the example package path after e2e has been initialized | ||
flavorExamplePath = filepath.Join("build", fmt.Sprintf("zarf-package-package-flavors-%s.tar.zst", e2e.Arch)) | ||
} | ||
|
||
func (suite *FlavorSuite) TearDownSuite() { | ||
err := os.RemoveAll(flavorExamplePath) | ||
suite.NoError(err) | ||
err = os.RemoveAll(flavorTestAMDPath) | ||
suite.NoError(err) | ||
err = os.RemoveAll(flavorTestARMPath) | ||
suite.NoError(err) | ||
} | ||
|
||
func (suite *FlavorSuite) Test_0_FlavorExample() { | ||
suite.T().Log("E2E: Package Flavor Example") | ||
|
||
_, stdErr, err := e2e.Zarf("package", "create", flavorExample, "-o", "build", "--flavor", "oracle-cookie-crunch", "--no-color", "--confirm") | ||
suite.NoError(err) | ||
|
||
// Ensure that the oracle image is included | ||
suite.Contains(stdErr, `oraclelinux:9-slim`) | ||
|
||
// Ensure that the common pod was included | ||
suite.Contains(stdErr, `description: The pod that runs the specified flavor of Enterprise Linux`) | ||
|
||
// Ensure that the other flavors are not included | ||
suite.NotContains(stdErr, `rockylinux:9-minimal`) | ||
suite.NotContains(stdErr, `almalinux:9-minimal`) | ||
suite.NotContains(stdErr, `opensuse/leap:15`) | ||
} | ||
|
||
func (suite *FlavorSuite) Test_1_FlavorArchFiltering() { | ||
suite.T().Log("E2E: Package Flavor + Arch Filtering") | ||
|
||
_, stdErr, err := e2e.Zarf("package", "create", flavorTest, "-o", "build", "--flavor", "vanilla", "-a", "amd64", "--no-color", "--confirm") | ||
suite.NoError(err) | ||
|
||
// Ensure that the initial filter was applied | ||
suite.Contains(stdErr, ` | ||
- name: combined | ||
description: vanilla-amd`) | ||
|
||
// Ensure that the import filter was applied | ||
suite.Contains(stdErr, ` | ||
- name: via-import | ||
description: vanilla-amd`) | ||
|
||
// Ensure that the other flavors / architectures are not included | ||
suite.NotContains(stdErr, `vanilla-arm`) | ||
suite.NotContains(stdErr, `chocolate-amd`) | ||
suite.NotContains(stdErr, `chocolate-arm`) | ||
|
||
_, stdErr, err = e2e.Zarf("package", "create", flavorTest, "-o", "build", "--flavor", "chocolate", "-a", "amd64", "--no-color", "--confirm") | ||
suite.NoError(err) | ||
|
||
// Ensure that the initial filter was applied | ||
suite.Contains(stdErr, ` | ||
- name: combined | ||
description: chocolate-amd`) | ||
|
||
// Ensure that the import filter was applied | ||
suite.Contains(stdErr, ` | ||
- name: via-import | ||
description: chocolate-amd`) | ||
|
||
// Ensure that the other flavors / architectures are not included | ||
suite.NotContains(stdErr, `vanilla-arm`) | ||
suite.NotContains(stdErr, `vanilla-amd`) | ||
suite.NotContains(stdErr, `chocolate-arm`) | ||
|
||
_, stdErr, err = e2e.Zarf("package", "create", flavorTest, "-o", "build", "--flavor", "chocolate", "-a", "arm64", "--no-color", "--confirm") | ||
suite.NoError(err) | ||
|
||
// Ensure that the initial filter was applied | ||
suite.Contains(stdErr, ` | ||
- name: combined | ||
description: chocolate-arm`) | ||
|
||
// Ensure that the import filter was applied | ||
suite.Contains(stdErr, ` | ||
- name: via-import | ||
description: chocolate-arm`) | ||
|
||
// Ensure that the other flavors / architectures are not included | ||
suite.NotContains(stdErr, `vanilla-arm`) | ||
suite.NotContains(stdErr, `vanilla-amd`) | ||
suite.NotContains(stdErr, `chocolate-amd`) | ||
} | ||
|
||
func TestFlavorSuite(t *testing.T) { | ||
e2e.SetupWithCluster(t) | ||
|
||
suite.Run(t, new(FlavorSuite)) | ||
} |
Oops, something went wrong.