Skip to content
Open
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
16 changes: 12 additions & 4 deletions site/src/content/docs/ref/components.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,18 @@ When merging components together Zarf will adopt the following strategies depend

| Kind | Key(s) | Description |
|----------------------------|----------------------------------------|-------------|
| Component Behavior | `name`, `group`, `default`, `required` | These keys control how Zarf interacts with a given component and will *always* take the value of the overriding component |
| Component Description | `description` | This key will only take the value of the overriding component if it is not empty |
| Un'name'd Primitive Arrays | `actions`, `dataInjections`, `files`, `images`, `repos` | These keys will append the overriding component's version of the array to the end of the base component's array |
| 'name'd Primitive Arrays | `charts`, `manifests` | For any given element in the overriding component, if the element matches based on `name` then its values will be merged with the base element of the same `name`. If not then the element will be appended to the end of the array |
| Component Behavior | `name`, `group`, `default`, `required` | These keys control how Zarf interacts with a given component and will *always* take the value of the importing component |
| Component Description | `description` | This key will only take the value of the importing component if it is not empty, otherwise it will take the value of the imported component |
| Un'name'd Primitive Arrays | `actions`, `dataInjections`, `files`, `images`, `repos` | These keys will append the importing component's array to the end of the imported component's array |
| 'name'd Primitive Arrays | `charts`, `manifests` | For any given element in the importing component, if the element matches based on `name` then its values will be merged with the imported element of the same `name`. If not, then the element will be appended to the end of the array |

Some package level fields from imported components will also be merged with the importing package. These fields will be processed from the first component to the last component in a Zarf package definition.

| Kind | Field(s) | Description |
|----------------------------|--------------------------|-------------|
| 'name'd Globals | `constants`, `variables` | These fields will match on `name` building up a map as components are processed (starting with the importing package definition). Any names that already exist will be skipped so the parent or an earlier component import will take precedence. |
| Un'name'd Primitive Arrays | `values.files` | The importing package definition's array will be appended to the end of the array from the imported component's package definition. Elements will be reappended regardless of whether they already exist in the array (since merge order impacts the final values). |
| Global Behavior | `values.schema` | This field will always keep the value of the importing component's package definition (even if it is empty) |

### Health Checks

Expand Down
8 changes: 8 additions & 0 deletions src/pkg/packager/load/import.go
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we'll also want sourcePath/targetPath to work with imports with the parents sourcePath/targetPath taking priority

Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"fmt"
"os"
"path/filepath"
"slices"
"strings"
"time"

Expand Down Expand Up @@ -55,6 +56,7 @@ func resolveImports(ctx context.Context, pkg v1alpha1.ZarfPackage, packagePath,
"importStack", len(importStack),
)

var valuesFiles []string
variables := pkg.Variables
constants := pkg.Constants
components := []v1alpha1.ZarfComponent{}
Expand Down Expand Up @@ -156,8 +158,14 @@ func resolveImports(ctx context.Context, pkg v1alpha1.ZarfPackage, packagePath,
components = append(components, composed)
variables = append(variables, importedPkg.Variables...)
constants = append(constants, importedPkg.Constants...)
for _, v := range importedPkg.Values.Files {
valuesFiles = append(valuesFiles, makePathRelativeTo(v, importPath))
}
}

valuesFiles = append(valuesFiles, pkg.Values.Files...)
valuesFiles = slices.Compact(valuesFiles)
pkg.Values.Files = valuesFiles
pkg.Components = components

varMap := map[string]bool{}
Expand Down
2 changes: 1 addition & 1 deletion src/pkg/packager/load/import_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func TestResolveImports(t *testing.T) {
path: "./testdata/import/import-each-other",
},
{
name: "variables and constants are resolved correctly",
name: "variables, constants, and values are resolved correctly",
path: "./testdata/import/variables",
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ variables:
default: "default from child"
- name: SECONDARY_CHILD_VAR
default: "default from child in component imported later"
values:
files:
- child-values.yaml
- secondary-child-values.yaml
- parent-values.yaml
schema: "parent-values.schema.json"
components:
- name: first-imported-component
required: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ variables:
default: "default from child"
- name: CHILD_VAR
default: "default from child"
values:
files:
- ../child-values.yaml
schema: "child-values.schema.json"
components:
- name: first-imported-component
required: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ variables:
default: "default from child in component imported later"
- name: SECONDARY_CHILD_VAR
default: "default from child in component imported later"
values:
files:
- ../secondary-child-values.yaml
schema: "secondary-child-values.schema.json"
components:
- name: component-from-different-package
required: true
6 changes: 6 additions & 0 deletions src/pkg/packager/load/testdata/import/variables/zarf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,17 @@ constants:
variables:
- name: PARENT_VAR
default: "default from parent"
values:
files:
- parent-values.yaml
schema: "parent-values.schema.json"

components:
- name: first-imported-component
required: true
import:
path: import

- name: same-package-imported-again
required: true
import:
Expand Down
Loading