Kaynağa Gözat

Error on attempting service logs on TTY container

Right now getting logs from a service with an attached TTY does not
work. The behavior was undefined and caused the command to hang and
strange messages to occur in the daemon logs.

This returns errors, both deep in the swarmkit adapter (to guard against
undefined behavior, which is Bad) and in the daemon (to tell users that
the thing they're asking for is not possible).

Signed-off-by: Drew Erny <drew.erny@docker.com>
Drew Erny 8 yıl önce
ebeveyn
işleme
37ae1ef0ff

+ 6 - 0
daemon/cluster/executor/container/adapter.go

@@ -397,6 +397,12 @@ func (c *containerAdapter) deactivateServiceBinding() error {
 }
 }
 
 
 func (c *containerAdapter) logs(ctx context.Context, options api.LogSubscriptionOptions) (io.ReadCloser, error) {
 func (c *containerAdapter) logs(ctx context.Context, options api.LogSubscriptionOptions) (io.ReadCloser, error) {
+	// we can't handle the peculiarities of a TTY-attached container yet
+	conf := c.container.config()
+	if conf != nil && conf.Tty {
+		return nil, errors.New("logs not supported on containers with a TTY attached")
+	}
+
 	reader, writer := io.Pipe()
 	reader, writer := io.Pipe()
 
 
 	apiOptions := &backend.ContainerLogsConfig{
 	apiOptions := &backend.ContainerLogsConfig{

+ 7 - 0
daemon/cluster/services.go

@@ -262,6 +262,13 @@ func (c *Cluster) ServiceLogs(ctx context.Context, input string, config *backend
 		c.mu.RUnlock()
 		c.mu.RUnlock()
 		return err
 		return err
 	}
 	}
+	container := service.Spec.Task.GetContainer()
+	if container == nil {
+		return errors.New("service logs only supported for container tasks")
+	}
+	if container.TTY {
+		return errors.New("service logs not supported on tasks with a TTY attached")
+	}
 
 
 	// set the streams we'll use
 	// set the streams we'll use
 	stdStreams := []swarmapi.LogStream{}
 	stdStreams := []swarmapi.LogStream{}