NewClient returns a new containerd client
(cliContext *cli.Context, opts ...containerd.Opt)
| 58 | |
| 59 | // NewClient returns a new containerd client |
| 60 | func NewClient(cliContext *cli.Context, opts ...containerd.Opt) (*containerd.Client, context.Context, context.CancelFunc, error) { |
| 61 | timeoutOpt := containerd.WithTimeout(cliContext.Duration("connect-timeout")) |
| 62 | opts = append(opts, timeoutOpt) |
| 63 | socketPath := cliContext.String("address") |
| 64 | if _, err := os.Stat(socketPath); err != nil { |
| 65 | return nil, nil, nil, fmt.Errorf("cannot access socket %s: %w", socketPath, err) |
| 66 | } |
| 67 | client, err := containerd.New(socketPath, opts...) |
| 68 | if err != nil { |
| 69 | return nil, nil, nil, err |
| 70 | } |
| 71 | ctx, cancel := AppContext(cliContext) |
| 72 | var suppressDeprecationWarnings bool |
| 73 | if s := os.Getenv("CONTAINERD_SUPPRESS_DEPRECATION_WARNINGS"); s != "" { |
| 74 | suppressDeprecationWarnings, err = strconv.ParseBool(s) |
| 75 | if err != nil { |
| 76 | log.L.WithError(err).Warn("Failed to parse CONTAINERD_SUPPRESS_DEPRECATION_WARNINGS=" + s) |
| 77 | } |
| 78 | } |
| 79 | if !suppressDeprecationWarnings { |
| 80 | resp, err := client.IntrospectionService().Server(ctx) |
| 81 | if err != nil { |
| 82 | log.L.WithError(err).Warn("Failed to check deprecations") |
| 83 | } else { |
| 84 | for _, d := range resp.Deprecations { |
| 85 | log.L.Warn("DEPRECATION: " + d.Message) |
| 86 | } |
| 87 | } |
| 88 | } |
| 89 | return client, ctx, cancel, nil |
| 90 | } |
no test coverage detected
searching dependent graphs…