forked from containers/conmon-rs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.go
793 lines (650 loc) · 19.8 KB
/
client.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
package client
import (
"context"
"errors"
"fmt"
"io"
"net"
"os"
"os/exec"
"path/filepath"
"strconv"
"syscall"
"time"
"capnproto.org/go/capnp/v3"
"capnproto.org/go/capnp/v3/rpc"
"github.com/containers/conmon-rs/internal/proto"
"github.com/sirupsen/logrus"
)
const (
binaryName = "conmonrs"
socketName = "conmon.sock"
pidFileName = "pidfile"
defaultTimeout = 10 * time.Second
)
var (
errRuntimeUnspecified = errors.New("runtime must be specified")
errRunDirUnspecified = errors.New("RunDir must be specified")
errInvalidValue = errors.New("invalid value")
errRunDirNotCreated = errors.New("could not create RunDir")
errTimeoutWaitForPid = errors.New("timed out waiting for server PID to disappear")
errUndefinedCgroupManager = errors.New("undefined cgroup manager")
)
// ConmonClient is the main client structure of this package.
type ConmonClient struct {
serverPID uint32
runDir string
logger *logrus.Logger
}
// ConmonServerConfig is the configuration for the conmon server instance.
type ConmonServerConfig struct {
// ClientLogger can be set to use a custom logger rather than the
// logrus.StandardLogger.
ClientLogger *logrus.Logger
// ConmonServerPath is the binary path to the conmon server.
ConmonServerPath string
// LogLevel of the server to be used.
// Can be "trace", "debug", "info", "warn", "error" or "off".
LogLevel string
// LogDriver is the possible server logging driver.
// Can be "stdout" or "systemd".
LogDriver string
// Runtime is the binary path of the OCI runtime to use to operate on the
// containers.
Runtime string
// RuntimeRoot is the root directory used by the OCI runtime to operate on
// containers.
RuntimeRoot string
// ServerRunDir is the path of the directory for the server to hold files
// at runtime.
ServerRunDir string
// Stdout is the standard output stream of the server when the log driver
// "stdout" is being used (can be nil).
Stdout io.WriteCloser
// Stderr is the standard error stream of the server when the log driver
// "stdout" is being used (can be nil).
Stderr io.WriteCloser
// CgroupManager can be use to select the cgroup manager.
CgroupManager CgroupManager
}
// CgroupManager is the enum for all available cgroup managers.
type CgroupManager int
const (
// CgroupManagerSystemd specifies to use systemd to create and manage
// cgroups.
CgroupManagerSystemd CgroupManager = iota
// CgroupManagerCgroupfs specifies to use the cgroup filesystem to create
// and manage cgroups.
CgroupManagerCgroupfs
)
// NewConmonServerConfig creates a new ConmonServerConfig instance for the
// required arguments. Optional arguments are pointing to their corresponding
// default values.
func NewConmonServerConfig(
runtime, runtimeRoot, serverRunDir string,
) *ConmonServerConfig {
return &ConmonServerConfig{
LogLevel: LogLevelDebug,
LogDriver: LogDriverStdout,
Runtime: runtime,
RuntimeRoot: runtimeRoot,
ServerRunDir: serverRunDir,
Stdout: os.Stdout,
Stderr: os.Stderr,
}
}
// FromLogrusLevel converts the logrus.Level to a conmon-rs server log level.
func FromLogrusLevel(level logrus.Level) string {
switch level {
case logrus.PanicLevel, logrus.FatalLevel:
return LogLevelOff
case logrus.ErrorLevel:
return LogLevelError
case logrus.WarnLevel:
return LogLevelWarn
case logrus.InfoLevel:
return LogLevelInfo
case logrus.DebugLevel:
return LogLevelDebug
case logrus.TraceLevel:
return LogLevelTrace
}
return LogLevelDebug
}
// New creates a new conmon server, starts it and connects a new client to it.
func New(config *ConmonServerConfig) (client *ConmonClient, retErr error) {
cl, err := config.toClient()
if err != nil {
return nil, fmt.Errorf("convert config to client: %w", err)
}
// Check if the process has already started, and inherit that process instead.
ctx, cancel := defaultContext()
defer cancel()
if resp, err := cl.Version(ctx); err == nil {
cl.serverPID = resp.ProcessID
return cl, nil
}
if err := cl.startServer(config); err != nil {
return nil, fmt.Errorf("start server: %w", err)
}
pid, err := pidGivenFile(cl.pidFile())
if err != nil {
return nil, fmt.Errorf("get pid from env: %w", err)
}
cl.serverPID = pid
// Cleanup the background server process
// if we fail any of the next steps
defer func() {
if retErr != nil {
if err := cl.Shutdown(); err != nil {
cl.logger.Errorf("Unable to shutdown server: %v", err)
}
}
}()
if err := cl.waitUntilServerUp(); err != nil {
return nil, fmt.Errorf("wait until server is up: %w", err)
}
if err := os.Remove(cl.pidFile()); err != nil {
return nil, fmt.Errorf("remove pid file: %w", err)
}
return cl, nil
}
func (c *ConmonServerConfig) toClient() (*ConmonClient, error) {
const perm = 0o755
if err := os.MkdirAll(c.ServerRunDir, perm); err != nil && !os.IsExist(err) {
return nil, fmt.Errorf("%s: %w", c.ServerRunDir, errRunDirNotCreated)
}
if c.ClientLogger == nil {
c.ClientLogger = logrus.StandardLogger()
}
return &ConmonClient{
runDir: c.ServerRunDir,
logger: c.ClientLogger,
}, nil
}
func (c *ConmonClient) startServer(config *ConmonServerConfig) error {
entrypoint, args, err := c.toArgs(config)
if err != nil {
return fmt.Errorf("convert config to args: %w", err)
}
cmd := exec.Command(entrypoint, args...)
cmd.SysProcAttr = &syscall.SysProcAttr{
Setpgid: true,
}
if config.LogDriver == LogDriverStdout {
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if config.Stdout != nil {
cmd.Stdout = config.Stdout
}
if config.Stderr != nil {
cmd.Stderr = config.Stderr
}
}
if err := cmd.Run(); err != nil {
return fmt.Errorf("run server command: %w", err)
}
return nil
}
func (c *ConmonClient) toArgs(config *ConmonServerConfig) (entrypoint string, args []string, err error) {
if c == nil {
return "", args, nil
}
entrypoint = config.ConmonServerPath
if entrypoint == "" {
path, err := exec.LookPath(binaryName)
if err != nil {
return "", args, fmt.Errorf("finding path: %w", err)
}
entrypoint = path
}
if config.Runtime == "" {
return "", args, errRuntimeUnspecified
}
args = append(args, "--runtime", config.Runtime)
if config.ServerRunDir == "" {
return "", args, errRunDirUnspecified
}
args = append(args, "--runtime-dir", config.ServerRunDir)
if config.RuntimeRoot != "" {
args = append(args, "--runtime-root", config.RuntimeRoot)
}
if config.LogLevel != "" {
if err := validateLogLevel(config.LogLevel); err != nil {
return "", args, fmt.Errorf("validate log level: %w", err)
}
args = append(args, "--log-level", config.LogLevel)
}
if config.LogDriver != "" {
if err := validateLogDriver(config.LogDriver); err != nil {
return "", args, fmt.Errorf("validate log driver: %w", err)
}
args = append(args, "--log-driver", config.LogDriver)
}
const cgroupManagerFlag = "--cgroup-manager"
switch config.CgroupManager {
case CgroupManagerSystemd:
args = append(args, cgroupManagerFlag, "systemd")
case CgroupManagerCgroupfs:
args = append(args, cgroupManagerFlag, "cgroupfs")
default:
return "", args, errUndefinedCgroupManager
}
return entrypoint, args, nil
}
func validateLogLevel(level string) error {
return validateStringSlice(
"log level",
level,
LogLevelTrace, LogLevelDebug, LogLevelInfo, LogLevelWarn, LogLevelError, LogLevelOff,
)
}
func validateLogDriver(driver string) error {
return validateStringSlice(
"log driver",
driver,
LogDriverStdout, LogDriverSystemd,
)
}
func validateStringSlice(typ, given string, possibleValues ...string) error {
for _, possibleValue := range possibleValues {
if given == possibleValue {
return nil
}
}
return fmt.Errorf("%w: %s %q", errInvalidValue, typ, given)
}
func pidGivenFile(file string) (uint32, error) {
pidBytes, err := os.ReadFile(file)
if err != nil {
return 0, fmt.Errorf("reading pid bytes: %w", err)
}
const (
base = 10
bitSize = 32
)
pidU64, err := strconv.ParseUint(string(pidBytes), base, bitSize)
if err != nil {
return 0, fmt.Errorf("parsing pid: %w", err)
}
return uint32(pidU64), nil
}
func (c *ConmonClient) waitUntilServerUp() (err error) {
for i := 0; i < 100; i++ {
ctx, cancel := defaultContext()
_, err = c.Version(ctx)
if err == nil {
cancel()
break
}
cancel()
time.Sleep(1 * time.Millisecond)
}
return err
}
func defaultContext() (context.Context, context.CancelFunc) {
return context.WithTimeout(context.Background(), defaultTimeout)
}
func (c *ConmonClient) newRPCConn() (*rpc.Conn, error) {
socketConn, err := DialLongSocket("unix", c.socket())
if err != nil {
return nil, fmt.Errorf("dial long socket: %w", err)
}
return rpc.NewConn(rpc.NewStreamTransport(socketConn), nil), nil
}
// DialLongSocket is a wrapper around net.DialUnix.
// Its purpose is to allow for an arbitrarily long socket.
// It does so by opening the parent directory of path, and using the
// `/proc/self/fd` entry of that parent (which is a symlink to the actual parent)
// to construct the path to the socket.
// It assumes a valid path, as well as a file name that doesn't exceed the unix max socket length.
func DialLongSocket(network, path string) (*net.UnixConn, error) {
parent := filepath.Dir(path)
f, err := os.Open(parent)
if err != nil {
return nil, fmt.Errorf("open socket parent: %w", err)
}
defer f.Close()
socketName := filepath.Base(path)
const procSelfFDPath = "/proc/self/fd"
socketPath := filepath.Join(procSelfFDPath, strconv.Itoa(int(f.Fd())), socketName)
conn, err := net.DialUnix(network, nil, &net.UnixAddr{
Name: socketPath, Net: network,
})
if err != nil {
return nil, fmt.Errorf("dial unix socket: %w", err)
}
return conn, nil
}
// VersionResponse is the response of the Version method.
type VersionResponse struct {
// Version is the actual version string of the server.
Version string
// Tag is the git tag of the server, empty if no tag is available.
Tag string
// Commit is git commit SHA of the build.
Commit string
// BuildDate is the date of build.
BuildDate string
// RustVersion is the used Rust version.
RustVersion string
// ProcessID is the PID of the server.
ProcessID uint32
}
// Version can be used to retrieve all available version information.
func (c *ConmonClient) Version(ctx context.Context) (*VersionResponse, error) {
conn, err := c.newRPCConn()
if err != nil {
return nil, fmt.Errorf("create RPC connection: %w", err)
}
defer conn.Close()
client := proto.Conmon{Client: conn.Bootstrap(ctx)}
future, free := client.Version(ctx, nil)
defer free()
result, err := future.Struct()
if err != nil {
return nil, fmt.Errorf("create result: %w", err)
}
response, err := result.Response()
if err != nil {
return nil, fmt.Errorf("set response: %w", err)
}
version, err := response.Version()
if err != nil {
return nil, fmt.Errorf("set version: %w", err)
}
tag, err := response.Tag()
if err != nil {
return nil, fmt.Errorf("set tag: %w", err)
}
commit, err := response.Commit()
if err != nil {
return nil, fmt.Errorf("set commit: %w", err)
}
buildDate, err := response.BuildDate()
if err != nil {
return nil, fmt.Errorf("set build date: %w", err)
}
rustVersion, err := response.RustVersion()
if err != nil {
return nil, fmt.Errorf("set rust version: %w", err)
}
return &VersionResponse{
Version: version,
Tag: tag,
Commit: commit,
BuildDate: buildDate,
RustVersion: rustVersion,
ProcessID: response.ProcessId(),
}, nil
}
// CreateContainerConfig is the configuration for calling the CreateContainer
// method.
type CreateContainerConfig struct {
// ID is the container identifier.
ID string
// BundlePath is the path to the filesystem bundle.
BundlePath string
// Terminal indicates if a tty should be used or not.
Terminal bool
// ExitPaths is a slice of paths to write the exit statuses.
ExitPaths []string
// OOMExitPaths is a slice of files that should be created if the given container is OOM killed.
OOMExitPaths []string
// LogDrivers is a slice of selected log drivers.
LogDrivers []LogDriver
// CleanupCmd is the command that will be executed once the container exits
CleanupCmd []string
}
// LogDriver specifies a selected logging mechanism.
type LogDriver struct {
// Type defines the log driver variant.
Type LogDriverType
// Path specifies the filesystem path of the log driver.
Path string
// MaxSize is the maximum amount of bytes to be written before rotation.
// 0 translates to an unlimited size.
MaxSize uint64
}
// LogDriverType specifies available log drivers.
type LogDriverType int
const (
// LogDriverTypeContainerRuntimeInterface is the Kubernetes CRI logger
// type.
LogDriverTypeContainerRuntimeInterface LogDriverType = iota
)
// CreateContainerResponse is the response of the CreateContainer method.
type CreateContainerResponse struct {
// PID is the container process identifier.
PID uint32
}
// CreateContainer can be used to create a new running container instance.
func (c *ConmonClient) CreateContainer(
ctx context.Context, cfg *CreateContainerConfig,
) (*CreateContainerResponse, error) {
conn, err := c.newRPCConn()
if err != nil {
return nil, fmt.Errorf("create RPC connection: %w", err)
}
defer conn.Close()
client := proto.Conmon{Client: conn.Bootstrap(ctx)}
future, free := client.CreateContainer(ctx, func(p proto.Conmon_createContainer_Params) error {
req, err := p.NewRequest()
if err != nil {
return fmt.Errorf("create request: %w", err)
}
if err := req.SetId(cfg.ID); err != nil {
return fmt.Errorf("set ID: %w", err)
}
if err := req.SetBundlePath(cfg.BundlePath); err != nil {
return fmt.Errorf("set bundle path: %w", err)
}
req.SetTerminal(cfg.Terminal)
if err := stringSliceToTextList(cfg.ExitPaths, req.NewExitPaths); err != nil {
return fmt.Errorf("convert exit paths string slice to text list: %w", err)
}
if err := stringSliceToTextList(cfg.OOMExitPaths, req.NewOomExitPaths); err != nil {
return fmt.Errorf("convert oom exit paths string slice to text list: %w", err)
}
if err := stringSliceToTextList(cfg.OOMExitPaths, req.NewOomExitPaths); err != nil {
return err
}
if err := c.initLogDrivers(&req, cfg.LogDrivers); err != nil {
return fmt.Errorf("init log drivers: %w", err)
}
if err := p.SetRequest(req); err != nil {
return fmt.Errorf("set request: %w", err)
}
if err := stringSliceToTextList(cfg.CleanupCmd, req.NewCleanupCmd); err != nil {
return fmt.Errorf("convert cleanup command string slice to text list: %w", err)
}
return nil
})
defer free()
result, err := future.Struct()
if err != nil {
return nil, fmt.Errorf("create result: %w", err)
}
response, err := result.Response()
if err != nil {
return nil, fmt.Errorf("set response: %w", err)
}
return &CreateContainerResponse{
PID: response.ContainerPid(),
}, nil
}
// ExecSyncConfig is the configuration for calling the ExecSyncContainer
// method.
type ExecSyncConfig struct {
// ID is the container identifier.
ID string
// Command is a slice of command line arguments.
Command []string
// Timeout is the maximum time the command can run in seconds.
Timeout uint64
// Terminal specifies if a tty should be used.
Terminal bool
}
// ExecContainerResult is the result for calling the ExecSyncContainer method.
type ExecContainerResult struct {
// ExitCode specifies the returned exit status.
ExitCode int32
// Stdout contains the stdout stream result.
Stdout []byte
// Stderr contains the stderr stream result.
Stderr []byte
// TimedOut is true if the command timed out.
TimedOut bool
}
// ExecSyncContainer can be used to execute a command within a running
// container.
func (c *ConmonClient) ExecSyncContainer(ctx context.Context, cfg *ExecSyncConfig) (*ExecContainerResult, error) {
conn, err := c.newRPCConn()
if err != nil {
return nil, fmt.Errorf("create RPC connection: %w", err)
}
defer conn.Close()
client := proto.Conmon{Client: conn.Bootstrap(ctx)}
future, free := client.ExecSyncContainer(ctx, func(p proto.Conmon_execSyncContainer_Params) error {
req, err := p.NewRequest()
if err != nil {
return fmt.Errorf("create request: %w", err)
}
if err := req.SetId(cfg.ID); err != nil {
return fmt.Errorf("set ID: %w", err)
}
req.SetTimeoutSec(cfg.Timeout)
if err := stringSliceToTextList(cfg.Command, req.NewCommand); err != nil {
return err
}
req.SetTerminal(cfg.Terminal)
if err := p.SetRequest(req); err != nil {
return fmt.Errorf("set request: %w", err)
}
return nil
})
defer free()
result, err := future.Struct()
if err != nil {
return nil, fmt.Errorf("create result: %w", err)
}
resp, err := result.Response()
if err != nil {
return nil, fmt.Errorf("set response: %w", err)
}
stdout, err := resp.Stdout()
if err != nil {
return nil, fmt.Errorf("get stdout: %w", err)
}
stderr, err := resp.Stderr()
if err != nil {
return nil, fmt.Errorf("get stderr: %w", err)
}
execContainerResult := &ExecContainerResult{
ExitCode: resp.ExitCode(),
Stdout: stdout,
Stderr: stderr,
TimedOut: resp.TimedOut(),
}
return execContainerResult, nil
}
func stringSliceToTextList(src []string, newFunc func(int32) (capnp.TextList, error)) error {
l := int32(len(src))
if l == 0 {
return nil
}
list, err := newFunc(l)
if err != nil {
return err
}
for i := 0; i < len(src); i++ {
if err := list.Set(i, src[i]); err != nil {
return fmt.Errorf("set list element: %w", err)
}
}
return nil
}
func (c *ConmonClient) initLogDrivers(req *proto.Conmon_CreateContainerRequest, logDrivers []LogDriver) error {
newLogDrivers, err := req.NewLogDrivers(int32(len(logDrivers)))
if err != nil {
return fmt.Errorf("create log drivers: %w", err)
}
for i, logDriver := range logDrivers {
n := newLogDrivers.At(i)
if logDriver.Type == LogDriverTypeContainerRuntimeInterface {
n.SetType(proto.Conmon_LogDriver_Type_containerRuntimeInterface)
}
if err := n.SetPath(logDriver.Path); err != nil {
return fmt.Errorf("set log driver path: %w", err)
}
n.SetMaxSize(logDriver.MaxSize)
}
return nil
}
// PID returns the server process ID.
func (c *ConmonClient) PID() uint32 {
return c.serverPID
}
// Shutdown kill the server via SIGINT. Waits up to 10 seconds for the server
// PID to be removed from the system.
func (c *ConmonClient) Shutdown() error {
pid := int(c.serverPID)
if err := syscall.Kill(pid, syscall.SIGINT); err != nil {
return fmt.Errorf("kill server PID: %w", err)
}
const (
waitInterval = 100 * time.Millisecond
waitCount = 100
)
for i := 0; i < waitCount; i++ {
if err := syscall.Kill(pid, 0); errors.Is(err, syscall.ESRCH) {
return nil
}
time.Sleep(waitInterval)
}
return errTimeoutWaitForPid
}
func (c *ConmonClient) pidFile() string {
return filepath.Join(c.runDir, pidFileName)
}
func (c *ConmonClient) socket() string {
return filepath.Join(c.runDir, socketName)
}
// ReopenLogContainerConfig is the configuration for calling the
// ReopenLogContainer method.
type ReopenLogContainerConfig struct {
// ID is the container identifier.
ID string
}
// ReopenLogContainer can be used to rotate all configured container log
// drivers.
func (c *ConmonClient) ReopenLogContainer(ctx context.Context, cfg *ReopenLogContainerConfig) error {
conn, err := c.newRPCConn()
if err != nil {
return fmt.Errorf("create RPC connection: %w", err)
}
defer conn.Close()
client := proto.Conmon{Client: conn.Bootstrap(ctx)}
future, free := client.ReopenLogContainer(ctx, func(p proto.Conmon_reopenLogContainer_Params) error {
req, err := p.NewRequest()
if err != nil {
return fmt.Errorf("create request: %w", err)
}
if err := req.SetId(cfg.ID); err != nil {
return fmt.Errorf("set ID: %w", err)
}
if err := p.SetRequest(req); err != nil {
return fmt.Errorf("set request: %w", err)
}
return nil
})
defer free()
result, err := future.Struct()
if err != nil {
return fmt.Errorf("create result: %w", err)
}
if _, err := result.Response(); err != nil {
return fmt.Errorf("set response: %w", err)
}
return nil
}