New returns a new containerd client that is connected to the containerd instance provided by address
(address string, opts ...Opt)
| 102 | // New returns a new containerd client that is connected to the containerd |
| 103 | // instance provided by address |
| 104 | func New(address string, opts ...Opt) (*Client, error) { |
| 105 | var copts clientOpts |
| 106 | for _, o := range opts { |
| 107 | if err := o(&copts); err != nil { |
| 108 | return nil, err |
| 109 | } |
| 110 | } |
| 111 | if copts.timeout == 0 { |
| 112 | copts.timeout = 10 * time.Second |
| 113 | } |
| 114 | |
| 115 | c := &Client{ |
| 116 | defaultns: copts.defaultns, |
| 117 | } |
| 118 | |
| 119 | if copts.defaultRuntime != "" { |
| 120 | c.defaults.runtime = copts.defaultRuntime |
| 121 | } |
| 122 | |
| 123 | if copts.defaultSandboxer != "" { |
| 124 | c.defaults.sandboxer = copts.defaultSandboxer |
| 125 | } |
| 126 | |
| 127 | if copts.defaultPlatform != nil { |
| 128 | c.platform = copts.defaultPlatform |
| 129 | } else { |
| 130 | c.platform = platforms.Default() |
| 131 | } |
| 132 | |
| 133 | if copts.services != nil { |
| 134 | c.services = *copts.services |
| 135 | } |
| 136 | if address != "" { |
| 137 | backoffConfig := backoff.DefaultConfig |
| 138 | backoffConfig.MaxDelay = copts.timeout |
| 139 | connParams := grpc.ConnectParams{ |
| 140 | Backoff: backoffConfig, |
| 141 | MinConnectTimeout: copts.timeout, |
| 142 | } |
| 143 | gopts := []grpc.DialOption{ |
| 144 | grpc.WithTransportCredentials(insecure.NewCredentials()), |
| 145 | grpc.WithConnectParams(connParams), |
| 146 | grpc.WithContextDialer(dialer.ContextDialer), |
| 147 | } |
| 148 | if len(copts.dialOptions) > 0 { |
| 149 | gopts = copts.dialOptions |
| 150 | } |
| 151 | gopts = append(gopts, copts.extraDialOpts...) |
| 152 | |
| 153 | gopts = append(gopts, grpc.WithDefaultCallOptions( |
| 154 | grpc.MaxCallRecvMsgSize(defaults.DefaultMaxRecvMsgSize), |
| 155 | grpc.MaxCallSendMsgSize(defaults.DefaultMaxSendMsgSize))) |
| 156 | if len(copts.callOptions) > 0 { |
| 157 | gopts = append(gopts, grpc.WithDefaultCallOptions(copts.callOptions...)) |
| 158 | } |
| 159 | if copts.defaultns != "" { |
| 160 | unary, stream := newNSInterceptors(copts.defaultns) |
| 161 | gopts = append(gopts, grpc.WithChainUnaryInterceptor(unary)) |
no test coverage detected