Create service connections for image with registry host and without project

See gh-46974

Signed-off-by: Yanming Zhou <zhouyanming@gmail.com>
This commit is contained in:
Yanming Zhou
2025-09-02 14:30:01 +02:00
committed by Moritz Halbritter
parent fafd0bbd20
commit c8d29fd3fe
2 changed files with 4 additions and 2 deletions
@@ -29,6 +29,7 @@ import org.springframework.util.Assert;
* {@link Predicate} that matches against connection name.
*
* @author Phillip Webb
* @author Yanming Zhou
*/
class ConnectionNamePredicate implements Predicate<DockerComposeConnectionSource> {
@@ -47,7 +48,7 @@ class ConnectionNamePredicate implements Predicate<DockerComposeConnectionSource
private String getActual(RunningService service) {
String label = service.labels().get("org.springframework.boot.service-connection");
return (label != null) ? asCanonicalName(label) : service.image().getName();
return asCanonicalName((label != null) ? label : service.image().getName());
}
private String asCanonicalName(String name) {
@@ -32,6 +32,7 @@ import static org.mockito.Mockito.mock;
* Tests for {@link ConnectionNamePredicate}.
*
* @author Phillip Webb
* @author Yanming Zhou
*/
class ConnectionNamePredicateTests {
@@ -63,7 +64,7 @@ class ConnectionNamePredicateTests {
assertThat(predicateOf("redis")).accepts(sourceOf("internalhost:8080/library/redis"));
assertThat(predicateOf("redis")).accepts(sourceOf("myhost.com/library/redis"));
assertThat(predicateOf("redis")).accepts(sourceOf("myhost.com:8080/library/redis"));
assertThat(predicateOf("redis")).rejects(sourceOf("internalhost:8080/redis"));
assertThat(predicateOf("redis")).accepts(sourceOf("internalhost:8080/redis"));
}
@Test