@@ -4,19 +4,15 @@ import (
4
4
"fmt"
5
5
"io"
6
6
"strings"
7
- "time"
8
7
9
8
"github.com/spf13/cobra"
10
9
11
10
"k8s.io/apimachinery/pkg/api/errors"
12
11
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
13
- "k8s.io/apimachinery/pkg/fields"
14
- "k8s.io/apimachinery/pkg/watch"
15
12
"k8s.io/kubernetes/pkg/api/legacyscheme"
16
13
kapi "k8s.io/kubernetes/pkg/apis/core"
17
14
"k8s.io/kubernetes/pkg/kubectl/cmd/templates"
18
15
kcmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
19
- kprinters "k8s.io/kubernetes/pkg/printers"
20
16
21
17
imageapiv1 "github.com/openshift/api/image/v1"
22
18
imageapi "github.com/openshift/origin/pkg/image/apis/image"
@@ -170,53 +166,36 @@ func (o *ImportImageOptions) Run() error {
170
166
return err
171
167
}
172
168
173
- // Attempt the new, direct import path
174
169
result , err := o .imageClient .ImageStreamImports (isi .Namespace ).Create (isi )
175
- err = TransformUnsupportedError (err )
176
- switch {
177
- case err == imageapi .ErrImageStreamImportUnsupported :
178
- case err != nil :
170
+ if err != nil {
179
171
return err
180
- default :
181
- if o .DryRun {
182
- if wasError (result ) {
183
- fmt .Fprintf (o .errout , "The dry-run import completed with errors.\n \n " )
184
- } else {
185
- fmt .Fprint (o .out , "The dry-run import completed successfully.\n \n " )
186
- }
172
+ }
173
+
174
+ if o .DryRun {
175
+ if wasError (result ) {
176
+ fmt .Fprintf (o .errout , "The dry-run import completed with errors.\n \n " )
187
177
} else {
188
- if wasError (result ) {
189
- fmt .Fprintf (o .errout , "The import completed with errors.\n \n " )
190
- } else {
191
- fmt .Fprint (o .out , "The import completed successfully.\n \n " )
192
- }
178
+ fmt .Fprint (o .out , "The dry-run import completed successfully.\n \n " )
193
179
}
194
-
195
- if result .Status .Import != nil {
196
- // TODO: dry-run doesn't return an image stream, so we have to display partial results
197
- info , err := describe .DescribeImageStream (result .Status .Import )
198
- if err != nil {
199
- return err
200
- }
201
- fmt .Fprintln (o .out , info )
180
+ } else {
181
+ if wasError (result ) {
182
+ fmt .Fprintf (o .errout , "The import completed with errors.\n \n " )
183
+ } else {
184
+ fmt .Fprint (o .out , "The import completed successfully.\n \n " )
202
185
}
186
+ }
203
187
204
- if repo := result .Status .Repository ; repo != nil {
205
- for _ , image := range repo .Images {
206
- if image .Image != nil {
207
- info , err := describe .DescribeImage (image .Image , imageapi .JoinImageStreamTag (stream .Name , image .Tag ))
208
- if err != nil {
209
- fmt .Fprintf (o .errout , "error: tag %s failed: %v\n " , image .Tag , err )
210
- } else {
211
- fmt .Fprintln (o .out , info )
212
- }
213
- } else {
214
- fmt .Fprintf (o .errout , "error: repository tag %s failed: %v\n " , image .Tag , image .Status .Message )
215
- }
216
- }
188
+ if result .Status .Import != nil {
189
+ // TODO: dry-run doesn't return an image stream, so we have to display partial results
190
+ info , err := describe .DescribeImageStream (result .Status .Import )
191
+ if err != nil {
192
+ return err
217
193
}
194
+ fmt .Fprintln (o .out , info )
195
+ }
218
196
219
- for _ , image := range result .Status .Images {
197
+ if repo := result .Status .Repository ; repo != nil {
198
+ for _ , image := range repo .Images {
220
199
if image .Image != nil {
221
200
info , err := describe .DescribeImage (image .Image , imageapi .JoinImageStreamTag (stream .Name , image .Tag ))
222
201
if err != nil {
@@ -225,54 +204,27 @@ func (o *ImportImageOptions) Run() error {
225
204
fmt .Fprintln (o .out , info )
226
205
}
227
206
} else {
228
- fmt .Fprintf (o .errout , "error: tag %s failed: %v\n " , image .Tag , image .Status .Message )
207
+ fmt .Fprintf (o .errout , "error: repository tag %s failed: %v\n " , image .Tag , image .Status .Message )
229
208
}
230
209
}
231
-
232
- if r := result .Status .Repository ; r != nil && len (r .AdditionalTags ) > 0 {
233
- fmt .Fprintf (o .out , "\n info: The remote repository contained %d additional tags which were not imported: %s\n " , len (r .AdditionalTags ), strings .Join (r .AdditionalTags , ", " ))
234
- }
235
- return nil
236
- }
237
-
238
- // Legacy path, remove when support for older importers is removed
239
- delete (stream .Annotations , imageapi .DockerImageRepositoryCheckAnnotation )
240
- if o .Insecure != nil && * o .Insecure {
241
- if stream .Annotations == nil {
242
- stream .Annotations = make (map [string ]string )
243
- }
244
- stream .Annotations [imageapi .InsecureRepositoryAnnotation ] = "true"
245
- }
246
-
247
- if stream .CreationTimestamp .IsZero () {
248
- stream , err = o .isClient .Create (stream )
249
- } else {
250
- stream , err = o .isClient .Update (stream )
251
210
}
252
- if err != nil {
253
- return err
254
- }
255
-
256
- fmt .Fprintln (o .out , "Importing (ctrl+c to stop waiting) ..." )
257
211
258
- resourceVersion := stream .ResourceVersion
259
- updatedStream , err := o .waitForImport (resourceVersion )
260
- if err != nil {
261
- if _ , ok := err .(importError ); ok {
262
- return err
212
+ for _ , image := range result .Status .Images {
213
+ if image .Image != nil {
214
+ info , err := describe .DescribeImage (image .Image , imageapi .JoinImageStreamTag (stream .Name , image .Tag ))
215
+ if err != nil {
216
+ fmt .Fprintf (o .errout , "error: tag %s failed: %v\n " , image .Tag , err )
217
+ } else {
218
+ fmt .Fprintln (o .out , info )
219
+ }
220
+ } else {
221
+ fmt .Fprintf (o .errout , "error: tag %s failed: %v\n " , image .Tag , image .Status .Message )
263
222
}
264
- return fmt .Errorf ("unable to determine if the import completed successfully - please run '%s describe -n %s imagestream/%s' to see if the tags were updated as expected: %v" , o .CommandName , stream .Namespace , stream .Name , err )
265
223
}
266
224
267
- fmt .Fprint (o .out , "The import completed successfully.\n \n " )
268
-
269
- d := describe.ImageStreamDescriber {ImageClient : o .imageClient }
270
- info , err := d .Describe (updatedStream .Namespace , updatedStream .Name , kprinters.DescriberSettings {})
271
- if err != nil {
272
- return err
225
+ if r := result .Status .Repository ; r != nil && len (r .AdditionalTags ) > 0 {
226
+ fmt .Fprintf (o .out , "\n info: The remote repository contained %d additional tags which were not imported: %s\n " , len (r .AdditionalTags ), strings .Join (r .AdditionalTags , ", " ))
273
227
}
274
-
275
- fmt .Fprintln (o .out , info )
276
228
return nil
277
229
}
278
230
@@ -297,45 +249,6 @@ func (e importError) Error() string {
297
249
return fmt .Sprintf ("unable to import image: %s" , e .annotation )
298
250
}
299
251
300
- func (o * ImportImageOptions ) waitForImport (resourceVersion string ) (* imageapi.ImageStream , error ) {
301
- streamWatch , err := o .isClient .Watch (metav1.ListOptions {FieldSelector : fields .OneTermEqualSelector ("metadata.name" , o .Name ).String (), ResourceVersion : resourceVersion })
302
- if err != nil {
303
- return nil , err
304
- }
305
- defer streamWatch .Stop ()
306
-
307
- for {
308
- select {
309
- case event , ok := <- streamWatch .ResultChan ():
310
- if ! ok {
311
- return nil , fmt .Errorf ("image stream watch ended prematurely" )
312
- }
313
-
314
- switch event .Type {
315
- case watch .Modified :
316
- s , ok := event .Object .(* imageapi.ImageStream )
317
- if ! ok {
318
- continue
319
- }
320
- annotation , ok := s .Annotations [imageapi .DockerImageRepositoryCheckAnnotation ]
321
- if ! ok {
322
- continue
323
- }
324
-
325
- if _ , err := time .Parse (time .RFC3339 , annotation ); err == nil {
326
- return s , nil
327
- }
328
- return nil , importError {annotation }
329
-
330
- case watch .Deleted :
331
- return nil , fmt .Errorf ("the image stream was deleted" )
332
- case watch .Error :
333
- return nil , fmt .Errorf ("error watching image stream" )
334
- }
335
- }
336
- }
337
- }
338
-
339
252
func (o * ImportImageOptions ) createImageImport () (* imageapi.ImageStream , * imageapi.ImageStreamImport , error ) {
340
253
var isi * imageapi.ImageStreamImport
341
254
stream , err := o .isClient .Get (o .Name , metav1.GetOptions {})
@@ -593,27 +506,3 @@ func (o *ImportImageOptions) newImageStreamImportTags(stream *imageapi.ImageStre
593
506
}
594
507
return isi
595
508
}
596
-
597
- // TransformUnsupportedError converts specific error conditions to unsupported
598
- func TransformUnsupportedError (err error ) error {
599
- if err == nil {
600
- return nil
601
- }
602
- if errors .IsNotFound (err ) {
603
- status , ok := err .(errors.APIStatus )
604
- if ! ok {
605
- return imageapi .ErrImageStreamImportUnsupported
606
- }
607
- if status .Status ().Details == nil || status .Status ().Details .Kind == "" {
608
- return imageapi .ErrImageStreamImportUnsupported
609
- }
610
- }
611
- // The ImageStreamImport resource exists in v1.1.1 of origin but is not yet
612
- // enabled by policy. A create request will return a Forbidden(403) error.
613
- // We want to return ErrImageStreamImportUnsupported to allow fallback behavior
614
- // in clients.
615
- if errors .IsForbidden (err ) && ! quotautil .IsErrorQuotaExceeded (err ) {
616
- return imageapi .ErrImageStreamImportUnsupported
617
- }
618
- return err
619
- }
0 commit comments