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

Pass package architecture around through ImgConfigs #1497

Merged
merged 4 commits into from
Mar 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions src/cmd/tools/crane.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
)

func init() {
// No package information is available so do not pass in a list of architectures
cranePlatformOptions := config.GetCraneOptions(false)

craneLogin := craneCmd.NewCmdAuthLogin()
Expand Down
4 changes: 2 additions & 2 deletions src/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func GetDataInjectionMarker() string {
}

// GetCraneOptions returns a crane option object with the correct options & platform.
func GetCraneOptions(insecure bool) []crane.Option {
func GetCraneOptions(insecure bool, archs ...string) []crane.Option {
var options []crane.Option

// Handle insecure registry option
Expand All @@ -133,7 +133,7 @@ func GetCraneOptions(insecure bool) []crane.Option {
options = append(options,
crane.WithPlatform(&v1.Platform{
OS: "linux",
Architecture: GetArch(),
Architecture: GetArch(archs...),
}),
)

Expand Down
4 changes: 3 additions & 1 deletion src/internal/packager/images/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ type ImgConfig struct {
NoChecksum bool

Insecure bool

Architectures []string
}

// GetLegacyImgTarballPath returns the ImagesPath as if it were a path to a tarball instead of a directory.
Expand All @@ -38,7 +40,7 @@ func (i *ImgConfig) GetLegacyImgTarballPath() string {
func (i ImgConfig) LoadImageFromPackage(imgTag string) (v1.Image, error) {
// If the package still has a images.tar that contains all of the images, use crane to load the specific tag we want
if _, statErr := os.Stat(i.GetLegacyImgTarballPath()); statErr == nil {
return crane.LoadTag(i.GetLegacyImgTarballPath(), imgTag, config.GetCraneOptions(i.Insecure)...)
return crane.LoadTag(i.GetLegacyImgTarballPath(), imgTag, config.GetCraneOptions(i.Insecure, i.Architectures...)...)
}

// Load the image from the OCI formatted images directory
Expand Down
6 changes: 3 additions & 3 deletions src/internal/packager/images/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,11 @@ func (i *ImgConfig) PullImage(src string, spinner *message.Spinner) (img v1.Imag
// Load image tarballs from the local filesystem.
if strings.HasSuffix(src, ".tar") || strings.HasSuffix(src, ".tar.gz") || strings.HasSuffix(src, ".tgz") {
spinner.Updatef("Reading image tarball: %s", src)
return crane.Load(src, config.GetCraneOptions(true)...)
return crane.Load(src, config.GetCraneOptions(true, i.Architectures...)...)
}

// If crane is unable to pull the image, try to load it from the local docker daemon.
if _, err := crane.Manifest(src, config.GetCraneOptions(i.Insecure)...); err != nil {
if _, err := crane.Manifest(src, config.GetCraneOptions(i.Insecure, i.Architectures...)...); err != nil {
message.Debugf("crane unable to pull image %s: %s", src, err)
spinner.Updatef("Falling back to docker for %s. This may take some time.", src)

Expand Down Expand Up @@ -192,7 +192,7 @@ func (i *ImgConfig) PullImage(src string, spinner *message.Spinner) (img v1.Imag
}

// Manifest was found, so use crane to pull the image.
if img, err = crane.Pull(src, config.GetCraneOptions(i.Insecure)...); err != nil {
if img, err = crane.Pull(src, config.GetCraneOptions(i.Insecure, i.Architectures...)...); err != nil {
return nil, fmt.Errorf("failed to pull image %s: %w", src, err)
}

Expand Down
2 changes: 1 addition & 1 deletion src/internal/packager/images/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (i *ImgConfig) PushToZarfRegistry() error {
spinner := message.NewProgressSpinner("Storing images in the zarf registry")
defer spinner.Stop()

pushOptions := config.GetCraneOptions(i.Insecure)
pushOptions := config.GetCraneOptions(i.Insecure, i.Architectures...)
pushOptions = append(pushOptions, config.GetCraneAuthOption(i.RegInfo.PushUsername, i.RegInfo.PushPassword))

message.Debugf("crane pushOptions = %#v", pushOptions)
Expand Down
1 change: 1 addition & 0 deletions src/pkg/packager/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ func NewOrDie(config *types.PackagerConfig) *Packager {
func GetInitPackageName(arch string) string {
message.Debug("packager.GetInitPackageName()")
if arch == "" {
// No package has been loaded yet so lookup GetArch() with no package info
arch = config.GetArch()
}
return fmt.Sprintf("zarf-init-%s-%s.tar.zst", arch, config.CLIVersion)
Expand Down
10 changes: 6 additions & 4 deletions src/pkg/packager/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ func (p *Packager) Create(baseDir string) error {

ociPath := path.Join(p.tmp.Base, "seed-image")
imgConfig := images.ImgConfig{
Insecure: config.CommonOptions.Insecure,
Insecure: config.CommonOptions.Insecure,
Architectures: []string{p.cfg.Pkg.Metadata.Architecture, p.cfg.Pkg.Build.Architecture},
}

image, err := imgConfig.PullImage(seedImage, spinner)
Expand Down Expand Up @@ -157,9 +158,10 @@ func (p *Packager) Create(baseDir string) error {

doPull := func() error {
imgConfig := images.ImgConfig{
ImagesPath: p.tmp.Images,
ImgList: imgList,
Insecure: config.CommonOptions.Insecure,
ImagesPath: p.tmp.Images,
ImgList: imgList,
Insecure: config.CommonOptions.Insecure,
Architectures: []string{p.cfg.Pkg.Metadata.Architecture, p.cfg.Pkg.Build.Architecture},
}

return imgConfig.PullAll()
Expand Down
11 changes: 6 additions & 5 deletions src/pkg/packager/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,11 +387,12 @@ func (p *Packager) pushImagesToRegistry(componentImages []string, noImgChecksum
}

imgConfig := images.ImgConfig{
ImagesPath: p.tmp.Images,
ImgList: componentImages,
NoChecksum: noImgChecksum,
RegInfo: p.cfg.State.RegistryInfo,
Insecure: config.CommonOptions.Insecure,
ImagesPath: p.tmp.Images,
ImgList: componentImages,
NoChecksum: noImgChecksum,
RegInfo: p.cfg.State.RegistryInfo,
Insecure: config.CommonOptions.Insecure,
Architectures: []string{p.cfg.Pkg.Metadata.Architecture, p.cfg.Pkg.Build.Architecture},
}

return utils.Retry(func() error {
Expand Down