Fix the auto restart fail when using LogURI and TTY together
Signed-off-by: Kay Yan <kay.yan@daocloud.io>
This commit is contained in:
parent
fec3191abc
commit
073de93086
14
cio/io.go
14
cio/io.go
@ -241,6 +241,20 @@ func LogURI(uri *url.URL) Creator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TerminalLogURI provides the raw logging URI
|
||||||
|
// as well as sets the terminal option to true.
|
||||||
|
func TerminalLogURI(uri *url.URL) Creator {
|
||||||
|
return func(_ string) (IO, error) {
|
||||||
|
return &logURI{
|
||||||
|
config: Config{
|
||||||
|
Stdout: uri.String(),
|
||||||
|
Stderr: uri.String(),
|
||||||
|
Terminal: true,
|
||||||
|
},
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// BinaryIO forwards container STDOUT|STDERR directly to a logging binary
|
// BinaryIO forwards container STDOUT|STDERR directly to a logging binary
|
||||||
func BinaryIO(binary string, args map[string]string) Creator {
|
func BinaryIO(binary string, args map[string]string) Creator {
|
||||||
return func(_ string) (IO, error) {
|
return func(_ string) (IO, error) {
|
||||||
|
@ -44,13 +44,21 @@ type startChange struct {
|
|||||||
|
|
||||||
func (s *startChange) apply(ctx context.Context, client *containerd.Client) error {
|
func (s *startChange) apply(ctx context.Context, client *containerd.Client) error {
|
||||||
log := cio.NullIO
|
log := cio.NullIO
|
||||||
|
spec, err := s.container.Spec(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
useTTY := spec.Process.Terminal
|
||||||
if s.logURI != "" {
|
if s.logURI != "" {
|
||||||
uri, err := url.Parse(s.logURI)
|
uri, err := url.Parse(s.logURI)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to parse %v into url: %w", s.logURI, err)
|
return fmt.Errorf("failed to parse %v into url: %w", s.logURI, err)
|
||||||
}
|
}
|
||||||
log = cio.LogURI(uri)
|
if useTTY {
|
||||||
|
log = cio.TerminalLogURI(uri)
|
||||||
|
} else {
|
||||||
|
log = cio.LogURI(uri)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if s.count > 0 {
|
if s.count > 0 {
|
||||||
|
Loading…
Reference in New Issue
Block a user