MCPcopy
hub / github.com/zarf-dev/zarf / installManifests

Method installManifests

src/pkg/packager/deploy.go:645–729  ·  view source on GitHub ↗
(ctx context.Context, pkgLayout *layout.PackageLayout, component v1alpha1.ZarfComponent, opts DeployOptions)

Source from the content-addressed store, hash-verified

643}
644
645func (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)

Callers 1

deployComponentMethod · 0.95

Calls 15

FromFunction · 0.92
MakeTempDirFunction · 0.92
ManifestFileNameFunction · 0.92
NewObjectsFunction · 0.92
ApplyToFileFunction · 0.92
KustomizationFileNameFunction · 0.92
ChartFromZarfManifestFunction · 0.92
InstallOrUpgradeChartFunction · 0.92
GetComponentDirMethod · 0.80
ReplaceTextTemplateMethod · 0.80
WithStateMethod · 0.80
WithConstantsMethod · 0.80

Tested by

no test coverage detected