Skip to content

Commit

Permalink
Support stdinOnce, which allows run-once STDIN injection
Browse files Browse the repository at this point in the history
This allows containers to wait for input before startup by listening
on STDIN, and after STDIN is closed, continue running. Matches the
Docker syntax.
  • Loading branch information
smarterclayton committed Oct 17, 2015
1 parent b255e7c commit e929baf
Show file tree
Hide file tree
Showing 12 changed files with 34 additions and 6 deletions.
6 changes: 5 additions & 1 deletion api/swagger-spec/v1.json
Original file line number Diff line number Diff line change
Expand Up @@ -12986,7 +12986,11 @@
},
"stdin": {
"type": "boolean",
"description": "Whether this container should allocate a buffer for stdin in the container runtime. Default is false."
"description": "Whether this container should allocate a buffer for stdin in the container runtime. If this is not set, reads from stdin in the container will always result in EOF. Default is false."
},
"stdinOnce": {
"type": "boolean",
"description": "Whether the container runtime should close the stdin channel after it has been opened by a single attach. When stdin is true the stdin stream will remain open across multiple attach sessions. If stdinOnce is set to true, stdin is opened on container start, is empty until the first client attaches to stdin, and then remains open and accepts data until the client disconnects, at which time stdin is closed and remains closed until the container is restarted. If this flag is false, a container processes that reads from stdin will never receive an EOF. Default is false"
},
"tty": {
"type": "boolean",
Expand Down
6 changes: 5 additions & 1 deletion api/swagger-spec/v1beta1.json
Original file line number Diff line number Diff line change
Expand Up @@ -3537,7 +3537,11 @@
},
"stdin": {
"type": "boolean",
"description": "Whether this container should allocate a buffer for stdin in the container runtime. Default is false."
"description": "Whether this container should allocate a buffer for stdin in the container runtime. If this is not set, reads from stdin in the container will always result in EOF. Default is false."
},
"stdinOnce": {
"type": "boolean",
"description": "Whether the container runtime should close the stdin channel after it has been opened by a single attach. When stdin is true the stdin stream will remain open across multiple attach sessions. If stdinOnce is set to true, stdin is opened on container start, is empty until the first client attaches to stdin, and then remains open and accepts data until the client disconnects, at which time stdin is closed and remains closed until the container is restarted. If this flag is false, a container processes that reads from stdin will never receive an EOF. Default is false"
},
"tty": {
"type": "boolean",
Expand Down
1 change: 1 addition & 0 deletions pkg/api/deep_copy_generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ func deepCopy_api_Container(in Container, out *Container, c *conversion.Cloner)
out.SecurityContext = nil
}
out.Stdin = in.Stdin
out.StdinOnce = in.StdinOnce
out.TTY = in.TTY
return nil
}
Expand Down
5 changes: 3 additions & 2 deletions pkg/api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -794,8 +794,9 @@ type Container struct {

// Variables for interactive containers, these have very specialized use-cases (e.g. debugging)
// and shouldn't be used for general purpose containers.
Stdin bool `json:"stdin,omitempty"`
TTY bool `json:"tty,omitempty"`
Stdin bool `json:"stdin,omitempty"`
StdinOnce bool `json:"stdinOnce,omitempty"`
TTY bool `json:"tty,omitempty"`
}

