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