Skip to content

Commit

Permalink
CLOUDP-268554 Fix atlas deployments inspect errors not showing up (#3249
Browse files Browse the repository at this point in the history
)
  • Loading branch information
fmenezes authored Sep 10, 2024
1 parent b110ee6 commit c55b214
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
18 changes: 11 additions & 7 deletions internal/cli/deployments/diagnostics.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type diagnostic struct {
Version map[string]any
Images []string
Containers []*containerDiagnostic
Err error
Err string
}

type machineDiagnostic struct {
Expand All @@ -64,24 +64,26 @@ func (opts *diagnosticsOpts) Run(ctx context.Context) error {
Engine: opts.ContainerEngine.Name(),
}

errs := []error{}

cores, err := cpu.Counts(true)
if err != nil {
d.Err = errors.Join(d.Err, err)
errs = append(errs, err)
cores = -1
}
d.Machine.CPU = cores

v, err := mem.VirtualMemory()
if err != nil {
d.Err = errors.Join(d.Err, err)
errs = append(errs, err)
d.Machine.Memory = 0
} else {
d.Machine.Memory = v.Available
}

images, err := opts.ContainerEngine.ImageList(ctx, "mongodb/mongodb-atlas-local")
if err != nil {
d.Err = errors.Join(d.Err, err)
errs = append(errs, err)
} else {
for _, image := range images {
d.Images = append(d.Images, image.Repository+":"+image.Tag)
Expand All @@ -90,18 +92,18 @@ func (opts *diagnosticsOpts) Run(ctx context.Context) error {

d.Version, err = opts.ContainerEngine.Version(ctx)
if err != nil {
d.Err = errors.Join(d.Err, err)
errs = append(errs, err)
}

if opts.LocalMongodHostname() != "" {
inspectData, err := opts.ContainerEngine.ContainerInspect(ctx, opts.LocalMongodHostname())
if err != nil {
d.Err = errors.Join(d.Err, err)
errs = append(errs, err)
}

logs, err := opts.ContainerEngine.ContainerLogs(ctx, opts.LocalMongodHostname())
if err != nil {
d.Err = errors.Join(d.Err, err)
errs = append(errs, err)
}

d.Containers = append(d.Containers, &containerDiagnostic{
Expand All @@ -110,6 +112,8 @@ func (opts *diagnosticsOpts) Run(ctx context.Context) error {
})
}

d.Err = errors.Join(errs...).Error()

return opts.Print(d)
}

Expand Down
2 changes: 1 addition & 1 deletion internal/container/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ func (e *dockerImpl) ContainerInspect(ctx context.Context, names ...string) ([]*
}

func (e *dockerImpl) ImageList(ctx context.Context, references ...string) ([]Image, error) {
args := []string{"image", "ls", "--format", "{{.}}"}
args := []string{"image", "ls", "--format", "{{. | json}}"}

if len(references) > 0 {
for _, name := range references {
Expand Down

0 comments on commit c55b214

Please sign in to comment.