forked from arcalot/arcaflow-engine-deployer-podman
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli_plugin.go
50 lines (41 loc) · 1.02 KB
/
cli_plugin.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
package podman
import (
"io"
log "go.arcalot.io/log/v2"
"go.flow.arcalot.io/podmandeployer/internal/cliwrapper"
)
type CliPlugin struct {
wrapper cliwrapper.CliWrapper
containerImage string
containerName string
config *Config
logger log.Logger
stdin io.WriteCloser
stdout io.ReadCloser
}
// TODO: unwrap the whole config
func (p *CliPlugin) Write(b []byte) (n int, err error) {
return p.stdin.Write(b)
}
func (p *CliPlugin) Read(b []byte) (n int, err error) {
return p.stdout.Read(b)
}
func (p *CliPlugin) Close() error {
if err := p.wrapper.KillAndClean(p.containerName); err != nil {
return err
}
if err := p.stdin.Close(); err != nil {
p.logger.Errorf("failed to close stdin pipe")
} else {
p.logger.Infof("stdin pipe successfully closed")
}
if err := p.stdout.Close(); err != nil {
p.logger.Infof("failed to close stdout pipe")
} else {
p.logger.Infof("stdout pipe successfully closed")
}
return nil
}
func (p *CliPlugin) ID() string {
return p.containerName
}