// Handler defines a specific action that should be taken
Expand Down
2 changes: 2 additions & 0 deletions pkg/api/v1/conversion_generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ func autoconvert_api_Container_To_v1_Container(in *api.Container, out *Container
out.SecurityContext = nil
}
out.Stdin = in.Stdin
out.StdinOnce = in.StdinOnce
out.TTY = in.TTY
return nil
}
Expand Down Expand Up @@ -3305,6 +3306,7 @@ func autoconvert_v1_Container_To_api_Container(in *Container, out *api.Container
out.SecurityContext = nil
}
out.Stdin = in.Stdin
out.StdinOnce = in.StdinOnce
out.TTY = in.TTY
return nil
}
Expand Down
1 change: 1 addition & 0 deletions pkg/api/v1/deep_copy_generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ func deepCopy_v1_Container(in Container, out *Container, c *conversion.Cloner) e
out.SecurityContext = nil
}
out.Stdin = in.Stdin
out.StdinOnce = in.StdinOnce
out.TTY = in.TTY
return nil
}
Expand Down
11 changes: 10 additions & 1 deletion pkg/api/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -976,9 +976,18 @@ type Container struct {
// Variables for interactive containers, these have very specialized use-cases (e.g. debugging)
// and shouldn't be used for general purpose containers.

// Whether this container should allocate a buffer for stdin in the container runtime.
// Whether this container should allocate a buffer for stdin in the container runtime. If this
// is not set, reads from stdin in the container will always result in EOF.
// Default is false.
Stdin bool `json:"stdin,omitempty"`
// Whether the container runtime should close the stdin channel after it has been opened by
// a single attach. When stdin is true the stdin stream will remain open across multiple attach
// sessions. If stdinOnce is set to true, stdin is opened on container start, is empty until the
// first client attaches to stdin, and then remains open and accepts data until the client disconnects,
// at which time stdin is closed and remains closed until the container is restarted. If this
// flag is false, a container processes that reads from stdin will never receive an EOF.
// Default is false
StdinOnce bool `json:"stdinOnce,omitempty"`
// Whether this container should allocate a TTY for itself, also requires 'stdin' to be true.
// Default is false.
TTY bool `json:"tty,omitempty"`
Expand Down
3 changes: 2 additions & 1 deletion pkg/api/v1/types_swagger_doc_generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ var map_Container = map[string]string{
"terminationMessagePath": "Optional: Path at which the file to which the container's termination message will be written is mounted into the container's filesystem. Message written is intended to be brief final status, such as an assertion failure message. Defaults to /dev/termination-log. Cannot be updated.",
"imagePullPolicy": "Image pull policy. One of Always, Never, IfNotPresent. Defaults to Always if :latest tag is specified, or IfNotPresent otherwise. Cannot be updated. More info: http://releases.k8s.io/HEAD/docs/user-guide/images.md#updating-images",
"securityContext": "Security options the pod should run with. More info: http://releases.k8s.io/HEAD/docs/design/security_context.md",
"stdin": "Whether this container should allocate a buffer for stdin in the container runtime. Default is false.",
"stdin": "Whether this container should allocate a buffer for stdin in the container runtime. If this is not set, reads from stdin in the container will always result in EOF. Default is false.",
"stdinOnce": "Whether the container runtime should close the stdin channel after it has been opened by a single attach. When stdin is true the stdin stream will remain open across multiple attach sessions. If stdinOnce is set to true, stdin is opened on container start, is empty until the first client attaches to stdin, and then remains open and accepts data until the client disconnects, at which time stdin is closed and remains closed until the container is restarted. If this flag is false, a container processes that reads from stdin will never receive an EOF. Default is false",
"tty": "Whether this container should allocate a TTY for itself, also requires 'stdin' to be true. Default is false.",
}

Expand Down
1 change: 1 addition & 0 deletions pkg/apis/extensions/deep_copy_generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ func deepCopy_api_Container(in api.Container, out *api.Container, c *conversion.
out.SecurityContext = nil
}
out.Stdin = in.Stdin
out.StdinOnce = in.StdinOnce
out.TTY = in.TTY
return nil
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/apis/extensions/v1beta1/conversion_generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ func autoconvert_api_Container_To_v1_Container(in *api.Container, out *v1.Contai
out.SecurityContext = nil
}
out.Stdin = in.Stdin
out.StdinOnce = in.StdinOnce
out.TTY = in.TTY
return nil
}
Expand Down Expand Up @@ -1255,6 +1256,7 @@ func autoconvert_v1_Container_To_api_Container(in *v1.Container, out *api.Contai
out.SecurityContext = nil
}
out.Stdin = in.Stdin
out.StdinOnce = in.StdinOnce
out.TTY = in.TTY
return nil
}
Expand Down
1 change: 1 addition & 0 deletions pkg/apis/extensions/v1beta1/deep_copy_generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ func deepCopy_v1_Container(in v1.Container, out *v1.Container, c *conversion.Clo
out.SecurityContext = nil
}
out.Stdin = in.Stdin
out.StdinOnce = in.StdinOnce
out.TTY = in.TTY
return nil
}
Expand Down
1 change: 1 addition & 0 deletions pkg/kubelet/dockertools/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,7 @@ func (dm *DockerManager) runContainer(
Labels: labels,
// Interactive containers:
OpenStdin: container.Stdin,
StdinOnce: container.StdinOnce,
Tty: container.TTY,
},
}
Expand Down

0 comments on commit e929baf

Please sign in to comment.