@@ -3,6 +3,7 @@ package imagestreamimport
3
3
import (
4
4
"fmt"
5
5
"net/http"
6
+ "strings"
6
7
"time"
7
8
8
9
"github.com/golang/glog"
@@ -199,6 +200,34 @@ func (r *REST) Create(ctx apirequest.Context, obj runtime.Object, createValidati
199
200
return nil , kapierrors .NewInternalError (err )
200
201
}
201
202
203
+ // check imported images status. If we get authentication error (401), try import same image without authentication.
204
+ // Docker registry gives 401 on public images if you have wrong secret in your secret list.
205
+ // this block was introduced by PR #18012
206
+ var imageStatus []metav1.Status
207
+ importFailed := false
208
+ for _ , image := range isi .Status .Images {
209
+ //cache all imports status
210
+ imageStatus = append (imageStatus , image .Status )
211
+ if image .Status .Reason == metav1 .StatusReasonUnauthorized && strings .Contains (strings .ToLower (image .Status .Message ), "username or password" ) {
212
+ importFailed = true
213
+ }
214
+ }
215
+ // try import IS without auth if it failed before
216
+ if importFailed {
217
+ importCtx := registryclient .NewContext (r .transport , r .insecureTransport ).WithCredentials (nil )
218
+ imports := r .importFn (importCtx )
219
+ //TODO add check if we get error and run import outside the loop
220
+ if err := imports .Import (ctx .(gocontext.Context ), isi , stream ); err != nil {
221
+ return nil , kapierrors .NewInternalError (err )
222
+ }
223
+ }
224
+ //cycle through status and set old messages so not to confuse users
225
+ for key , image := range isi .Status .Images {
226
+ if image .Status .Reason == metav1 .StatusReasonUnauthorized {
227
+ isi .Status .Images [key ].Status = imageStatus [key ]
228
+ }
229
+ }
230
+
202
231
// if we encountered an error loading credentials and any images could not be retrieved with an access
203
232
// related error, modify the message.
204
233
// TODO: set a status cause
0 commit comments