diff --git a/src/pkg/packager/variables.go b/src/pkg/packager/variables.go index 98ae8f005d..5b062fc50c 100644 --- a/src/pkg/packager/variables.go +++ b/src/pkg/packager/variables.go @@ -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" @@ -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] @@ -57,6 +56,12 @@ func (p *Packager) fillActiveTemplate() error { return nil } + // update the component templates on the package + err := p.findComponentTemplatesAndReload(&p.cfg.Pkg) + if err != nil { + return err + } + if err := promptAndSetTemplate("###ZARF_PKG_TMPL_", false); err != nil { return err } @@ -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) 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 +} diff --git a/src/test/e2e/51_oci_compose_test.go b/src/test/e2e/51_oci_compose_test.go index e45048d6e0..62a02ffe26 100644 --- a/src/test/e2e/51_oci_compose_test.go +++ b/src/test/e2e/51_oci_compose_test.go @@ -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 == import-component-local", + "import-component-local-relative == import-component-local-relative", + "import-component-wordpress == import-component-wordpress", + "import-component-oci == import-component-oci", + "file-imports == file-imports", + "import-helm-local == import-helm-local", + "import-helm-local-relative == import-helm-local-relative", + "import-helm-oci == import-helm-oci", + "import-repos == import-repos", + "import-images == import-images", + } + + for _, target := range targets { + suite.Contains(stdErr, target) + } + +} + func (suite *SkeletonSuite) Test_3_FilePaths() { suite.T().Log("E2E: Skeleton Package File Paths") diff --git a/src/test/packages/51-import-everything/zarf.yaml b/src/test/packages/51-import-everything/zarf.yaml index e6564c227e..e24239ceca 100644 --- a/src/test/packages/51-import-everything/zarf.yaml +++ b/src/test/packages/51-import-everything/zarf.yaml @@ -6,12 +6,14 @@ metadata: components: - name: import-component-local + description: "import-component-local == ###ZARF_COMPONENT_NAME###" required: false import: path: foo name: baz - name: import-component-local-relative + description: "import-component-local-relative == ###ZARF_COMPONENT_NAME###" required: false import: path: ../../../../examples/dos-games @@ -22,12 +24,14 @@ components: - files - name: import-component-wordpress + description: "import-component-wordpress == ###ZARF_COMPONENT_NAME###" required: false import: path: ../../../../examples/wordpress name: wordpress - name: import-component-oci + description: "import-component-oci == ###ZARF_COMPONENT_NAME###" required: false import: # name is optional, if not provided the name of the component will be used to import @@ -35,6 +39,7 @@ components: url: oci://localhost:555/helm-charts:0.0.1-skeleton - name: file-imports + description: "file-imports == ###ZARF_COMPONENT_NAME###" required: false cosignKeyPath: ../../../../cosign.pub files: @@ -64,6 +69,7 @@ components: - cmd: test ! -f files/zarf-readme.md - name: import-helm-local + description: "import-helm-local == ###ZARF_COMPONENT_NAME###" required: false charts: - name: podinfo @@ -83,6 +89,7 @@ components: condition: available - name: import-helm-local-relative + description: "import-helm-local-relative == ###ZARF_COMPONENT_NAME###" required: false charts: - name: podinfo @@ -102,6 +109,7 @@ components: condition: available - name: import-helm-oci + description: "import-helm-oci == ###ZARF_COMPONENT_NAME###" required: false charts: - name: oci-demo @@ -128,6 +136,7 @@ components: condition: ready - name: import-repos + description: "import-repos == ###ZARF_COMPONENT_NAME###" required: false repos: # Import a full repo via HTTPS @@ -136,6 +145,7 @@ components: - file:///tmp/nocode - name: import-images + description: "import-images == ###ZARF_COMPONENT_NAME###" required: false images: - ghcr.io/stefanprodan/podinfo:6.4.0