mirror of
https://github.com/psviderski/uncloud.git
synced 2026-11-10 12:44:16 +00:00
refactor(grpc-proxy): use Metadata.Err() method to get upstream error for a broadcasted request
This commit is contained in:
+3
-2
@@ -92,7 +92,7 @@ func (cli *Client) ListImages(ctx context.Context, filter api.ImageFilter) ([]ap
|
||||
ContainerdStore: msg.ContainerdStore,
|
||||
}
|
||||
|
||||
if msg.Metadata.Error == "" && len(msg.Images) > 0 {
|
||||
if msg.Metadata.Err() == nil && len(msg.Images) > 0 {
|
||||
if err = json.Unmarshal(msg.Images, &mi.Images); err != nil {
|
||||
return nil, fmt.Errorf("unmarshal images: %w", err)
|
||||
}
|
||||
@@ -104,6 +104,7 @@ func (cli *Client) ListImages(ctx context.Context, filter api.ImageFilter) ([]ap
|
||||
return machineImages, nil
|
||||
}
|
||||
|
||||
// TODO: move PushImageOptions to api package and include PushImage in ImageClient interface.
|
||||
type PushImageOptions struct {
|
||||
// AllMachines pushes the image to all machines in the cluster. Takes precedence over Machines field.
|
||||
AllMachines bool
|
||||
@@ -215,7 +216,7 @@ func (cli *Client) pushImageToMachine(
|
||||
Name: "%invalid-name-to-only-check-store-type%",
|
||||
})
|
||||
if err == nil {
|
||||
err = images[0].Error()
|
||||
err = images[0].Metadata.Err()
|
||||
}
|
||||
if err != nil {
|
||||
return fmt.Errorf("check Docker image store type on machine '%s': %w", machine.Name, err)
|
||||
|
||||
@@ -125,10 +125,10 @@ func (cli *Client) InspectService(ctx context.Context, nameOrID string) (api.Ser
|
||||
continue
|
||||
}
|
||||
|
||||
if mc.Metadata.Error != "" {
|
||||
if err := mc.Metadata.Err(); err != nil {
|
||||
// TODO: return failed machines in the response.
|
||||
tui.PrintWarning(fmt.Sprintf("failed to list containers on machine '%s': %s",
|
||||
mc.Metadata.MachineName, mc.Metadata.Error))
|
||||
mc.Metadata.MachineName, err))
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -333,10 +333,10 @@ func (cli *Client) ListServices(ctx context.Context) ([]api.Service, error) {
|
||||
// Group containers by service ID using the broadcast results.
|
||||
servicesByID := make(map[string]api.Service)
|
||||
for _, mc := range machineContainers {
|
||||
if mc.Metadata.Error != "" {
|
||||
if err := mc.Metadata.Err(); err != nil {
|
||||
// TODO: return failed machines in the response.
|
||||
tui.PrintWarning(fmt.Sprintf("failed to list containers on machine '%s': %s",
|
||||
mc.Metadata.MachineName, mc.Metadata.Error))
|
||||
mc.Metadata.MachineName, err))
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
@@ -70,10 +70,10 @@ func (cli *Client) ListVolumes(ctx context.Context, filter *api.VolumeFilter) ([
|
||||
continue
|
||||
}
|
||||
|
||||
if mv.Metadata.Error != "" {
|
||||
if err := mv.Metadata.Err(); err != nil {
|
||||
// TODO: return failed machines in the response.
|
||||
tui.PrintWarning(fmt.Sprintf("failed to list volumes on machine '%s': %s", mv.Metadata.MachineName,
|
||||
mv.Metadata.Error))
|
||||
err))
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user