Skip to content

Commit

Permalink
fix(pkg): Handle offline-first re-packaging (#925)
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 25, 2023
2 parents 909e41a + 3eb3ebc commit dddb0c9
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions internal/cli/kraft/pkg/packager_kraftfile_runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ func (p *packagerKraftfileRuntime) Pack(ctx context.Context, opts *PkgOptions, a
qopts := []packmanager.QueryOption{
packmanager.WithName(opts.project.Runtime().Name()),
packmanager.WithVersion(opts.project.Runtime().Version()),
packmanager.WithUpdate(true),
}

if len(targets) == 1 {
Expand Down Expand Up @@ -111,12 +110,22 @@ func (p *packagerKraftfileRuntime) Pack(ctx context.Context, opts *PkgOptions, a
}
}

packs, err := opts.pm.Catalog(ctx, qopts...)
packs, err := opts.pm.Catalog(ctx, append(qopts, packmanager.WithUpdate(false))...)
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 && targ == nil && (opts.Architecture == "" || opts.Platform == "") {
// Try again with a remote update request. Save this to qopts in case we
// need to call `Catalog` again.
qopts = append(qopts, packmanager.WithUpdate(true))
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())
}
}

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.
Expand Down Expand Up @@ -149,6 +158,11 @@ func (p *packagerKraftfileRuntime) Pack(ctx context.Context, opts *PkgOptions, a
} else if len(packs) > 1 {
return fmt.Errorf("could not find runtime: too many options")
}

log.G(ctx).
WithField("arch", opts.Architecture).
WithField("plat", opts.Platform).
Info("using")
}

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

0 comments on commit dddb0c9

Please sign in to comment.