@@ -13,11 +13,13 @@ import (
1313 "k8s.io/kubernetes/pkg/kubectl/cmd/templates"
1414 kcmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
1515 "k8s.io/kubernetes/pkg/kubectl/genericclioptions"
16+ "k8s.io/kubernetes/pkg/kubectl/genericclioptions/resource"
1617
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"
1721 appsapi "github.com/openshift/origin/pkg/apps/apis/apps"
1822 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"
2123 buildutil "github.com/openshift/origin/pkg/build/util"
2224 "github.com/openshift/origin/pkg/oc/util/ocscheme"
2325)
@@ -66,11 +68,15 @@ type LogsOptions struct {
6668 KubeLogOptions * kcmd.LogsOptions
6769 // Client enables access to the Build object when processing
6870 // build logs for Jenkins Pipeline Strategy builds
69- Client buildclient. BuildsGetter
71+ Client buildclientv1. BuildV1Interface
7072 // Namespace is a required parameter when accessing the Build object when processing
7173 // build logs for Jenkins Pipeline Strategy builds
7274 Namespace string
73- Version int64
75+
76+ Builder func () * resource.Builder
77+ Resources []string
78+
79+ Version int64
7480
7581 genericclioptions.IOStreams
7682}
@@ -103,9 +109,9 @@ func NewCmdLogs(name, baseName string, f kcmdutil.Factory, streams genericcliopt
103109 return cmd
104110}
105111
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 )
109115 isPipeline := false
110116 switch {
111117 case isBC :
@@ -133,17 +139,49 @@ func (o *LogsOptions) Complete(f kcmdutil.Factory, cmd *cobra.Command, args []st
133139 if err != nil {
134140 return err
135141 }
136- client , err := buildclientinternal .NewForConfig (clientConfig )
142+ o . Client , err = buildclientv1 .NewForConfig (clientConfig )
137143 if err != nil {
138144 return err
139145 }
140- o .Client = client .Build ()
141146
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 {
142180 podLogOptions := o .KubeLogOptions .Options .(* kapi.PodLogOptions )
143- infos , err := f . NewBuilder ().
181+ infos , err := o . Builder ().
144182 WithScheme (ocscheme .ReadingInternalScheme , ocscheme .ReadingInternalScheme .PrioritizedVersionsAllGroups ()... ).
145183 NamespaceParam (o .Namespace ).DefaultNamespace ().
146- ResourceNames ("pods" , args ... ).
184+ ResourceNames ("pods" , o . Resources ... ).
147185 SingleResourceType ().RequireObject (false ).
148186 Do ().Infos ()
149187 if err != nil {
@@ -155,8 +193,8 @@ func (o *LogsOptions) Complete(f kcmdutil.Factory, cmd *cobra.Command, args []st
155193
156194 // TODO: podLogOptions should be included in our own logOptions objects.
157195 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" ):
160198 bopts := & buildapi.BuildLogOptions {
161199 Follow : podLogOptions .Follow ,
162200 Previous : podLogOptions .Previous ,
@@ -171,8 +209,9 @@ func (o *LogsOptions) Complete(f kcmdutil.Factory, cmd *cobra.Command, args []st
171209 }
172210 o .Options = bopts
173211
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
176215 dopts := & appsapi.DeploymentLogOptions {
177216 Container : podLogOptions .Container ,
178217 Follow : podLogOptions .Follow ,
@@ -191,36 +230,10 @@ func (o *LogsOptions) Complete(f kcmdutil.Factory, cmd *cobra.Command, args []st
191230 o .Options = nil
192231 }
193232
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 ()
219234}
220235
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 {
224237 if o .Options != nil {
225238 // Use our own options object.
226239 o .KubeLogOptions .Options = o .Options
0 commit comments