Skip to content

Commit

Permalink
fix(pkg): Handle single-target runtimes repackaging (#894)
Browse files Browse the repository at this point in the history
Reviewed-by: Cezar Craciunoiu <cezar.craciunoiu@unikraft.io>
Approved-by: Cezar Craciunoiu <cezar.craciunoiu@unikraft.io>
  • Loading branch information
craciunoiuc committed Oct 23, 2023
2 parents d2cff05 + 87c6a04 commit b74ce5e
Showing 1 changed file with 41 additions and 15 deletions.
56 changes: 41 additions & 15 deletions cmd/kraft/pkg/packager_kraftfile_runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,30 +99,56 @@ func (p *packagerKraftfileRuntime) Pack(ctx context.Context, opts *Pkg, args ...
packmanager.WithKConfig(kconfigs),
)
} else {
arch, err := ukarch.HostArchitecture()
if err != nil {
return fmt.Errorf("could not get host architecture: %w", err)
if opts.Platform != "" {
qopts = append(qopts,
packmanager.WithPlatform(opts.Platform),
)
}

plat, _, err := platform.Detect(ctx)
if err != nil {
return fmt.Errorf("could not get host platform: %w", err)
if opts.Architecture != "" {
qopts = append(qopts,
packmanager.WithArchitecture(opts.Architecture),
)
}

// Use host information
qopts = append(qopts,
packmanager.WithPlatform(plat.String()),
packmanager.WithArchitecture(arch),
)
}

packs, err := opts.pm.Catalog(ctx, qopts...)
if err != nil {
return fmt.Errorf("could not query catalog: %w", err)
} else if len(packs) == 0 {
return fmt.Errorf("coud not find runtime '%s'", opts.project.Runtime().Name())
} else if len(packs) > 1 {
return fmt.Errorf("could not find runtime: too many options")
} else if len(packs) > 1 && targ == nil && (opts.Architecture == "" || opts.Platform == "") {
// At this point, we have queried the registry without asking for the
// platform and architecture and received multiple options. Re-query the
// catalog with the host architecture and platform.

if opts.Architecture == "" {
opts.Architecture, err = ukarch.HostArchitecture()
if err != nil {
return fmt.Errorf("could not get host architecture: %w", err)
}
}
if opts.Platform == "" {
plat, _, err := platform.Detect(ctx)
if err != nil {
return fmt.Errorf("could not get host platform: %w", err)
}

opts.Platform = plat.String()
}

qopts = append(qopts,
packmanager.WithPlatform(opts.Platform),
packmanager.WithArchitecture(opts.Architecture),
)

packs, err = opts.pm.Catalog(ctx, qopts...)
if err != nil {
return fmt.Errorf("could not query catalog: %w", err)
} else if len(packs) == 0 {
return fmt.Errorf("coud not find runtime '%s'", opts.project.Runtime().Name())
} else if len(packs) > 1 {
return fmt.Errorf("could not find runtime: too many options")
}
}

// Create a temporary directory we can use to store the artifacts from
Expand Down

0 comments on commit b74ce5e

Please sign in to comment.