@@ -1353,32 +1353,39 @@ func validateRegistryMirror() {
1353
1353
// args match the format of registry.cn-hangzhou.aliyuncs.com/google_containers
1354
1354
// also "<hostname>[:<port>]"
1355
1355
func validateImageRepository (imageRepo string ) (validImageRepo string ) {
1356
+ expression := regexp .MustCompile (`^(?:(\w+)\:\/\/)?([-a-zA-Z0-9]{1,}(?:\.[-a-zA-Z]{1,}){0,})(?:\:(\d+))?(\/.*)?$` )
1356
1357
1357
1358
if strings .ToLower (imageRepo ) == "auto" {
1358
- validImageRepo = "auto"
1359
+ imageRepo = "auto"
1359
1360
}
1360
- URL , err := url .Parse (imageRepo )
1361
1361
1362
- if err != nil {
1363
- klog .Errorln ("Error Parsing URL: " , err )
1362
+ if ! expression .MatchString (imageRepo ) {
1363
+ klog .Errorln ("Provided repository is not a valid URL. Defaulting to \" auto\" " )
1364
+ imageRepo = "auto"
1364
1365
}
1365
1366
1366
1367
var imageRepoPort string
1368
+ groups := expression .FindStringSubmatch (imageRepo )
1369
+
1370
+ scheme := groups [1 ]
1371
+ hostname := groups [2 ]
1372
+ port := groups [3 ]
1373
+ path := groups [4 ]
1367
1374
1368
- if URL . Port () != "" && strings .Contains (imageRepo , ":" + URL . Port () ) {
1369
- imageRepoPort = ":" + URL . Port ()
1375
+ if port != "" && strings .Contains (imageRepo , ":" + port ) {
1376
+ imageRepoPort = ":" + port
1370
1377
}
1371
1378
1372
1379
// tips when imageRepo ended with a trailing /.
1373
1380
if strings .HasSuffix (imageRepo , "/" ) {
1374
- out .Infof ("The --image-repository flag your provided ended with a trailing / that could cause conflict in kuberentes , removed automatically" )
1381
+ out .Infof ("The --image-repository flag your provided ended with a trailing / that could cause conflict in kubernetes , removed automatically" )
1375
1382
}
1376
1383
// tips when imageRepo started with scheme such as http(s).
1377
- if URL . Scheme != "" {
1378
- out .Infof ("The --image-repository flag your provided contains Scheme: {{.scheme}}, which will be removed automatically" , out.V {"scheme" : URL . Scheme })
1384
+ if scheme != "" {
1385
+ out .Infof ("The --image-repository flag you provided contains Scheme: {{.scheme}}, which will be removed automatically" , out.V {"scheme" : scheme })
1379
1386
}
1380
1387
1381
- validImageRepo = URL . Hostname () + imageRepoPort + strings .TrimSuffix (URL . Path , "/" )
1388
+ validImageRepo = hostname + imageRepoPort + strings .TrimSuffix (path , "/" )
1382
1389
1383
1390
return validImageRepo
1384
1391
}
0 commit comments