@@ -13,11 +13,13 @@ import (
13
13
"k8s.io/kubernetes/pkg/kubectl/cmd/templates"
14
14
kcmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
15
15
"k8s.io/kubernetes/pkg/kubectl/genericclioptions"
16
+ "k8s.io/kubernetes/pkg/kubectl/genericclioptions/resource"
16
17
18
+ appsapiv1 "github.com/openshift/api/apps/v1"
19
+ buildapiv1 "github.com/openshift/api/build/v1"
20
+ buildclientv1 "github.com/openshift/client-go/build/clientset/versioned/typed/build/v1"
17
21
appsapi "github.com/openshift/origin/pkg/apps/apis/apps"
18
22
buildapi "github.com/openshift/origin/pkg/build/apis/build"
19
- buildclientinternal "github.com/openshift/origin/pkg/build/generated/internalclientset"
20
- buildclient "github.com/openshift/origin/pkg/build/generated/internalclientset/typed/build/internalversion"
21
23
buildutil "github.com/openshift/origin/pkg/build/util"
22
24
"github.com/openshift/origin/pkg/oc/util/ocscheme"
23
25
)
@@ -66,11 +68,15 @@ type LogsOptions struct {
66
68
KubeLogOptions * kcmd.LogsOptions
67
69
// Client enables access to the Build object when processing
68
70
// build logs for Jenkins Pipeline Strategy builds
69
- Client buildclient. BuildsGetter
71
+ Client buildclientv1. BuildV1Interface
70
72
// Namespace is a required parameter when accessing the Build object when processing
71
73
// build logs for Jenkins Pipeline Strategy builds
72
74
Namespace string
73
- Version int64
75
+
76
+ Builder func () * resource.Builder
77
+ Resources []string
78
+
79
+ Version int64
74
80
75
81
genericclioptions.IOStreams
76
82
}
@@ -103,9 +109,9 @@ func NewCmdLogs(name, baseName string, f kcmdutil.Factory, streams genericcliopt
103
109
return cmd
104
110
}
105
111
106
- func isPipelineBuild (obj runtime.Object ) (bool , * buildapi .BuildConfig , bool , * buildapi .Build , bool ) {
107
- bc , isBC := obj .(* buildapi .BuildConfig )
108
- build , isBld := obj .(* buildapi .Build )
112
+ func isPipelineBuild (obj runtime.Object ) (bool , * buildapiv1 .BuildConfig , bool , * buildapiv1 .Build , bool ) {
113
+ bc , isBC := obj .(* buildapiv1 .BuildConfig )
114
+ build , isBld := obj .(* buildapiv1 .Build )
109
115
isPipeline := false
110
116
switch {
111
117
case isBC :
@@ -133,17 +139,49 @@ func (o *LogsOptions) Complete(f kcmdutil.Factory, cmd *cobra.Command, args []st
133
139
if err != nil {
134
140
return err
135
141
}
136
- client , err := buildclientinternal .NewForConfig (clientConfig )
142
+ o . Client , err = buildclientv1 .NewForConfig (clientConfig )
137
143
if err != nil {
138
144
return err
139
145
}
140
- o .Client = client .Build ()
141
146
147
+ o .Builder = f .NewBuilder
148
+ o .Resources = args
149
+
150
+ return nil
151
+ }
152
+
153
+ // Validate runs the upstream validation for the logs command and then it
154
+ // will validate any OpenShift-specific log options.
155
+ func (o * LogsOptions ) Validate () error {
156
+ if err := o .KubeLogOptions .Validate (); err != nil {
157
+ return err
158
+ }
159
+ if o .Options == nil {
160
+ return nil
161
+ }
162
+ switch t := o .Options .(type ) {
163
+ case * buildapiv1.BuildLogOptions :
164
+ if t .Previous && t .Version != nil {
165
+ return errors .New ("cannot use both --previous and --version" )
166
+ }
167
+ case * appsapiv1.DeploymentLogOptions :
168
+ if t .Previous && t .Version != nil {
169
+ return errors .New ("cannot use both --previous and --version" )
170
+ }
171
+ default :
172
+ return errors .New ("invalid log options object provided" )
173
+ }
174
+ return nil
175
+ }
176
+
177
+ // RunLog will run the upstream logs command and may use an OpenShift
178
+ // logOptions object.
179
+ func (o * LogsOptions ) RunLog () error {
142
180
podLogOptions := o .KubeLogOptions .Options .(* kapi.PodLogOptions )
143
- infos , err := f . NewBuilder ().
181
+ infos , err := o . Builder ().
144
182
WithScheme (ocscheme .ReadingInternalScheme , ocscheme .ReadingInternalScheme .PrioritizedVersionsAllGroups ()... ).
145
183
NamespaceParam (o .Namespace ).DefaultNamespace ().
146
- ResourceNames ("pods" , args ... ).
184
+ ResourceNames ("pods" , o . Resources ... ).
147
185
SingleResourceType ().RequireObject (false ).
148
186
Do ().Infos ()
149
187
if err != nil {
@@ -155,8 +193,8 @@ func (o *LogsOptions) Complete(f kcmdutil.Factory, cmd *cobra.Command, args []st
155
193
156
194
// TODO: podLogOptions should be included in our own logOptions objects.
157
195
switch gr := infos [0 ].Mapping .Resource .GroupResource (); gr {
158
- case buildapi .Resource ("builds" ),
159
- buildapi .Resource ("buildconfigs" ):
196
+ case buildapiv1 .Resource ("builds" ),
197
+ buildapiv1 .Resource ("buildconfigs" ):
160
198
bopts := & buildapi.BuildLogOptions {
161
199
Follow : podLogOptions .Follow ,
162
200
Previous : podLogOptions .Previous ,
@@ -171,8 +209,9 @@ func (o *LogsOptions) Complete(f kcmdutil.Factory, cmd *cobra.Command, args []st
171
209
}
172
210
o .Options = bopts
173
211
174
- case appsapi .Resource ("deploymentconfig" ),
175
- appsapi .Resource ("deploymentconfigs" ):
212
+ case appsapiv1 .Resource ("deploymentconfig" ),
213
+ appsapiv1 .Resource ("deploymentconfigs" ):
214
+ // TODO: switch to using appsapiv1.DeploymentLogOptions once originpolymorphichelpers.LogsForObjectFn supports appsv1
176
215
dopts := & appsapi.DeploymentLogOptions {
177
216
Container : podLogOptions .Container ,
178
217
Follow : podLogOptions .Follow ,
@@ -191,36 +230,10 @@ func (o *LogsOptions) Complete(f kcmdutil.Factory, cmd *cobra.Command, args []st
191
230
o .Options = nil
192
231
}
193
232
194
- return nil
195
- }
196
-
197
- // Validate runs the upstream validation for the logs command and then it
198
- // will validate any OpenShift-specific log options.
199
- func (o * LogsOptions ) Validate () error {
200
- if err := o .KubeLogOptions .Validate (); err != nil {
201
- return err
202
- }
203
- if o .Options == nil {
204
- return nil
205
- }
206
- switch t := o .Options .(type ) {
207
- case * buildapi.BuildLogOptions :
208
- if t .Previous && t .Version != nil {
209
- return errors .New ("cannot use both --previous and --version" )
210
- }
211
- case * appsapi.DeploymentLogOptions :
212
- if t .Previous && t .Version != nil {
213
- return errors .New ("cannot use both --previous and --version" )
214
- }
215
- default :
216
- return errors .New ("invalid log options object provided" )
217
- }
218
- return nil
233
+ return o .runLogPipeline ()
219
234
}
220
235
221
- // RunLog will run the upstream logs command and may use an OpenShift
222
- // logOptions object.
223
- func (o * LogsOptions ) RunLog () error {
236
+ func (o * LogsOptions ) runLogPipeline () error {
224
237
if o .Options != nil {
225
238
// Use our own options object.
226
239
o .KubeLogOptions .Options = o .Options
0 commit comments