BREAKING CHANGE: resolve gRPC API proxy targets (machines) on server instead of client, needs upgrade to v0.20 (#247)

Co-authored-by: Pasha Sviderski <me@psviderski.name>
This commit is contained in:
Justin Bradford
2026-05-19 15:22:50 +10:00
committed by GitHub
co-authored by Pasha Sviderski
parent 03ff4cd51d
commit c95136eae6
29 changed files with 914 additions and 741 deletions
+27 -24
View File
@@ -25,6 +25,7 @@ import (
"github.com/docker/docker/pkg/jsonmessage"
"github.com/docker/go-connections/nat"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/psviderski/uncloud/internal/cli/tui"
"github.com/psviderski/uncloud/internal/docker"
"github.com/psviderski/uncloud/internal/machine/api/pb"
"github.com/psviderski/uncloud/internal/machine/constants"
@@ -58,10 +59,7 @@ func (cli *Client) InspectRemoteImage(ctx context.Context, id string) ([]api.Mac
// it lists images on all machines.
func (cli *Client) ListImages(ctx context.Context, filter api.ImageFilter) ([]api.MachineImages, error) {
// Broadcast the image list request to the specified machines or all machines if none specified.
listCtx, machines, err := cli.ProxyMachinesContext(ctx, filter.Machines)
if err != nil {
return nil, fmt.Errorf("create request context to broadcast to machines: %w", err)
}
listCtx := cli.ProxyMachinesContext(ctx, filter.Machines)
opts := image.ListOptions{Manifests: true}
if filter.Name != "" {
@@ -80,32 +78,36 @@ func (cli *Client) ListImages(ctx context.Context, filter api.ImageFilter) ([]ap
return nil, err
}
machineImages := make([]api.MachineImages, len(resp.Messages))
for i, msg := range resp.Messages {
machineImages[i].Metadata = msg.Metadata
// TODO: handle this in the grpc-proxy router and always provide Metadata if possible.
machineImages := make([]api.MachineImages, 0, len(resp.Messages))
for _, msg := range resp.Messages {
// NOTE: Metadata should never be nil in practice. This is legacy fallback that will be removed.
if msg.Metadata == nil {
// Metadata can be nil if the request was broadcasted to only one machine.
machineImages[i].Metadata = &pb.Metadata{
Machine: machines[0].Machine.Id,
}
} else {
// Replace management IP with machine ID for friendlier error messages.
// TODO: migrate Metadata.Machine to use machine ID instead of IP in the grpc-proxy router.
if m := machines.FindByManagementIP(msg.Metadata.Machine); m != nil {
machineImages[i].Metadata.Machine = m.Machine.Id
}
if msg.Metadata.Error != "" {
continue
}
tui.PrintWarning("metadata is missing in response from unknown server")
continue
}
if msg.Metadata.Error != "" {
// Continue processing other messages even if some machines return an error to avoid a partial failure
// of the entire command.
tui.PrintWarning(fmt.Sprintf(
"failed to list images on machine %s: %s", msg.Metadata.MachineName, msg.Metadata.Error,
))
continue
}
mi := api.MachineImages{
Metadata: msg.Metadata,
ContainerdStore: msg.ContainerdStore,
}
if len(msg.Images) > 0 {
if err = json.Unmarshal(msg.Images, &machineImages[i].Images); err != nil {
if err = json.Unmarshal(msg.Images, &mi.Images); err != nil {
return nil, fmt.Errorf("unmarshal images: %w", err)
}
}
machineImages[i].ContainerdStore = msg.ContainerdStore
machineImages = append(machineImages, mi)
}
return machineImages, nil
@@ -350,7 +352,8 @@ func (cli *Client) pushImageToMachine(
pw.Event(progress.NewEvent(proxyEventID, progress.Error, err.Error()))
return fmt.Errorf("run socat container with unix socket to proxy unregistry: %w", err)
}
slog.Debug("Started unix socket socat proxy container.", "id", proxyCtrID, "hostPort", proxyPort, "socket", socketPath)
slog.Debug("Started unix socket socat proxy container.",
"id", proxyCtrID, "hostPort", proxyPort, "socket", socketPath)
}
pw.Event(progress.Event{