Skip to content

Commit c6a72ef

Browse files
committed
Use a struct to describe ephemeral container spec in k8s api
1 parent abed337 commit c6a72ef

File tree

3 files changed

+25
-15
lines changed

3 files changed

+25
-15
lines changed

pkg/api/types.go

+9-5
Original file line numberDiff line numberDiff line change
@@ -3627,14 +3627,19 @@ type PodExecOptions struct {
36273627
// Command is the remote command to execute; argv array; not executed within a shell.
36283628
Command []string
36293629

3630-
// Name is the name of the Debug Container. Its presence will cause
3631-
// exec to create a Debug Container rather than performing a runtime exec.
3632-
AlphaName string
3630+
// Run Command in an ephemeral container which shares some namespaces with Container.
3631+
AlphaEphemeralContainer PodExecEphemeralContainerSpec
3632+
}
3633+
3634+
type PodExecEphemeralContainerSpec struct {
3635+
// Name is the name of the Ephemeral Container. This must be specified to create
3636+
// an Ephemeral Container rather than performing a runtime exec.
3637+
Name string
36333638

36343639
// Image is an optional container image name that will be used to for the Debug
36353640
// Container in the specified Pod with Command as ENTRYPOINT. If omitted a
36363641
// default image will be used.
3637-
AlphaImage string
3642+
Image string
36383643
}
36393644

36403645
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
@@ -4137,7 +4142,6 @@ const (
41374142
// Command to run for remote command execution
41384143
ExecCommandParam = "command"
41394144
// Name of Debug Container when executing container image
4140-
// TODO(verb): will this conflict with target container name?
41414145
ExecDebugNameParam = "name"
41424146
// Container Image for Debug Container
41434147
ExecImageParam = "image"

pkg/registry/core/pod/strategy.go

+7-6
Original file line numberDiff line numberDiff line change
@@ -417,11 +417,11 @@ func streamParams(params url.Values, opts runtime.Object) error {
417417
for _, c := range opts.Command {
418418
params.Add("command", c)
419419
}
420-
if opts.AlphaName != "" {
421-
params.Add(api.ExecDebugNameParam, opts.AlphaName)
420+
if opts.AlphaEphemeralContainer.Name != "" {
421+
params.Add(api.ExecDebugNameParam, opts.AlphaEphemeralContainer.Name)
422422
}
423-
if opts.AlphaImage != "" {
424-
params.Add(api.ExecImageParam, opts.AlphaImage)
423+
if opts.AlphaEphemeralContainer.Image != "" {
424+
params.Add(api.ExecImageParam, opts.AlphaEphemeralContainer.Image)
425425
}
426426
case *api.PodAttachOptions:
427427
if opts.Stdin {
@@ -472,11 +472,12 @@ func ExecLocation(
472472
opts *api.PodExecOptions,
473473
) (*url.URL, http.RoundTripper, error) {
474474
kubeletPath := "exec"
475-
if opts.AlphaName != "" || opts.AlphaImage != "" {
475+
// BROKEN: opts.AlphaEphemeralContainer has not been populated from HTTP params
476+
if opts.AlphaEphemeralContainer.Name != "" || opts.AlphaEphemeralContainer.Image != "" {
476477
if !utilfeature.DefaultFeatureGate.Enabled(features.DebugContainers) {
477478
return nil, nil, errors.NewBadRequest("debug containers feature disabled")
478479
}
479-
if opts.AlphaName == "" {
480+
if opts.AlphaEphemeralContainer.Name == "" {
480481
// TODO(verb): consider allowing either and defaulting/generating the other
481482
return nil, nil, errors.NewBadRequest("Name required when Image specified")
482483
}

staging/src/k8s.io/api/core/v1/types.go

+9-4
Original file line numberDiff line numberDiff line change
@@ -4108,14 +4108,19 @@ type PodExecOptions struct {
41084108
// Command is the remote command to execute. argv array. Not executed within a shell.
41094109
Command []string `json:"command" protobuf:"bytes,6,rep,name=command"`
41104110

4111-
// Name is the name of the Debug Container. Its presence will cause
4112-
// exec to create a Debug Container rather than performing a runtime exec.
4113-
AlphaName string `json:"name" protobuf:"bytes,7,opt,name=name"`
4111+
// Run Command in an ephemeral container which shares some namespaces with Container.
4112+
AlphaEphemeralContainer PodExecEphemeralContainerSpec `json:"PodExecEphemeralContainerSpec,omitempty" protobuf:"bytes,7,opt,name=alphaEphemeralContainer"`
4113+
}
4114+
4115+
type PodExecEphemeralContainerSpec struct {
4116+
// Name is the name of the Ephemeral Container. This must be specified to create
4117+
// an Ephemeral Container rather than performing a runtime exec.
4118+
Name string `json:"name" protobuf:"bytes,1,opt,name=name"`
41144119

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

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

0 commit comments

Comments
 (0)