(ctx context.Context, t any, id string)
| 28 | } |
| 29 | |
| 30 | func (r *IDResolver) get(ctx context.Context, t any, id string) (string, error) { |
| 31 | switch t.(type) { |
| 32 | case swarm.Node: |
| 33 | res, err := r.client.NodeInspect(ctx, id, client.NodeInspectOptions{}) |
| 34 | if err != nil { |
| 35 | // TODO(thaJeztah): should error-handling be more specific, or is it ok to ignore any error? |
| 36 | return id, nil //nolint:nilerr // ignore nil-error being returned, as this is a best-effort. |
| 37 | } |
| 38 | if res.Node.Spec.Annotations.Name != "" { |
| 39 | return res.Node.Spec.Annotations.Name, nil |
| 40 | } |
| 41 | if res.Node.Description.Hostname != "" { |
| 42 | return res.Node.Description.Hostname, nil |
| 43 | } |
| 44 | return id, nil |
| 45 | case swarm.Service: |
| 46 | res, err := r.client.ServiceInspect(ctx, id, client.ServiceInspectOptions{}) |
| 47 | if err != nil { |
| 48 | // TODO(thaJeztah): should error-handling be more specific, or is it ok to ignore any error? |
| 49 | return id, nil //nolint:nilerr // ignore nil-error being returned, as this is a best-effort. |
| 50 | } |
| 51 | return res.Service.Spec.Annotations.Name, nil |
| 52 | default: |
| 53 | return "", errors.New("unsupported type") |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | // Resolve will attempt to resolve an ID to a Name by querying the manager. |
| 58 | // Results are stored into a cache. |
no test coverage detected