Skip to content

Commit

Permalink
Use a struct to describe ephemeral container spec in k8s api
Browse files Browse the repository at this point in the history
  • Loading branch information
verb committed Sep 27, 2017
1 parent abed337 commit c6a72ef
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 15 deletions.
14 changes: 9 additions & 5 deletions pkg/api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -3627,14 +3627,19 @@ type PodExecOptions struct {
// Command is the remote command to execute; argv array; not executed within a shell.
Command []string

// Name is the name of the Debug Container. Its presence will cause
// exec to create a Debug Container rather than performing a runtime exec.
AlphaName string
// Run Command in an ephemeral container which shares some namespaces with Container.
AlphaEphemeralContainer PodExecEphemeralContainerSpec
}

type PodExecEphemeralContainerSpec struct {
// Name is the name of the Ephemeral Container. This must be specified to create
// an Ephemeral Container rather than performing a runtime exec.
Name string

// Image is an optional container image name that will be used to for the Debug
// Container in the specified Pod with Command as ENTRYPOINT. If omitted a
// default image will be used.
AlphaImage string
Image string
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
Expand Down Expand Up @@ -4137,7 +4142,6 @@ const (
// Command to run for remote command execution
ExecCommandParam = "command"
// Name of Debug Container when executing container image
// TODO(verb): will this conflict with target container name?
ExecDebugNameParam = "name"
// Container Image for Debug Container
ExecImageParam = "image"
Expand Down
13 changes: 7 additions & 6 deletions pkg/registry/core/pod/strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,11 +417,11 @@ func streamParams(params url.Values, opts runtime.Object) error {
for _, c := range opts.Command {
params.Add("command", c)
}
if opts.AlphaName != "" {
params.Add(api.ExecDebugNameParam, opts.AlphaName)
if opts.AlphaEphemeralContainer.Name != "" {
params.Add(api.ExecDebugNameParam, opts.AlphaEphemeralContainer.Name)
}
if opts.AlphaImage != "" {
params.Add(api.ExecImageParam, opts.AlphaImage)
if opts.AlphaEphemeralContainer.Image != "" {
params.Add(api.ExecImageParam, opts.AlphaEphemeralContainer.Image)
}
case *api.PodAttachOptions:
if opts.Stdin {
Expand Down Expand Up @@ -472,11 +472,12 @@ func ExecLocation(
opts *api.PodExecOptions,
) (*url.URL, http.RoundTripper, error) {
kubeletPath := "exec"
if opts.AlphaName != "" || opts.AlphaImage != "" {
// BROKEN: opts.AlphaEphemeralContainer has not been populated from HTTP params
if opts.AlphaEphemeralContainer.Name != "" || opts.AlphaEphemeralContainer.Image != "" {
if !utilfeature.DefaultFeatureGate.Enabled(features.DebugContainers) {
return nil, nil, errors.NewBadRequest("debug containers feature disabled")
}
if opts.AlphaName == "" {
if opts.AlphaEphemeralContainer.Name == "" {
// TODO(verb): consider allowing either and defaulting/generating the other
return nil, nil, errors.NewBadRequest("Name required when Image specified")
}
Expand Down
13 changes: 9 additions & 4 deletions staging/src/k8s.io/api/core/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -4108,14 +4108,19 @@ type PodExecOptions struct {
// Command is the remote command to execute. argv array. Not executed within a shell.
Command []string `json:"command" protobuf:"bytes,6,rep,name=command"`

// Name is the name of the Debug Container. Its presence will cause
// exec to create a Debug Container rather than performing a runtime exec.
AlphaName string `json:"name" protobuf:"bytes,7,opt,name=name"`
// Run Command in an ephemeral container which shares some namespaces with Container.
AlphaEphemeralContainer PodExecEphemeralContainerSpec `json:"PodExecEphemeralContainerSpec,omitempty" protobuf:"bytes,7,opt,name=alphaEphemeralContainer"`
}

type PodExecEphemeralContainerSpec struct {
// Name is the name of the Ephemeral Container. This must be specified to create
// an Ephemeral Container rather than performing a runtime exec.
Name string `json:"name" protobuf:"bytes,1,opt,name=name"`

// Image is an optional container image name that will be used to for the Debug
// Container in the specified Pod with Command as ENTRYPOINT. If omitted a
// default image will be used.
AlphaImage string `json:"image" protobuf:"bytes,8,opt,name=image"`
Image string `json:"image" protobuf:"bytes,2,opt,name=image"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
Expand Down

0 comments on commit c6a72ef

Please sign in to comment.