Skip to content

Commit 72feb01

Browse files
committed
review comments
1 parent 91256af commit 72feb01

File tree

2 files changed

+43
-43
lines changed

2 files changed

+43
-43
lines changed

pkg/cmd/cli/cmd/importimage.go

+41-41
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ func (o *ImportImageOptions) createImageImport() (*imageapi.ImageStream, *imagea
265265

266266
// the stream already exists
267267
if len(stream.Spec.DockerImageRepository) == 0 && len(stream.Spec.Tags) == 0 {
268-
return nil, nil, fmt.Errorf("image stream has not defined anything to import")
268+
return nil, nil, fmt.Errorf("image stream does not have valid docker images to be imported")
269269
}
270270

271271
if o.All {
@@ -285,45 +285,6 @@ func (o *ImportImageOptions) createImageImport() (*imageapi.ImageStream, *imagea
285285
return stream, isi, nil
286286
}
287287

288-
func (o *ImportImageOptions) newImageStream() (*imageapi.ImageStream, *imageapi.ImageStreamImport) {
289-
from := o.From
290-
tag := o.Tag
291-
if len(from) == 0 {
292-
from = o.Target
293-
}
294-
var stream *imageapi.ImageStream
295-
// create new ImageStream
296-
if o.All {
297-
stream = &imageapi.ImageStream{
298-
ObjectMeta: kapi.ObjectMeta{Name: o.Name},
299-
Spec: imageapi.ImageStreamSpec{DockerImageRepository: from},
300-
}
301-
} else {
302-
stream = &imageapi.ImageStream{
303-
ObjectMeta: kapi.ObjectMeta{Name: o.Name},
304-
Spec: imageapi.ImageStreamSpec{
305-
Tags: map[string]imageapi.TagReference{
306-
tag: {
307-
From: &kapi.ObjectReference{
308-
Kind: "DockerImage",
309-
Name: from,
310-
},
311-
},
312-
},
313-
},
314-
}
315-
}
316-
// and accompanying ImageStreamImport
317-
var isi *imageapi.ImageStreamImport
318-
if o.All {
319-
isi = o.newImageStreamImportAll(stream, from)
320-
} else {
321-
isi = o.newImageStreamImportTags(stream, map[string]string{tag: from})
322-
}
323-
324-
return stream, isi
325-
}
326-
327288
func (o *ImportImageOptions) importAll(stream *imageapi.ImageStream) (*imageapi.ImageStreamImport, error) {
328289
from := o.From
329290
// update ImageStream appropriately
@@ -338,7 +299,7 @@ func (o *ImportImageOptions) importAll(stream *imageapi.ImageStream) (*imageapi.
338299
}
339300
}
340301
if len(tags) == 0 {
341-
return nil, fmt.Errorf("image stream does not have importable tags (pointing to DockerImage)")
302+
return nil, fmt.Errorf("image stream does not have tags pointing to external docker images")
342303
}
343304
return o.newImageStreamImportTags(stream, tags), nil
344305
}
@@ -414,6 +375,45 @@ func (o *ImportImageOptions) importTag(stream *imageapi.ImageStream) (*imageapi.
414375
return o.newImageStreamImportTags(stream, map[string]string{tag: from}), nil
415376
}
416377

378+
func (o *ImportImageOptions) newImageStream() (*imageapi.ImageStream, *imageapi.ImageStreamImport) {
379+
from := o.From
380+
tag := o.Tag
381+
if len(from) == 0 {
382+
from = o.Target
383+
}
384+
var stream *imageapi.ImageStream
385+
// create new ImageStream
386+
if o.All {
387+
stream = &imageapi.ImageStream{
388+
ObjectMeta: kapi.ObjectMeta{Name: o.Name},
389+
Spec: imageapi.ImageStreamSpec{DockerImageRepository: from},
390+
}
391+
} else {
392+
stream = &imageapi.ImageStream{
393+
ObjectMeta: kapi.ObjectMeta{Name: o.Name},
394+
Spec: imageapi.ImageStreamSpec{
395+
Tags: map[string]imageapi.TagReference{
396+
tag: {
397+
From: &kapi.ObjectReference{
398+
Kind: "DockerImage",
399+
Name: from,
400+
},
401+
},
402+
},
403+
},
404+
}
405+
}
406+
// and accompanying ImageStreamImport
407+
var isi *imageapi.ImageStreamImport
408+
if o.All {
409+
isi = o.newImageStreamImportAll(stream, from)
410+
} else {
411+
isi = o.newImageStreamImportTags(stream, map[string]string{tag: from})
412+
}
413+
414+
return stream, isi
415+
}
416+
417417
func (o *ImportImageOptions) newImageStreamImport(stream *imageapi.ImageStream) (*imageapi.ImageStreamImport, bool) {
418418
isi := &imageapi.ImageStreamImport{
419419
ObjectMeta: kapi.ObjectMeta{

pkg/cmd/cli/cmd/importimage_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ func TestCreateImageImport(t *testing.T) {
182182
"import all from .spec.tags no DockerImage tags": {
183183
name: "testis",
184184
all: true,
185-
err: "does not have importable tags",
185+
err: "does not have tags pointing to external docker images",
186186
stream: &imageapi.ImageStream{
187187
ObjectMeta: kapi.ObjectMeta{Name: "testis", Namespace: "other"},
188188
Spec: imageapi.ImageStreamSpec{
@@ -194,7 +194,7 @@ func TestCreateImageImport(t *testing.T) {
194194
},
195195
"empty image stream": {
196196
name: "testis",
197-
err: "image stream has not defined anything to import",
197+
err: "does not have valid docker images",
198198
stream: &imageapi.ImageStream{
199199
ObjectMeta: kapi.ObjectMeta{Name: "testis", Namespace: "other"},
200200
},

0 commit comments

Comments
 (0)