Browse code

Apply defaulting in image stream import

In the future, we should move ISI to a versioned client.

Clayton Coleman authored on 2016/12/21 06:02:58
Showing 4 changed files
... ...
@@ -212,6 +212,15 @@ func fuzzInternalObject(t *testing.T, forVersion unversioned.GroupVersion, item
212 212
 			j.IssuedBy = nil
213 213
 			j.IssuedTo = nil
214 214
 		},
215
+		func(j *image.ImageStream, c fuzz.Continue) {
216
+			c.FuzzNoCustom(j)
217
+			for k, v := range j.Spec.Tags {
218
+				if len(v.ReferencePolicy.Type) == 0 {
219
+					v.ReferencePolicy.Type = image.SourceTagReferencePolicy
220
+					j.Spec.Tags[k] = v
221
+				}
222
+			}
223
+		},
215 224
 		func(j *image.ImageStreamMapping, c fuzz.Continue) {
216 225
 			c.FuzzNoCustom(j)
217 226
 			j.DockerImageRepository = ""
... ...
@@ -20,6 +20,7 @@ import (
20 20
 	"github.com/openshift/origin/pkg/client"
21 21
 	"github.com/openshift/origin/pkg/dockerregistry"
22 22
 	"github.com/openshift/origin/pkg/image/api"
23
+	imageapiv1 "github.com/openshift/origin/pkg/image/api/v1"
23 24
 	"github.com/openshift/origin/pkg/image/importer"
24 25
 	"github.com/openshift/origin/pkg/image/registry/imagestream"
25 26
 	quotautil "github.com/openshift/origin/pkg/quota/util"
... ...
@@ -237,6 +238,20 @@ func (r *REST) Create(ctx kapi.Context, obj runtime.Object) (runtime.Object, err
237 237
 
238 238
 	clearManifests(isi)
239 239
 
240
+	// ensure defaulting is applied by round trip converting
241
+	// TODO: convert to using versioned types.
242
+	external, err := kapi.Scheme.ConvertToVersion(stream, imageapiv1.SchemeGroupVersion)
243
+	if err != nil {
244
+		return nil, err
245
+	}
246
+	internal, err := kapi.Scheme.ConvertToVersion(external, api.SchemeGroupVersion)
247
+	if err != nil {
248
+		return nil, err
249
+	}
250
+	stream = internal.(*api.ImageStream)
251
+
252
+	// if and only if we have changes between the original and the imported stream, trigger
253
+	// an import
240 254
 	hasChanges := !kapi.Semantic.DeepEqual(original, stream)
241 255
 	if create {
242 256
 		stream.Annotations[api.DockerImageRepositoryCheckAnnotation] = now.UTC().Format(time.RFC3339)
... ...
@@ -419,6 +419,9 @@ func TestDeleteImageStreamTag(t *testing.T) {
419 419
 						Name: "test:foo",
420 420
 					},
421 421
 					Generation: &three,
422
+					ReferencePolicy: api.TagReferencePolicy{
423
+						Type: api.SourceTagReferencePolicy,
424
+					},
422 425
 				},
423 426
 			}
424 427
 			expectedStreamStatus := map[string]api.TagEventList{
... ...
@@ -100,7 +100,7 @@ func TestImageStreamImport(t *testing.T) {
100 100
 		},
101 101
 	})
102 102
 	if err != nil || isi == nil || isi.Status.Import == nil {
103
-		t.Fatalf("unexpected responses: %v %#v %#v", err, isi, isi.Status.Import)
103
+		t.Fatalf("unexpected responses: %v %#v", err, isi)
104 104
 	}
105 105
 
106 106
 	if isi.Status.Images[0].Image == nil || isi.Status.Images[0].Image.DockerImageMetadata.Size == 0 || len(isi.Status.Images[0].Image.DockerImageLayers) == 0 {