Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions pkg/controller/internalreleaseimage/aggregation.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,9 +283,24 @@ func buildAPIIntUnavailableReleases(specReleases []mcfgv1alpha1.InternalReleaseI
return releases
}

// transformToAPIIntURL converts localhost:22625/path to api-int.<domain>:22625/path
// transformToAPIIntURL converts a localhost URL (e.g. localhost:22625/path or
// localhost.localdomain:22625/path) to api-int.<domain>:22625/path by replacing
// the hostname before the port with the api-int hostname.
func transformToAPIIntURL(localhostURL, clusterDomain string) string {
return strings.Replace(localhostURL, "localhost", "api-int."+clusterDomain, 1)
// Find the host:port boundary by looking for ":" before the first "/"
slashIdx := strings.Index(localhostURL, "/")
hostPort := localhostURL
if slashIdx >= 0 {
hostPort = localhostURL[:slashIdx]
}

colonIdx := strings.Index(hostPort, ":")
if colonIdx < 0 {
// No port found — return unchanged to avoid mangling the URL
return localhostURL
}

return "api-int." + clusterDomain + localhostURL[colonIdx:]
}

// pingRegistry checks if the registry at the given URL is reachable.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -461,3 +461,50 @@ func TestAggregateIRIStatus(t *testing.T) {
})
}
}

func TestTransformToAPIIntURL(t *testing.T) {
cases := []struct {
name string
localhostURL string
clusterDomain string
expected string
}{
{
name: "localhost without localdomain",
localhostURL: "localhost:22625/openshift/release-images@sha256:abc123",
clusterDomain: "ostest.test.metalkube.org",
expected: "api-int.ostest.test.metalkube.org:22625/openshift/release-images@sha256:abc123",
},
{
name: "localhost.localdomain",
localhostURL: "localhost.localdomain:22625/openshift/release-images@sha256:abc123",
clusterDomain: "ostest.test.metalkube.org",
expected: "api-int.ostest.test.metalkube.org:22625/openshift/release-images@sha256:abc123",
},
{
name: "no port returns input unchanged",
localhostURL: "localhost",
clusterDomain: "example.com",
expected: "localhost",
},
{
name: "no port with sha256 digest returns input unchanged",
localhostURL: "localhost/openshift/release-images@sha256:abc123",
clusterDomain: "example.com",
expected: "localhost/openshift/release-images@sha256:abc123",
},
{
name: "non-localhost host with port",
localhostURL: "virthost.example.com:5000/openshift/release-images@sha256:abc123",
clusterDomain: "ostest.test.metalkube.org",
expected: "api-int.ostest.test.metalkube.org:5000/openshift/release-images@sha256:abc123",
},
}

for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
result := transformToAPIIntURL(tc.localhostURL, tc.clusterDomain)
assert.Equal(t, tc.expected, result)
})
}
}