diff --git a/src/pkg/packager/common.go b/src/pkg/packager/common.go index e1cbfb0a20..4c603867f7 100644 --- a/src/pkg/packager/common.go +++ b/src/pkg/packager/common.go @@ -151,17 +151,6 @@ func NewOrDie(config *types.PackagerConfig, mods ...Modifier) *Packager { return pkgr } -// setTempDirectory sets the temp directory for the packager. -func (p *Packager) setTempDirectory(path string) error { - dir, err := utils.MakeTempDir(path) - if err != nil { - return fmt.Errorf("unable to create package temp paths: %w", err) - } - - p.layout = layout.New(dir) - return nil -} - // GetInitPackageName returns the formatted name of the init package. func GetInitPackageName(arch string) string { if arch == "" { @@ -200,6 +189,21 @@ func (p *Packager) ClearTempPaths() { _ = os.RemoveAll(layout.SBOMDir) } +// setTempDirectory sets the temp directory for the packager. +func (p *Packager) setTempDirectory(path string) error { + dir, err := utils.MakeTempDir(path) + if err != nil { + return fmt.Errorf("unable to create package temp paths: %w", err) + } + + p.layout = layout.New(dir) + return nil +} + +func (p *Packager) setArch() { + p.arch = config.GetArch(p.cfg.Pkg.Metadata.Architecture, p.cfg.Pkg.Build.Architecture) +} + // connectToCluster attempts to connect to a cluster if a connection is not already established func (p *Packager) connectToCluster(timeout time.Duration) (err error) { if p.isConnectedToCluster() { diff --git a/src/pkg/packager/create_stages.go b/src/pkg/packager/create_stages.go index e21a2343af..b7a2b45039 100644 --- a/src/pkg/packager/create_stages.go +++ b/src/pkg/packager/create_stages.go @@ -33,12 +33,13 @@ import ( ) func (p *Packager) load() error { - if err := p.readZarfYAML(layout.ZarfYAML); err != nil { + if err := utils.ReadYaml(layout.ZarfYAML, &p.cfg.Pkg); err != nil { return fmt.Errorf("unable to read the zarf.yaml file: %s", err.Error()) } if p.isInitConfig() { p.cfg.Pkg.Metadata.Version = config.CLIVersion } + p.setArch() // Compose components into a single zarf.yaml file if err := p.composeComponents(); err != nil { diff --git a/src/pkg/packager/deploy.go b/src/pkg/packager/deploy.go index 0e8c6e5c99..e7902acdb3 100644 --- a/src/pkg/packager/deploy.go +++ b/src/pkg/packager/deploy.go @@ -44,10 +44,10 @@ func (p *Packager) Deploy() (err error) { return fmt.Errorf("unable to load the package: %w", err) } - if err = p.readZarfYAML(p.layout.ZarfYAML); err != nil { + if err = utils.ReadYaml(layout.ZarfYAML, &p.cfg.Pkg); err != nil { return err } - + p.setArch() p.runMigrations() if err := p.validateLastNonBreakingVersion(); err != nil { diff --git a/src/pkg/packager/inspect.go b/src/pkg/packager/inspect.go index 993c9ffeb0..2fa154499c 100644 --- a/src/pkg/packager/inspect.go +++ b/src/pkg/packager/inspect.go @@ -6,6 +6,7 @@ package packager import ( "github.com/defenseunicorns/zarf/src/internal/packager/sbom" + "github.com/defenseunicorns/zarf/src/pkg/layout" "github.com/defenseunicorns/zarf/src/pkg/utils" ) @@ -17,9 +18,10 @@ func (p *Packager) Inspect() (err error) { return err } - if err = p.readZarfYAML(p.layout.ZarfYAML); err != nil { + if err = utils.ReadYaml(layout.ZarfYAML, &p.cfg.Pkg); err != nil { return err } + p.setArch() utils.ColorPrintYAML(p.cfg.Pkg, nil, false) diff --git a/src/pkg/packager/mirror.go b/src/pkg/packager/mirror.go index 689ddcfbaa..1d1b06cd2d 100644 --- a/src/pkg/packager/mirror.go +++ b/src/pkg/packager/mirror.go @@ -9,7 +9,9 @@ import ( "strings" "github.com/defenseunicorns/zarf/src/config" + "github.com/defenseunicorns/zarf/src/pkg/layout" "github.com/defenseunicorns/zarf/src/pkg/message" + "github.com/defenseunicorns/zarf/src/pkg/utils" "github.com/defenseunicorns/zarf/src/types" ) @@ -21,7 +23,7 @@ func (p *Packager) Mirror() (err error) { if err = p.source.LoadPackage(p.layout, true); err != nil { return fmt.Errorf("unable to load the package: %w", err) } - if err = p.readZarfYAML(p.layout.ZarfYAML); err != nil { + if err = utils.ReadYaml(layout.ZarfYAML, &p.cfg.Pkg); err != nil { return err } diff --git a/src/pkg/packager/prepare.go b/src/pkg/packager/prepare.go index 3bdde325d9..60b6b32b52 100644 --- a/src/pkg/packager/prepare.go +++ b/src/pkg/packager/prepare.go @@ -47,9 +47,10 @@ func (p *Packager) FindImages() (imgMap map[string][]string, err error) { } message.Note(fmt.Sprintf("Using build directory %s", p.cfg.CreateOpts.BaseDir)) - if err = p.readZarfYAML(layout.ZarfYAML); err != nil { + if err = utils.ReadYaml(layout.ZarfYAML, &p.cfg.Pkg); err != nil { return nil, fmt.Errorf("unable to read the zarf.yaml file: %s", err.Error()) } + p.setArch() if err := p.composeComponents(); err != nil { return nil, err diff --git a/src/pkg/packager/publish.go b/src/pkg/packager/publish.go index 05dcbc4a28..512ac52130 100644 --- a/src/pkg/packager/publish.go +++ b/src/pkg/packager/publish.go @@ -12,6 +12,7 @@ import ( "strings" "github.com/defenseunicorns/zarf/src/config" + "github.com/defenseunicorns/zarf/src/pkg/layout" "github.com/defenseunicorns/zarf/src/pkg/message" "github.com/defenseunicorns/zarf/src/pkg/oci" "github.com/defenseunicorns/zarf/src/pkg/packager/creator" @@ -103,7 +104,7 @@ func (p *Packager) Publish() (err error) { if err = p.source.LoadPackage(p.layout, false); err != nil { return fmt.Errorf("unable to load the package: %w", err) } - if err = p.readZarfYAML(p.layout.ZarfYAML); err != nil { + if err = utils.ReadYaml(layout.ZarfYAML, &p.cfg.Pkg); err != nil { return err } } diff --git a/src/pkg/packager/remove.go b/src/pkg/packager/remove.go index 2aaee0c3af..a09952ff8e 100644 --- a/src/pkg/packager/remove.go +++ b/src/pkg/packager/remove.go @@ -14,8 +14,10 @@ import ( "github.com/defenseunicorns/zarf/src/config" "github.com/defenseunicorns/zarf/src/internal/packager/helm" "github.com/defenseunicorns/zarf/src/pkg/cluster" + "github.com/defenseunicorns/zarf/src/pkg/layout" "github.com/defenseunicorns/zarf/src/pkg/message" "github.com/defenseunicorns/zarf/src/pkg/packager/sources" + "github.com/defenseunicorns/zarf/src/pkg/utils" "github.com/defenseunicorns/zarf/src/pkg/utils/helpers" "github.com/defenseunicorns/zarf/src/types" "helm.sh/helm/v3/pkg/storage/driver" @@ -38,7 +40,7 @@ func (p *Packager) Remove() (err error) { if err = p.source.LoadPackageMetadata(p.layout, false, false); err != nil { return err } - if err = p.readZarfYAML(p.layout.ZarfYAML); err != nil { + if err = utils.ReadYaml(layout.ZarfYAML, &p.cfg.Pkg); err != nil { return err } p.filterComponents() diff --git a/src/pkg/packager/yaml.go b/src/pkg/packager/yaml.go index 913f17c07c..5a1b4fd462 100644 --- a/src/pkg/packager/yaml.go +++ b/src/pkg/packager/yaml.go @@ -16,15 +16,6 @@ import ( "github.com/defenseunicorns/zarf/src/types" ) -// readZarfYAML reads a Zarf YAML file. -func (p *Packager) readZarfYAML(path string) error { - if err := utils.ReadYaml(path, &p.cfg.Pkg); err != nil { - return err - } - p.arch = config.GetArch(p.cfg.Pkg.Metadata.Architecture, p.cfg.Pkg.Build.Architecture) - return nil -} - // filterComponents removes components not matching the current OS if filterByOS is set. func (p *Packager) filterComponents() { // Filter each component to only compatible platforms.