Skip to content

Commit 60f9c87

Browse files
committed
switch logs to externals
1 parent 179c130 commit 60f9c87

File tree

2 files changed

+63
-50
lines changed

2 files changed

+63
-50
lines changed

pkg/oc/cli/logs/logs.go

Lines changed: 57 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@ 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

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"
1821
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"
2122
buildutil "github.com/openshift/origin/pkg/build/util"
2223
"github.com/openshift/origin/pkg/oc/util/ocscheme"
2324
)
@@ -66,11 +67,15 @@ type LogsOptions struct {
6667
KubeLogOptions *kcmd.LogsOptions
6768
// Client enables access to the Build object when processing
6869
// build logs for Jenkins Pipeline Strategy builds
69-
Client buildclient.BuildsGetter
70+
Client buildclientv1.BuildV1Interface
7071
// Namespace is a required parameter when accessing the Build object when processing
7172
// build logs for Jenkins Pipeline Strategy builds
7273
Namespace string
73-
Version int64
74+
75+
Builder func() *resource.Builder
76+
Resources []string
77+
78+
Version int64
7479

7580
genericclioptions.IOStreams
7681
}
@@ -103,9 +108,9 @@ func NewCmdLogs(name, baseName string, f kcmdutil.Factory, streams genericcliopt
103108
return cmd
104109
}
105110

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)
109114
isPipeline := false
110115
switch {
111116
case isBC:
@@ -133,17 +138,49 @@ func (o *LogsOptions) Complete(f kcmdutil.Factory, cmd *cobra.Command, args []st
133138
if err != nil {
134139
return err
135140
}
136-
client, err := buildclientinternal.NewForConfig(clientConfig)
141+
o.Client, err = buildclientv1.NewForConfig(clientConfig)
137142
if err != nil {
138143
return err
139144
}
140-
o.Client = client.Build()
141145

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 {
142179
podLogOptions := o.KubeLogOptions.Options.(*kapi.PodLogOptions)
143-
infos, err := f.NewBuilder().
180+
infos, err := o.Builder().
144181
WithScheme(ocscheme.ReadingInternalScheme, ocscheme.ReadingInternalScheme.PrioritizedVersionsAllGroups()...).
145182
NamespaceParam(o.Namespace).DefaultNamespace().
146-
ResourceNames("pods", args...).
183+
ResourceNames("pods", o.Resources...).
147184
SingleResourceType().RequireObject(false).
148185
Do().Infos()
149186
if err != nil {
@@ -155,9 +192,9 @@ func (o *LogsOptions) Complete(f kcmdutil.Factory, cmd *cobra.Command, args []st
155192

156193
// TODO: podLogOptions should be included in our own logOptions objects.
157194
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{
161198
Follow: podLogOptions.Follow,
162199
Previous: podLogOptions.Previous,
163200
SinceSeconds: podLogOptions.SinceSeconds,
@@ -171,9 +208,9 @@ func (o *LogsOptions) Complete(f kcmdutil.Factory, cmd *cobra.Command, args []st
171208
}
172209
o.Options = bopts
173210

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{
177214
Container: podLogOptions.Container,
178215
Follow: podLogOptions.Follow,
179216
Previous: podLogOptions.Previous,
@@ -191,36 +228,10 @@ func (o *LogsOptions) Complete(f kcmdutil.Factory, cmd *cobra.Command, args []st
191228
o.Options = nil
192229
}
193230

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()
219232
}
220233

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 {
224235
if o.Options != nil {
225236
// Use our own options object.
226237
o.KubeLogOptions.Options = o.Options

pkg/oc/cli/logs/logs_test.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ import (
1212
kcmd "k8s.io/kubernetes/pkg/kubectl/cmd"
1313
"k8s.io/kubernetes/pkg/kubectl/genericclioptions"
1414

15+
buildapi "github.com/openshift/api/build/v1"
16+
buildfake "github.com/openshift/client-go/build/clientset/versioned/fake"
1517
appsapi "github.com/openshift/origin/pkg/apps/apis/apps"
16-
buildapi "github.com/openshift/origin/pkg/build/apis/build"
17-
buildfake "github.com/openshift/origin/pkg/build/generated/internalclientset/fake"
18+
internalbuildapi "github.com/openshift/origin/pkg/build/apis/build"
1819
)
1920

2021
// TestLogsFlagParity makes sure that our copied flags don't slip during rebases
@@ -50,7 +51,7 @@ func TestRunLogForPipelineStrategy(t *testing.T) {
5051
ObjectMeta: metav1.ObjectMeta{
5152
Name: "foo-0",
5253
Namespace: "foo",
53-
Annotations: map[string]string{buildapi.BuildJenkinsBlueOceanLogURLAnnotation: "https://foo"},
54+
Annotations: map[string]string{internalbuildapi.BuildJenkinsBlueOceanLogURLAnnotation: "https://foo"},
5455
},
5556
Spec: buildapi.BuildSpec{
5657
CommonSpec: buildapi.CommonSpec{
@@ -91,12 +92,13 @@ func TestRunLogForPipelineStrategy(t *testing.T) {
9192
o := &LogsOptions{
9293
IOStreams: streams,
9394
KubeLogOptions: &kcmd.LogsOptions{
95+
IOStreams: streams,
9496
Object: tc.o,
9597
Namespace: "foo",
9698
},
9799
Client: fakebc.Build(),
98100
}
99-
if err := o.RunLog(); err != nil {
101+
if err := o.runLogPipeline(); err != nil {
100102
t.Errorf("%#v: RunLog error %v", tc.o, err)
101103
}
102104
if !strings.Contains(out.String(), "https://foo") {

0 commit comments

Comments
 (0)