File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -31,7 +31,12 @@ func (cb *CommandBuilder) launch() error {
3131 return errors .Wrap (err , "Failed to get info about target pod" )
3232 }
3333
34- targetContainer , err := targetPod .FindContainerInfo (cb .CommonOptions .Container )
34+ targetContainerName := cb .CommonOptions .Container
35+ if targetContainerName == "" {
36+ targetContainerName = targetPod .Annotations ["kubectl.kubernetes.io/default-container" ]
37+ }
38+
39+ targetContainer , err := targetPod .FindContainerInfo (targetContainerName )
3540 if err != nil {
3641 return errors .Wrap (err , "Failed to get info about target container" )
3742 }
@@ -40,7 +45,7 @@ func (cb *CommandBuilder) launch() error {
4045 NewJobRunSpec (cb .args (targetContainer ), cb .CommonOptions .Image , targetPod ).
4146 WithContainerFSVolume (targetContainer )
4247
43- if targetPod .ContainsMountedTmp (cb . CommonOptions . Container ) {
48+ if targetPod .ContainsMountedTmp (targetContainerName ) {
4449 jobSpec .WithContainerMountsVolume (targetContainer )
4550 }
4651
Original file line number Diff line number Diff line change @@ -11,8 +11,8 @@ import (
1111
1212// ContainerInfo is information about container struct
1313type ContainerInfo struct {
14- Runtime string
1514 ID string
15+ Runtime string
1616}
1717
1818type containerConfig struct {
@@ -30,8 +30,8 @@ func NewContainerInfo(cs *core.ContainerStatus) *ContainerInfo {
3030 containerInfo := strings .Split (cs .ContainerID , "://" )
3131
3232 return & ContainerInfo {
33- Runtime : containerInfo [0 ],
3433 ID : containerInfo [1 ],
34+ Runtime : containerInfo [0 ],
3535 }
3636}
3737
Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ import (
1515)
1616
1717type PodInfo struct {
18+ Annotations map [string ]string
1819 Name string
1920 Node string
2021 containers []core.Container
@@ -24,6 +25,7 @@ type PodInfo struct {
2425// NewPodInfo returns PodInfo generated from core.Pod spec
2526func NewPodInfo (pod * core.Pod ) * PodInfo {
2627 return & PodInfo {
28+ Annotations : pod .Annotations ,
2729 Name : pod .Name ,
2830 Node : pod .Spec .NodeName ,
2931 containers : pod .Spec .Containers ,
Original file line number Diff line number Diff line change @@ -41,6 +41,11 @@ func Test_DumpSubcommand(t *testing.T) {
4141 },
4242 pod : multiContainerPod (),
4343 },
44+ {
45+ name : "MultiContainer pod with default-container annotation" ,
46+ args : []string {},
47+ pod : multiContainerPodWithDefaultContainer (),
48+ },
4449 {
4550 name : "MultiContainer pod with shared mount" ,
4651 args : []string {
Original file line number Diff line number Diff line change @@ -50,6 +50,11 @@ func Test_GCDumpSubcommand(t *testing.T) {
5050 },
5151 pod : multiContainerPod (),
5252 },
53+ {
54+ name : "MultiContainer pod with default-container annotation" ,
55+ args : []string {},
56+ pod : multiContainerPodWithDefaultContainer (),
57+ },
5358 {
5459 name : "MultiContainer pod with shared mount" ,
5560 args : []string {
Original file line number Diff line number Diff line change @@ -51,13 +51,18 @@ func Test_TraceSubcommand(t *testing.T) {
5151 pod : singleContainerPod (),
5252 },
5353 {
54- name : "Multicontainer pod" ,
54+ name : "MultiContainer pod" ,
5555 args : []string {
5656 "--container" ,
5757 targetContainerName ,
5858 },
5959 pod : multiContainerPod (),
6060 },
61+ {
62+ name : "MultiContainer pod with default-container annotation" ,
63+ args : []string {},
64+ pod : multiContainerPodWithDefaultContainer (),
65+ },
6166 {
6267 name : "MultiContainer pod with shared mount" ,
6368 args : []string {
Original file line number Diff line number Diff line change @@ -118,6 +118,28 @@ func multiContainerPod() *core.Pod {
118118 }
119119}
120120
121+ func multiContainerPodWithDefaultContainer () * core.Pod {
122+ objectMeta := generateRandomPodMeta ()
123+ objectMeta .Annotations = map [string ]string {
124+ "kubectl.kubernetes.io/default-container" : targetContainerName ,
125+ }
126+ return & core.Pod {
127+ ObjectMeta : objectMeta ,
128+ Spec : core.PodSpec {
129+ Containers : []core.Container {
130+ {
131+ Name : targetContainerName ,
132+ Image : sampleAppImage ,
133+ },
134+ {
135+ Name : "sidecar" ,
136+ Image : "gcr.io/google_containers/pause-amd64:3.1" ,
137+ },
138+ },
139+ },
140+ }
141+ }
142+
121143func multiContainerPodWithSharedMount () * core.Pod {
122144 return & core.Pod {
123145 ObjectMeta : generateRandomPodMeta (),
You can’t perform that action at this time.
0 commit comments