feat(container): end the install phase between install and startup hooks

StartKit calls InstallDone after the install hooks, before files and
startup hooks, so the caller moves the egress session to its runtime
policy exactly where the Kit spec ends the install phase.
This commit is contained in:
sam committed 2026-09-26 03:17:49 +10:00
1 parent ef845daf47
commit ac738e6d07
2 files changed
+28

No files matched your search

+7
View File
@@ -32,6 +32,10 @@ type KitSpec struct {
Binds []string
Labels map[string]string
Launch kit.Launch
// InstallDone runs after the install hooks and before anything else, so
// the caller can end the install phase: the egress session moves to its
// runtime policy and install-phase credentials stop resolving.
InstallDone func()
}
// StartKit creates and starts a Kit container, then brings it to the state
@@ -79,6 +83,9 @@ func StartKit(ctx context.Context, cli *client.Client, s KitSpec) (string, error
return fail(fmt.Errorf("install hook %d: %w", i+1, err))
}
}
if s.InstallDone != nil {
s.InstallDone()
}
for _, f := range s.Launch.Files {
if err := writeKitFile(ctx, cli, created.ID, s.Launch.Harness.User, f.Path, f.Content, f.Mode, f.Overwrite); err != nil {
return fail(fmt.Errorf("write kit file %s: %w", f.Path, err))
+21
View File
@@ -139,3 +139,24 @@ func TestKitContainerFailingInstallHookIsRemoved(t *testing.T) {
t.Fatalf("a failed Kit start left %d container(s) behind", len(list.Items))
}
}
func TestKitContainerEndsTheInstallPhaseBetweenInstallAndStartup(t *testing.T) {
cli := kitClient(t)
s := kitSpec(t, kit.Hook{Argv: []string{"sh", "-c", "touch /tmp/installed"}, User: "0"})
var containerName string
var sawInstalled, sawStartup bool
s.InstallDone = func() {
containerName = s.Name
code, _, err := ExecIn(context.WithoutCancel(t.Context()), cli, containerName, "0", nil, []string{"test", "-e", "/tmp/installed"})
sawInstalled = err == nil && code == 0
code, _, err = ExecIn(context.WithoutCancel(t.Context()), cli, containerName, "0", nil, []string{"test", "-e", "/tmp/startup-uid"})
sawStartup = err == nil && code == 0
}
startKit(t, cli, s)
if containerName == "" {
t.Fatal("InstallDone was never called")
}
if !sawInstalled || sawStartup {
t.Fatalf("InstallDone ran with install done=%v and startup done=%v; want after install, before startup", sawInstalled, sawStartup)
}
}