diff --git a/internal/bootstrap/ports.go b/internal/bootstrap/ports.go index 4da7560..f7a77c3 100644 --- a/internal/bootstrap/ports.go +++ b/internal/bootstrap/ports.go @@ -385,6 +385,12 @@ func NamesFree(ctx context.Context, run Runner, names []string, known store.Stat if known.Recorded(string(declaration.TypeContainer), name) { continue } + if name == giteaBootstrap && len(known.Resources) > 0 { + // Genesis raises the package registry itself, by hand and before the host records + // anything of it, so on a re-run it is found under its own name with no label and no + // record. A machine that carries what an earlier genesis raised made it. + continue + } taken = append(taken, name) } if len(taken) > 0 { diff --git a/internal/bootstrap/ports_test.go b/internal/bootstrap/ports_test.go index 49a3e64..a94371a 100644 --- a/internal/bootstrap/ports_test.go +++ b/internal/bootstrap/ports_test.go @@ -284,3 +284,16 @@ func TestAGenesisOnTheDefaultsSetsNoSettings(t *testing.T) { t.Errorf("a converged genesis on the default ports set settings: %v", c.told) } } + +func TestARerunOfGenesisFindsItsOwnPackageRegistry(t *testing.T) { + // Raised by genesis itself with no label and no record, so a re-run finds it unlabelled. + m := machineRunner{unlabelled: map[string]bool{giteaBootstrap: true}} + rerun := store.State{Resources: []store.Applied{{ID: "store", Type: "container", Target: "mesh-store"}}} + if err := NamesFree(context.Background(), m.run, []string{giteaBootstrap, "mesh-store"}, rerun); err != nil { + t.Errorf("a re-run refused the package registry genesis raised: %v", err) + } + // On a machine genesis never ran on, a container under that name is a predecessor's. + if err := NamesFree(context.Background(), m.run, []string{giteaBootstrap}, store.State{}); err == nil { + t.Error("a container under the package registry's name on a fresh machine was not refused") + } +}