|
72 | 72 | } |
73 | 73 | return testregistry.Deploy(context.Background(), cfg, testregistry.DefaultNamespace, testregistry.DefaultName) |
74 | 74 | }) |
| 75 | + startRegistryPortForward = sync.OnceValues(func() (string, error) { |
| 76 | + if err := deployImageRegistry(); err != nil { |
| 77 | + return "", err |
| 78 | + } |
| 79 | + cfg, err := ctrl.GetConfig() |
| 80 | + if err != nil { |
| 81 | + return "", fmt.Errorf("failed to get kubeconfig: %w", err) |
| 82 | + } |
| 83 | + // Port-forward lives for the duration of the test process; |
| 84 | + // the stop function is not needed because the goroutine is |
| 85 | + // cleaned up on process exit. |
| 86 | + localAddr, _, err := testregistry.PortForward(context.Background(), cfg, testregistry.DefaultNamespace, testregistry.DefaultName) |
| 87 | + if err != nil { |
| 88 | + return "", fmt.Errorf("failed to start port-forward to registry: %w", err) |
| 89 | + } |
| 90 | + return localAddr, nil |
| 91 | + }) |
75 | 92 | ) |
76 | 93 |
|
77 | 94 | func RegisterSteps(sc *godog.ScenarioContext) { |
@@ -226,18 +243,19 @@ func projectRootDir() string { |
226 | 243 | } |
227 | 244 | } |
228 | 245 |
|
229 | | -// registryHosts returns the local and in-cluster registry addresses from environment |
230 | | -// variables, falling back to defaults suitable for kind clusters. |
231 | | -func registryHosts() (string, string) { |
232 | | - local := os.Getenv("LOCAL_REGISTRY_HOST") |
233 | | - if local == "" { |
234 | | - local = "localhost:30000" |
| 246 | +// registryHosts returns the local and in-cluster registry addresses. |
| 247 | +// The local address is obtained by port-forwarding to the in-cluster registry, |
| 248 | +// which works regardless of the cluster's network topology. |
| 249 | +func registryHosts() (string, string, error) { |
| 250 | + local, err := startRegistryPortForward() |
| 251 | + if err != nil { |
| 252 | + return "", "", fmt.Errorf("failed to get local registry address: %w", err) |
235 | 253 | } |
236 | 254 | cluster := os.Getenv("CLUSTER_REGISTRY_HOST") |
237 | 255 | if cluster == "" { |
238 | 256 | cluster = "docker-registry.operator-controller-e2e.svc.cluster.local:5000" |
239 | 257 | } |
240 | | - return local, cluster |
| 258 | + return local, cluster, nil |
241 | 259 | } |
242 | 260 |
|
243 | 261 | // ImageRegistryIsAvailable ensures the in-cluster image registry is deployed and ready. |
@@ -1445,7 +1463,10 @@ func CatalogVersionWithPackages(ctx context.Context, catalogUserName, version st |
1445 | 1463 | } |
1446 | 1464 |
|
1447 | 1465 | cat := catalog.NewCatalog(catalogUserName, sc.id, pkgOpts...) |
1448 | | - localRegistry, clusterRegistry := registryHosts() |
| 1466 | + localRegistry, clusterRegistry, err := registryHosts() |
| 1467 | + if err != nil { |
| 1468 | + return err |
| 1469 | + } |
1449 | 1470 |
|
1450 | 1471 | result, err := cat.Build(ctx, version, localRegistry, clusterRegistry) |
1451 | 1472 | if err != nil { |
@@ -1495,7 +1516,10 @@ func ScenarioCatalogIsUpdatedToVersion(ctx context.Context, catalogUserName, ver |
1495 | 1516 |
|
1496 | 1517 | // ScenarioCatalogTagImage tags an existing per-scenario catalog image with a new tag. |
1497 | 1518 | func ScenarioCatalogTagImage(ctx context.Context, catalogUserName, oldTag, newTag string) error { |
1498 | | - localRegistry, _ := registryHosts() |
| 1519 | + localRegistry, _, err := registryHosts() |
| 1520 | + if err != nil { |
| 1521 | + return err |
| 1522 | + } |
1499 | 1523 | sc := scenarioCtx(ctx) |
1500 | 1524 | imageRef := fmt.Sprintf("%s/e2e/%s-catalog-%s:%s", localRegistry, catalogUserName, sc.id, oldTag) |
1501 | 1525 | return crane.Tag(imageRef, newTag, crane.Insecure) |
@@ -1592,7 +1616,10 @@ func CatalogWithPackages(ctx context.Context, catalogUserName string, table *god |
1592 | 1616 | } |
1593 | 1617 |
|
1594 | 1618 | cat := catalog.NewCatalog(catalogUserName, sc.id, pkgOpts...) |
1595 | | - localRegistry, clusterRegistry := registryHosts() |
| 1619 | + localRegistry, clusterRegistry, err := registryHosts() |
| 1620 | + if err != nil { |
| 1621 | + return err |
| 1622 | + } |
1596 | 1623 |
|
1597 | 1624 | result, err := cat.Build(ctx, "v1", localRegistry, clusterRegistry) |
1598 | 1625 | if err != nil { |
|
0 commit comments