@@ -26,7 +26,7 @@ import (
26
26
corev1client "k8s.io/client-go/kubernetes/typed/core/v1"
27
27
"k8s.io/kubernetes/pkg/api/legacyscheme"
28
28
kapi "k8s.io/kubernetes/pkg/apis/core"
29
- coreclient "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/typed/ core/internalversion "
29
+ kapiv1 "k8s.io/kubernetes/pkg/apis/ core/v1 "
30
30
"k8s.io/kubernetes/pkg/kubectl"
31
31
kcmd "k8s.io/kubernetes/pkg/kubectl/cmd"
32
32
"k8s.io/kubernetes/pkg/kubectl/cmd/templates"
@@ -38,63 +38,22 @@ import (
38
38
"k8s.io/kubernetes/pkg/kubectl/util/term"
39
39
"k8s.io/kubernetes/pkg/util/interrupt"
40
40
41
+ appsapiv1 "github.com/openshift/api/apps/v1"
41
42
appsv1 "github.com/openshift/api/apps/v1"
43
+ imageapiv1 "github.com/openshift/api/image/v1"
42
44
imagev1 "github.com/openshift/api/image/v1"
45
+ appsclientv1 "github.com/openshift/client-go/apps/clientset/versioned/typed/apps/v1"
46
+ imageclientv1 "github.com/openshift/client-go/image/clientset/versioned/typed/image/v1"
43
47
appsapi "github.com/openshift/origin/pkg/apps/apis/apps"
44
- appsclientinternal "github.com/openshift/origin/pkg/apps/generated/internalclientset"
45
- appsclient "github.com/openshift/origin/pkg/apps/generated/internalclientset/typed/apps/internalversion"
46
48
appsutil "github.com/openshift/origin/pkg/apps/util"
47
49
imageapi "github.com/openshift/origin/pkg/image/apis/image"
48
- imageclientinternal "github.com/openshift/origin/pkg/image/generated/internalclientset "
49
- imageclient "github.com/openshift/origin/pkg/image/generated/internalclientset/typed/ image/internalversion "
50
+ internalimage "github.com/openshift/origin/pkg/image/apis/image "
51
+ oapiv1 "github.com/openshift/origin/pkg/image/apis/ image/v1 "
50
52
generateapp "github.com/openshift/origin/pkg/oc/lib/newapp/app"
51
53
utilenv "github.com/openshift/origin/pkg/oc/util/env"
52
54
"github.com/openshift/origin/pkg/oc/util/ocscheme"
53
55
)
54
56
55
- type DebugOptions struct {
56
- PrintFlags * genericclioptions.PrintFlags
57
-
58
- Attach kcmd.AttachOptions
59
-
60
- CoreClient coreclient.CoreInterface
61
- CoreV1Client corev1client.CoreV1Interface
62
- AppsClient appsclient.AppsInterface
63
- ImageClient imageclient.ImageInterface
64
-
65
- Printer printers.ResourcePrinter
66
- LogsForObject polymorphichelpers.LogsForObjectFunc
67
-
68
- NoStdin bool
69
- ForceTTY bool
70
- DisableTTY bool
71
- Timeout time.Duration
72
-
73
- Command []string
74
- Annotations map [string ]string
75
- AsRoot bool
76
- AsNonRoot bool
77
- AsUser int64
78
- KeepLabels bool // TODO: evaluate selecting the right labels automatically
79
- KeepAnnotations bool
80
- KeepLiveness bool
81
- KeepReadiness bool
82
- KeepInitContainers bool
83
- OneContainer bool
84
- NodeName string
85
- AddEnv []kapi.EnvVar
86
- RemoveEnv []string
87
- Resources []string
88
- Builder func () * resource.Builder
89
- Namespace string
90
- ExplicitNamespace bool
91
- DryRun bool
92
- FullCmdName string
93
-
94
- resource.FilenameOptions
95
- genericclioptions.IOStreams
96
- }
97
-
98
57
const (
99
58
debugPodLabelName = "debug.openshift.io/name"
100
59
@@ -139,6 +98,48 @@ var (
139
98
%[1]s dc/test -o yaml` )
140
99
)
141
100
101
+ type DebugOptions struct {
102
+ PrintFlags * genericclioptions.PrintFlags
103
+
104
+ Attach kcmd.AttachOptions
105
+
106
+ CoreClient corev1client.CoreV1Interface
107
+ AppsClient appsclientv1.AppsV1Interface
108
+ ImageClient imageclientv1.ImageV1Interface
109
+
110
+ Printer printers.ResourcePrinter
111
+ LogsForObject polymorphichelpers.LogsForObjectFunc
112
+
113
+ NoStdin bool
114
+ ForceTTY bool
115
+ DisableTTY bool
116
+ Timeout time.Duration
117
+
118
+ Command []string
119
+ Annotations map [string ]string
120
+ AsRoot bool
121
+ AsNonRoot bool
122
+ AsUser int64
123
+ KeepLabels bool // TODO: evaluate selecting the right labels automatically
124
+ KeepAnnotations bool
125
+ KeepLiveness bool
126
+ KeepReadiness bool
127
+ KeepInitContainers bool
128
+ OneContainer bool
129
+ NodeName string
130
+ AddEnv []corev1.EnvVar
131
+ RemoveEnv []string
132
+ Resources []string
133
+ Builder func () * resource.Builder
134
+ Namespace string
135
+ ExplicitNamespace bool
136
+ DryRun bool
137
+ FullCmdName string
138
+
139
+ resource.FilenameOptions
140
+ genericclioptions.IOStreams
141
+ }
142
+
142
143
func NewDebugOptions (streams genericclioptions.IOStreams ) * DebugOptions {
143
144
return & DebugOptions {
144
145
PrintFlags : genericclioptions .NewPrintFlags ("" ).WithTypeSetter (ocscheme .PrintingInternalScheme ),
@@ -256,11 +257,24 @@ func (o *DebugOptions) Complete(cmd *cobra.Command, f kcmdutil.Factory, args []s
256
257
257
258
o .Builder = f .NewBuilder
258
259
259
- o .AddEnv , o .RemoveEnv , err = utilenv .ParseEnv (envArgs , nil )
260
+ // TODO: not sure what to do with this helper - new duplicate for external versions?
261
+ internalAddEnv , removeEnv , err := utilenv .ParseEnv (envArgs , nil )
260
262
if err != nil {
261
263
return err
262
264
}
263
265
266
+ // convert EnvVars that we should add, from internal to external
267
+ for _ , internal := range internalAddEnv {
268
+ external := corev1.EnvVar {}
269
+ if err := kapiv1 .Convert_core_EnvVar_To_v1_EnvVar (& internal , & external , nil ); err != nil {
270
+ return err
271
+ }
272
+
273
+ o .AddEnv = append (o .AddEnv , external )
274
+ }
275
+
276
+ o .RemoveEnv = removeEnv
277
+
264
278
cmdParent := cmd .Parent ()
265
279
if cmdParent != nil && len (cmdParent .CommandPath ()) > 0 && kcmdutil .IsSiblingCommandExists (cmd , "describe" ) {
266
280
o .FullCmdName = cmdParent .CommandPath ()
@@ -290,29 +304,22 @@ func (o *DebugOptions) Complete(cmd *cobra.Command, f kcmdutil.Factory, args []s
290
304
}
291
305
o .Attach .Config = config
292
306
293
- kc , err := f . ClientSet ( )
307
+ o . CoreClient , err = corev1client . NewForConfig ( config )
294
308
if err != nil {
295
309
return err
296
310
}
297
- o .Attach .PodClient = kc .Core ()
298
- o .CoreClient = kc .Core ()
299
311
300
- o .CoreV1Client , err = corev1client .NewForConfig (config )
301
- if err != nil {
302
- return err
303
- }
312
+ o .Attach .PodClient = o .CoreClient
304
313
305
- appsClient , err := appsclientinternal .NewForConfig (config )
314
+ o . AppsClient , err = appsclientv1 .NewForConfig (config )
306
315
if err != nil {
307
316
return err
308
317
}
309
- o .AppsClient = appsClient .Apps ()
310
318
311
- imageClient , err := imageclientinternal .NewForConfig (config )
319
+ o . ImageClient , err = imageclientv1 .NewForConfig (config )
312
320
if err != nil {
313
321
return err
314
322
}
315
- o .ImageClient = imageClient .Image ()
316
323
317
324
return nil
318
325
}
@@ -351,11 +358,11 @@ func (o *DebugOptions) RunDebug() error {
351
358
if err != nil {
352
359
glog .V (4 ).Infof ("Unable to get exact template, but continuing with fallback: %v" , err )
353
360
}
354
- template := & kapi .PodTemplateSpec {}
361
+ template := & corev1 .PodTemplateSpec {}
355
362
if err := legacyscheme .Scheme .Convert (templateV1 , template , nil ); err != nil {
356
363
return err
357
364
}
358
- pod := & kapi .Pod {
365
+ pod := & corev1 .Pod {
359
366
ObjectMeta : template .ObjectMeta ,
360
367
Spec : template .Spec ,
361
368
}
@@ -471,7 +478,7 @@ func (o *DebugOptions) RunDebug() error {
471
478
// (via the "openshift.io/deployment-config.name" annotation), then tries to
472
479
// find the ImageStream from which the DeploymentConfig is deploying, then tries
473
480
// to find a match for the Container's image in the ImageStream's Images.
474
- func (o * DebugOptions ) getContainerImageViaDeploymentConfig (pod * kapi .Pod , container * kapi .Container ) (* imageapi .Image , error ) {
481
+ func (o * DebugOptions ) getContainerImageViaDeploymentConfig (pod * corev1 .Pod , container * corev1 .Container ) (* imageapiv1 .Image , error ) {
475
482
ref , err := imageapi .ParseDockerImageReference (container .Image )
476
483
if err != nil {
477
484
return nil , err
@@ -492,7 +499,7 @@ func (o *DebugOptions) getContainerImageViaDeploymentConfig(pod *kapi.Pod, conta
492
499
}
493
500
494
501
for _ , trigger := range dc .Spec .Triggers {
495
- if trigger .Type == appsapi .DeploymentTriggerOnImageChange &&
502
+ if trigger .Type == appsapiv1 .DeploymentTriggerOnImageChange &&
496
503
trigger .ImageChangeParams != nil &&
497
504
trigger .ImageChangeParams .From .Kind == "ImageStreamTag" {
498
505
@@ -523,15 +530,15 @@ func (o *DebugOptions) getContainerImageViaDeploymentConfig(pod *kapi.Pod, conta
523
530
// set to false. The request will not succeed if the backing repository
524
531
// requires Insecure to be set to true, which cannot be hard-coded for security
525
532
// reasons.
526
- func (o * DebugOptions ) getContainerImageViaImageStreamImport (container * kapi .Container ) (* imageapi .Image , error ) {
527
- isi := & imageapi .ImageStreamImport {
533
+ func (o * DebugOptions ) getContainerImageViaImageStreamImport (container * corev1 .Container ) (* imageapiv1 .Image , error ) {
534
+ isi := & imageapiv1 .ImageStreamImport {
528
535
ObjectMeta : metav1.ObjectMeta {
529
536
Name : "oc-debug" ,
530
537
},
531
- Spec : imageapi .ImageStreamImportSpec {
532
- Images : []imageapi .ImageImportSpec {
538
+ Spec : imageapiv1 .ImageStreamImportSpec {
539
+ Images : []imageapiv1 .ImageImportSpec {
533
540
{
534
- From : kapi .ObjectReference {
541
+ From : corev1 .ObjectReference {
535
542
Kind : "DockerImage" ,
536
543
Name : container .Image ,
537
544
},
@@ -552,7 +559,7 @@ func (o *DebugOptions) getContainerImageViaImageStreamImport(container *kapi.Con
552
559
return nil , nil
553
560
}
554
561
555
- func (o * DebugOptions ) getContainerImageCommand (pod * kapi .Pod , container * kapi .Container ) ([]string , error ) {
562
+ func (o * DebugOptions ) getContainerImageCommand (pod * corev1 .Pod , container * corev1 .Container ) ([]string , error ) {
556
563
if len (container .Command ) > 0 {
557
564
return container .Command , nil
558
565
}
@@ -562,16 +569,24 @@ func (o *DebugOptions) getContainerImageCommand(pod *kapi.Pod, container *kapi.C
562
569
image , _ = o .getContainerImageViaImageStreamImport (container )
563
570
}
564
571
565
- if image == nil || image .DockerImageMetadata .Config == nil {
572
+ // TODO: find a way to do this with the external api
573
+ // convert image to internal in order to extract its imagemetadata config
574
+ internalImage := & internalimage.Image {}
575
+ if err := oapiv1 .Convert_v1_Image_To_image_Image (image , internalImage , nil ); err != nil {
576
+ return nil , err
577
+ }
578
+
579
+ // TODO: DockerImageMetadata is a RawExtension in the external api - how to access config?
580
+ if internalImage == nil || internalImage .DockerImageMetadata .Config == nil {
566
581
return nil , errors .New ("error: no usable image found" )
567
582
}
568
583
569
- config := image .DockerImageMetadata .Config
584
+ config := internalImage .DockerImageMetadata .Config
570
585
return append (config .Entrypoint , config .Cmd ... ), nil
571
586
}
572
587
573
588
// transformPodForDebug alters the input pod to be debuggable
574
- func (o * DebugOptions ) transformPodForDebug (annotations map [string ]string ) (* kapi .Pod , []string ) {
589
+ func (o * DebugOptions ) transformPodForDebug (annotations map [string ]string ) (* corev1 .Pod , []string ) {
575
590
pod := o .Attach .Pod
576
591
577
592
if ! o .KeepInitContainers {
@@ -600,7 +615,7 @@ func (o *DebugOptions) transformPodForDebug(annotations map[string]string) (*kap
600
615
container .LivenessProbe = nil
601
616
}
602
617
603
- var newEnv []kapi .EnvVar
618
+ var newEnv []corev1 .EnvVar
604
619
if len (o .RemoveEnv ) > 0 {
605
620
for i := range container .Env {
606
621
skip := false
@@ -624,7 +639,7 @@ func (o *DebugOptions) transformPodForDebug(annotations map[string]string) (*kap
624
639
container .Env = newEnv
625
640
626
641
if container .SecurityContext == nil {
627
- container .SecurityContext = & kapi .SecurityContext {}
642
+ container .SecurityContext = & corev1 .SecurityContext {}
628
643
}
629
644
switch {
630
645
case o .AsNonRoot :
@@ -640,7 +655,7 @@ func (o *DebugOptions) transformPodForDebug(annotations map[string]string) (*kap
640
655
}
641
656
642
657
if o .OneContainer {
643
- pod .Spec .Containers = []kapi .Container {* container }
658
+ pod .Spec .Containers = []corev1 .Container {* container }
644
659
}
645
660
646
661
// reset the pod
@@ -661,9 +676,9 @@ func (o *DebugOptions) transformPodForDebug(annotations map[string]string) (*kap
661
676
pod .Spec .NodeName = o .NodeName
662
677
663
678
pod .ResourceVersion = ""
664
- pod .Spec .RestartPolicy = kapi .RestartPolicyNever
679
+ pod .Spec .RestartPolicy = corev1 .RestartPolicyNever
665
680
666
- pod .Status = kapi .PodStatus {}
681
+ pod .Status = corev1 .PodStatus {}
667
682
pod .UID = ""
668
683
pod .CreationTimestamp = metav1.Time {}
669
684
pod .SelfLink = ""
@@ -676,7 +691,7 @@ func (o *DebugOptions) transformPodForDebug(annotations map[string]string) (*kap
676
691
677
692
// createPod creates the debug pod, and will attempt to delete an existing debug
678
693
// pod with the same name, but will return an error in any other case.
679
- func (o * DebugOptions ) createPod (pod * kapi .Pod ) (* kapi .Pod , error ) {
694
+ func (o * DebugOptions ) createPod (pod * corev1 .Pod ) (* corev1 .Pod , error ) {
680
695
namespace , name := pod .Namespace , pod .Name
681
696
682
697
// create the pod
@@ -701,7 +716,7 @@ func (o *DebugOptions) createPod(pod *kapi.Pod) (*kapi.Pod, error) {
701
716
return o .Attach .PodClient .Pods (namespace ).Create (pod )
702
717
}
703
718
704
- func containerForName (pod * kapi .Pod , name string ) * kapi .Container {
719
+ func containerForName (pod * corev1 .Pod , name string ) * corev1 .Container {
705
720
for i , c := range pod .Spec .Containers {
706
721
if c .Name == name {
707
722
return & pod .Spec .Containers [i ]
@@ -715,7 +730,7 @@ func containerForName(pod *kapi.Pod, name string) *kapi.Container {
715
730
return nil
716
731
}
717
732
718
- func containerNames (pod * kapi .Pod ) []string {
733
+ func containerNames (pod * corev1 .Pod ) []string {
719
734
var names []string
720
735
for _ , c := range pod .Spec .Containers {
721
736
names = append (names , c .Name )
@@ -751,14 +766,14 @@ func (o *DebugOptions) approximatePodTemplateForObject(object runtime.Object) (*
751
766
fallback := t .Spec .Template
752
767
753
768
latestDeploymentName := appsutil .LatestDeploymentNameForConfigV1 (t )
754
- deployment , err := o .CoreV1Client .ReplicationControllers (t .Namespace ).Get (latestDeploymentName , metav1.GetOptions {})
769
+ deployment , err := o .CoreClient .ReplicationControllers (t .Namespace ).Get (latestDeploymentName , metav1.GetOptions {})
755
770
if err != nil {
756
771
return fallback , err
757
772
}
758
773
759
774
fallback = deployment .Spec .Template
760
775
761
- pods , err := o .CoreV1Client .Pods (deployment .Namespace ).List (metav1.ListOptions {LabelSelector : labels .SelectorFromSet (deployment .Spec .Selector ).String ()})
776
+ pods , err := o .CoreClient .Pods (deployment .Namespace ).List (metav1.ListOptions {LabelSelector : labels .SelectorFromSet (deployment .Spec .Selector ).String ()})
762
777
if err != nil {
763
778
return fallback , err
764
779
}
0 commit comments