Merge pull request #5197 from thaJeztah/27.0_backport_fix_custom_ports

[27.0 backport] re-introduced support for port numbers in docker registry URL
This commit is contained in:
Sebastiaan van Stijn 2024-06-26 15:04:51 +02:00 committed by GitHub
commit 37533c2f55
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 21 additions and 1 deletions

View File

@ -74,8 +74,11 @@ func ConvertToHostname(maybeURL string) string {
if strings.Contains(stripped, "://") {
u, err := url.Parse(stripped)
if err == nil && u.Hostname() != "" {
if u.Port() == "" {
return u.Hostname()
}
return u.Hostname() + ":" + u.Port()
}
}
hostName, _, _ := strings.Cut(stripped, "/")
return hostName

View File

@ -167,6 +167,23 @@ func TestConvertToHostname(t *testing.T) {
input: "ftp://example.com",
expected: "example.com",
},
// should support non-standard port in registry url
{
input: "example.com:6555",
expected: "example.com:6555",
},
{
input: "http://example.com:6555",
expected: "example.com:6555",
},
{
input: "https://example.com:6555",
expected: "example.com:6555",
},
{
input: "https://example.com:6555/v2/",
expected: "example.com:6555",
},
}
for _, tc := range tests {
tc := tc