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

1888 - Template Component Fields into Components on Zarf.yaml #1923

Merged
merged 30 commits into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
80aeded
WIP
cmwylie19 Jul 26, 2023
5b3fcab
both charts working
cmwylie19 Jul 26, 2023
72abac4
lint
cmwylie19 Jul 26, 2023
9b3e396
lint function description
cmwylie19 Jul 26, 2023
edded3e
[TASK] refactor FindComponentTemplatesAndReload - need to move this t…
cmwylie19 Jul 26, 2023
d2a55e5
[TASK] refactor and fix tests
cmwylie19 Jul 26, 2023
e6b24a2
pipeline bb changes
cmwylie19 Jul 27, 2023
08a26ab
update findComponentTemplatesAndReload
cmwylie19 Jul 27, 2023
52f90cd
remove suffix from findComponentTemplatesAndReload
cmwylie19 Jul 27, 2023
0c8320b
makefile
cmwylie19 Jul 27, 2023
0836e28
makefile accidentally change
cmwylie19 Jul 27, 2023
039a65b
update tests
cmwylie19 Jul 27, 2023
ea474ed
new line
cmwylie19 Jul 27, 2023
a291371
WIP
cmwylie19 Jul 27, 2023
338d942
WIP
cmwylie19 Jul 27, 2023
5ab683e
unit test component names
cmwylie19 Jul 27, 2023
e42bcfe
move warnings into package
cmwylie19 Jul 27, 2023
ee87005
Merge branch 'main' into 1888
cmwylie19 Jul 27, 2023
0acc735
changes from upstream
cmwylie19 Jul 27, 2023
ebf0d5d
changes from upstream
cmwylie19 Jul 27, 2023
b468ffb
changes from upstream
cmwylie19 Jul 27, 2023
41ecc56
makefile accidentally change
cmwylie19 Jul 27, 2023
95cd497
changes from upstream
cmwylie19 Jul 27, 2023
a54abe0
changes from upstream
cmwylie19 Jul 27, 2023
304d5d7
Merge branch 'main' into 1888
Noxsios Jul 28, 2023
54b5473
changes around test to address PR comments
cmwylie19 Jul 29, 2023
57d2ab1
linting
cmwylie19 Jul 29, 2023
f9b0fd5
Merge branch 'main' into 1888
cmwylie19 Aug 1, 2023
d040e5b
Merge branch 'main' into 1888
cmwylie19 Aug 2, 2023
fd10125
Merge branch 'main' into 1888
Noxsios Aug 2, 2023
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
25 changes: 23 additions & 2 deletions src/pkg/packager/variables.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (

"github.com/defenseunicorns/zarf/src/config"
"github.com/defenseunicorns/zarf/src/config/lang"
"github.com/defenseunicorns/zarf/src/pkg/message"
"github.com/defenseunicorns/zarf/src/pkg/utils"
"github.com/defenseunicorns/zarf/src/pkg/utils/helpers"
"github.com/defenseunicorns/zarf/src/types"
Expand All @@ -31,7 +30,7 @@ func (p *Packager) fillActiveTemplate() error {

for key := range yamlTemplates {
if deprecated {
message.Warnf(lang.PkgValidateTemplateDeprecation, key, key, key)
p.warnings = append(p.warnings, fmt.Sprintf(lang.PkgValidateTemplateDeprecation, key, key, key))
}

_, present := setFromCLIConfig[key]
Expand All @@ -57,6 +56,12 @@ func (p *Packager) fillActiveTemplate() error {
return nil
}

// update the component templates on the package
err := p.findComponentTemplatesAndReload(&p.cfg.Pkg, "###ZARF_COMPONENT_")
if err != nil {
return err
}

if err := promptAndSetTemplate("###ZARF_PKG_TMPL_", false); err != nil {
return err
}
Expand Down Expand Up @@ -146,3 +151,19 @@ func (p *Packager) injectImportedConstant(importedConstant types.ZarfPackageCons
p.cfg.Pkg.Constants = append(p.cfg.Pkg.Constants, importedConstant)
}
}

// findComponentTemplatesAndReload appends ###ZARF_COMPONENT_NAME for each component, assigns value, and reloads
func (p *Packager) findComponentTemplatesAndReload(config any, prefix string) error {

// iterate through components to and find all ###ZARF_COMPONENT_NAME, assign to component Name and value
for i, component := range config.(*types.ZarfPackage).Components {
mappings := map[string]string{}
mappings["###ZARF_COMPONENT_NAME###"] = component.Name
err := utils.ReloadYamlTemplate(&config.(*types.ZarfPackage).Components[i], mappings)
if err != nil {
return err
}
}

return nil
}
27 changes: 27 additions & 0 deletions src/test/e2e/51_oci_compose_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,33 @@ func (suite *SkeletonSuite) Test_1_Compose() {
suite.NoError(err)
}

func (suite *SkeletonSuite) Test_2_Component_Templates() {
suite.T().Log("E2E: Component Templates")
e2e.SetupWithCluster(suite.T())
importEverythingPath := fmt.Sprintf("build/zarf-package-import-everything-%s-0.0.1.tar.zst", e2e.Arch)

_, stdErr, err := e2e.Zarf("package", "inspect", importEverythingPath)
suite.NoError(err)

targets := []string{
"import-component-local case was here",
"import-component-local-relative case was here",
"import-component-wordpress case was here",
"import-component-oci case was here",
"file-imports case was here",
"import-helm-local case was here",
"import-helm-local-relative",
"import-helm-oci case was here",
"import-repos case was here",
"import-images case was here",
}

for _, target := range targets {
suite.Contains(stdErr, target)
}
Noxsios marked this conversation as resolved.
Show resolved Hide resolved

}

func (suite *SkeletonSuite) Test_3_FilePaths() {
suite.T().Log("E2E: Skeleton Package File Paths")

Expand Down
10 changes: 10 additions & 0 deletions src/test/packages/51-import-everything/zarf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ metadata:

components:
- name: import-component-local
description: "###ZARF_COMPONENT_NAME### case was here"
cmwylie19 marked this conversation as resolved.
Show resolved Hide resolved
required: false
import:
path: foo
name: baz

- name: import-component-local-relative
description: "###ZARF_COMPONENT_NAME### case was here"
required: false
import:
path: ../../../../examples/dos-games
Expand All @@ -22,19 +24,22 @@ components:
- files

- name: import-component-wordpress
description: "###ZARF_COMPONENT_NAME### case was here"
required: false
import:
path: ../../../../examples/wordpress
name: wordpress

- name: import-component-oci
description: "###ZARF_COMPONENT_NAME### case was here"
required: false
import:
# name is optional, if not provided the name of the component will be used to import
name: demo-helm-local-chart
url: oci://localhost:555/helm-charts:0.0.1-skeleton

- name: file-imports
description: "###ZARF_COMPONENT_NAME### case was here"
required: false
cosignKeyPath: ../../../../cosign.pub
files:
Expand Down Expand Up @@ -64,6 +69,7 @@ components:
- cmd: test ! -f files/zarf-readme.md

- name: import-helm-local
description: "###ZARF_COMPONENT_NAME### case was here"
required: false
charts:
- name: podinfo
Expand All @@ -83,6 +89,7 @@ components:
condition: available

- name: import-helm-local-relative
description: "###ZARF_COMPONENT_NAME### case was here"
required: false
charts:
- name: podinfo
Expand All @@ -102,6 +109,7 @@ components:
condition: available

- name: import-helm-oci
description: "###ZARF_COMPONENT_NAME### case was here"
required: false
charts:
- name: oci-demo
Expand All @@ -128,6 +136,7 @@ components:
condition: ready

- name: import-repos
description: "###ZARF_COMPONENT_NAME### case was here"
required: false
repos:
# Import a full repo via HTTPS
Expand All @@ -136,6 +145,7 @@ components:
- file:///tmp/nocode

- name: import-images
description: "###ZARF_COMPONENT_NAME### case was here"
required: false
images:
- ghcr.io/stefanprodan/podinfo:6.4.0