@@ -139,46 +139,54 @@ func (r *REST) Create(ctx apirequest.Context, obj runtime.Object, createValidati
139
139
return nil , fmt .Errorf ("%q must be of the form <stream_name>:<tag>" , istag .Name )
140
140
}
141
141
142
- target , err := r .imageStreamRegistry .GetImageStream (ctx , imageStreamName , & metav1.GetOptions {})
143
- if err != nil {
144
- if ! kapierrors .IsNotFound (err ) {
145
- return nil , err
146
- }
142
+ for i := 10 ; i > 0 ; i -- {
143
+ target , err := r .imageStreamRegistry .GetImageStream (ctx , imageStreamName , & metav1.GetOptions {})
144
+ if err != nil {
145
+ if ! kapierrors .IsNotFound (err ) {
146
+ return nil , err
147
+ }
147
148
148
- // try to create the target if it doesn't exist
149
- target = & imageapi.ImageStream {
150
- ObjectMeta : metav1.ObjectMeta {
151
- Name : imageStreamName ,
152
- Namespace : namespace ,
153
- },
149
+ // try to create the target if it doesn't exist
150
+ target = & imageapi.ImageStream {
151
+ ObjectMeta : metav1.ObjectMeta {
152
+ Name : imageStreamName ,
153
+ Namespace : namespace ,
154
+ },
155
+ }
154
156
}
155
- }
156
157
157
- if target .Spec .Tags == nil {
158
- target .Spec .Tags = make (map [string ]imageapi.TagReference )
159
- }
158
+ if target .Spec .Tags == nil {
159
+ target .Spec .Tags = make (map [string ]imageapi.TagReference )
160
+ }
160
161
161
- // The user wants to symlink a tag.
162
- _ , exists := target .Spec .Tags [imageTag ]
163
- if exists {
164
- return nil , kapierrors .NewAlreadyExists (imageapi .Resource ("imagestreamtag" ), istag .Name )
165
- }
166
- if istag .Tag != nil {
167
- target .Spec .Tags [imageTag ] = * istag .Tag
168
- }
162
+ // The user wants to symlink a tag.
163
+ _ , exists := target .Spec .Tags [imageTag ]
164
+ if exists {
165
+ return nil , kapierrors .NewAlreadyExists (imageapi .Resource ("imagestreamtag" ), istag .Name )
166
+ }
167
+ if istag .Tag != nil {
168
+ target .Spec .Tags [imageTag ] = * istag .Tag
169
+ }
169
170
170
- // Check the stream creation timestamp and make sure we will not
171
- // create a new image stream while deleting.
172
- if target .CreationTimestamp .IsZero () {
173
- _ , err = r .imageStreamRegistry .CreateImageStream (ctx , target )
174
- } else {
175
- _ , err = r .imageStreamRegistry .UpdateImageStream (ctx , target )
176
- }
177
- if err != nil {
178
- return nil , err
171
+ // Check the stream creation timestamp and make sure we will not
172
+ // create a new image stream while deleting.
173
+ if target .CreationTimestamp .IsZero () {
174
+ target , err = r .imageStreamRegistry .CreateImageStream (ctx , target )
175
+ } else {
176
+ target , err = r .imageStreamRegistry .UpdateImageStream (ctx , target )
177
+ }
178
+ if kapierrors .IsAlreadyExists (err ) || kapierrors .IsConflict (err ) {
179
+ continue
180
+ }
181
+ if err != nil {
182
+ return nil , err
183
+ }
184
+ image , _ := r .imageFor (ctx , imageTag , target )
185
+ return newISTag (imageTag , target , image , true )
179
186
}
180
-
181
- return istag , nil
187
+ // We tried to update resource, but we kept conflicting. Inform the client that we couldn't complete
188
+ // the operation but that they may try again.
189
+ return nil , kapierrors .NewServerTimeout (imageapi .Resource ("imagestreamtags" ), "create" , 2 )
182
190
}
183
191
184
192
func (r * REST ) Update (ctx apirequest.Context , tagName string , objInfo rest.UpdatedObjectInfo , createValidation rest.ValidateObjectFunc , updateValidation rest.ValidateObjectUpdateFunc ) (runtime.Object , bool , error ) {
0 commit comments