(ctx context.Context, pkgLayout *layout.PackageLayout, component v1alpha1.ZarfComponent, opts DeployOptions)
| 643 | } |
| 644 | |
| 645 | func (d *deployer) installManifests(ctx context.Context, pkgLayout *layout.PackageLayout, component v1alpha1.ZarfComponent, opts DeployOptions) (_ []state.InstalledChart, err error) { |
| 646 | l := logger.From(ctx) |
| 647 | tmpDir, err := utils.MakeTempDir(config.CommonOptions.TempDirectory) |
| 648 | if err != nil { |
| 649 | return nil, err |
| 650 | } |
| 651 | defer func() { |
| 652 | err = errors.Join(err, os.RemoveAll(tmpDir)) |
| 653 | }() |
| 654 | manifestDir, err := pkgLayout.GetComponentDir(ctx, tmpDir, component.Name, layout.ManifestsComponentDir) |
| 655 | if err != nil { |
| 656 | return nil, err |
| 657 | } |
| 658 | |
| 659 | installedCharts := []state.InstalledChart{} |
| 660 | for _, manifest := range component.Manifests { |
| 661 | for idx := range manifest.Files { |
| 662 | manifest.Files[idx] = layout.ManifestFileName(manifest.Name, idx) |
| 663 | path := filepath.Join(manifestDir, manifest.Files[idx]) |
| 664 | if helpers.InvalidPath(path) { |
| 665 | return installedCharts, fmt.Errorf("unable to find manifest file %s", manifest.Files[idx]) |
| 666 | } |
| 667 | // Apply ###ZARF_VAR_*### substitution before Helm sees the file. |
| 668 | if err := d.vc.ReplaceTextTemplate(path); err != nil { |
| 669 | return installedCharts, fmt.Errorf("error templating manifest %s: %w", path, err) |
| 670 | } |
| 671 | if manifest.IsTemplate() { |
| 672 | l.Debug("start manifest template", "manifest", manifest.Name, "path", path) |
| 673 | objs, err := template.NewObjects(d.vals). |
| 674 | WithPackage(pkgLayout.Pkg). |
| 675 | WithVariables(d.vc.GetSetVariableMap()). |
| 676 | WithConstants(d.vc.GetConstants()). |
| 677 | WithState(template.StateAccess{State: d.s, AccessKeys: component.StateAccess}) |
| 678 | if err != nil { |
| 679 | return nil, err |
| 680 | } |
| 681 | if err := template.ApplyToFile(ctx, path, path, objs); err != nil { |
| 682 | return nil, err |
| 683 | } |
| 684 | } |
| 685 | } |
| 686 | // Move kustomizations to files now, applying ###ZARF_VAR_*### substitution as well. |
| 687 | for idx := range manifest.Kustomizations { |
| 688 | kustomization := layout.KustomizationFileName(manifest.Name, idx) |
| 689 | manifest.Files = append(manifest.Files, kustomization) |
| 690 | path := filepath.Join(manifestDir, kustomization) |
| 691 | if err := d.vc.ReplaceTextTemplate(path); err != nil { |
| 692 | return installedCharts, fmt.Errorf("error templating kustomization %s: %w", path, err) |
| 693 | } |
| 694 | } |
| 695 | |
| 696 | if manifest.Namespace == "" { |
| 697 | // Helm gets sad when you don't provide a namespace even though we aren't using helm templating |
| 698 | manifest.Namespace = corev1.NamespaceDefault |
| 699 | } |
| 700 | |
| 701 | // Create a helmChart and helm cfg from a given Zarf Manifest. |
| 702 | chart, helmChart, err := helm.ChartFromZarfManifest(manifest, manifestDir, pkgLayout.Pkg.Metadata.Name, component.Name) |
no test coverage detected