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