feat(operator): 平台升级不再重启运行中的游戏服,registry 清理保留游戏 pod 在用的镜像
This commit is contained in:
5 files changed
+188
-10
No files matched your search
+17
-5
@@ -284,9 +284,10 @@ func cmdAPI(args []string, stdout, stderr io.Writer) int {
|
||||
rcfg = reaper.DefaultConfig()
|
||||
}
|
||||
|
||||
cluster := api.NewK8sCluster(cl, cfg.K8s.Namespace)
|
||||
a := &api.API{
|
||||
Repo: repo,
|
||||
Cluster: api.NewK8sCluster(cl, cfg.K8s.Namespace),
|
||||
Cluster: cluster,
|
||||
Console: api.NewK8sConsole(cl, cfg.K8s.Namespace),
|
||||
Logs: api.NewK8sLogStreamer(clientset, cfg.K8s.Namespace),
|
||||
// Build-log stream (spec §16) is scoped to the BUILD namespace — the same
|
||||
@@ -408,7 +409,7 @@ func cmdAPI(args []string, stdout, stderr io.Writer) int {
|
||||
// reconciles it, but this loop converges builds nobody is polling.
|
||||
go reconcileBuilds(ctx, builder, stderr)
|
||||
|
||||
if pruner := registryPruner(cfg, builder.Store, a.Cluster, stderr); pruner != nil {
|
||||
if pruner := registryPruner(cfg, builder.Store, cluster, stderr); pruner != nil {
|
||||
go pruner.Loop(ctx, registryPruneInterval)
|
||||
}
|
||||
go reapRejectedContexts(ctx, submissions, stderr)
|
||||
@@ -683,13 +684,19 @@ type imageRefStore interface {
|
||||
|
||||
type serverLister interface {
|
||||
ListServers(ctx context.Context) ([]api.ServerInfo, error)
|
||||
PodImages(ctx context.Context) ([]string, error)
|
||||
}
|
||||
|
||||
// inUseImageRefs lists every image reference the platform still depends on: the
|
||||
// whitelist (disabled rows too, an admin may enable them again), every server's
|
||||
// spec, builds still running, and the images the control plane and the build
|
||||
// Jobs run. Any source failing fails the whole list, so the pruner never decides
|
||||
// on a partial view.
|
||||
// spec, the images the game pods run, builds still running, and the images the
|
||||
// control plane and the build Jobs run. Any source failing fails the whole list,
|
||||
// so the pruner never decides on a partial view.
|
||||
//
|
||||
// The pods matter for the felis image: a running server keeps the one it started
|
||||
// with across platform upgrades (operator.PodTemplateAnnotation), which after a
|
||||
// few releases is no longer among the newest tags the pruner keeps anyway, and
|
||||
// the pod needs it again whenever it is recreated.
|
||||
func inUseImageRefs(ctx context.Context, store imageRefStore, servers serverLister, static []string) ([]string, error) {
|
||||
refs := append([]string(nil), static...)
|
||||
images, err := store.ListImages(ctx)
|
||||
@@ -706,6 +713,11 @@ func inUseImageRefs(ctx context.Context, store imageRefStore, servers serverList
|
||||
for _, s := range srvs {
|
||||
refs = append(refs, s.Image)
|
||||
}
|
||||
podImages, err := servers.PodImages(ctx)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("game pods: %w", err)
|
||||
}
|
||||
refs = append(refs, podImages...)
|
||||
builds, err := store.ListUnfinishedBuilds(ctx)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("running builds: %w", err)
|
||||
|
||||
+18
-3
@@ -108,9 +108,14 @@ func (f fakeRefStore) ListUnfinishedBuilds(context.Context) ([]build.Build, erro
|
||||
return f.builds, nil
|
||||
}
|
||||
|
||||
type fakeServers []api.ServerInfo
|
||||
type fakeServers struct {
|
||||
list []api.ServerInfo
|
||||
pods []string
|
||||
podsErr error
|
||||
}
|
||||
|
||||
func (f fakeServers) ListServers(context.Context) ([]api.ServerInfo, error) { return f, nil }
|
||||
func (f fakeServers) ListServers(context.Context) ([]api.ServerInfo, error) { return f.list, nil }
|
||||
func (f fakeServers) PodImages(context.Context) ([]string, error) { return f.pods, f.podsErr }
|
||||
|
||||
// The registry pruner deletes whatever this list does not name, so every source of
|
||||
// a reference has to be in it, and a failing source must fail the list.
|
||||
@@ -120,7 +125,10 @@ func TestInUseImageRefsCoversEverySource(t *testing.T) {
|
||||
images: []build.Image{{ImageRef: reg + "modpacks/pack:*"}, {ImageRef: reg + "felis/paper:demo"}},
|
||||
builds: []build.Build{{ImageRef: reg + "user-uploads/sub-9:latest"}},
|
||||
}
|
||||
servers := fakeServers{{Name: "s1", Image: reg + "felis/paper:demo@sha256:" + fmt.Sprintf("%064d", 1)}}
|
||||
servers := fakeServers{
|
||||
list: []api.ServerInfo{{Name: "s1", Image: reg + "felis/paper:demo@sha256:" + fmt.Sprintf("%064d", 1)}},
|
||||
pods: []string{reg + "felis/felis:v1.0.0"},
|
||||
}
|
||||
got, err := inUseImageRefs(context.Background(), store, servers, []string{reg + "felis/felis:b60"})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -129,12 +137,19 @@ func TestInUseImageRefsCoversEverySource(t *testing.T) {
|
||||
reg + "felis/felis:b60",
|
||||
reg + "modpacks/pack:*", reg + "felis/paper:demo",
|
||||
reg + "felis/paper:demo@sha256:" + fmt.Sprintf("%064d", 1),
|
||||
reg + "felis/felis:v1.0.0",
|
||||
reg + "user-uploads/sub-9:latest",
|
||||
}
|
||||
if fmt.Sprint(got) != fmt.Sprint(want) {
|
||||
t.Fatalf("refs = %v\nwant %v", got, want)
|
||||
}
|
||||
|
||||
servers.podsErr = errors.New("apiserver down")
|
||||
if _, err := inUseImageRefs(context.Background(), store, servers, nil); err == nil {
|
||||
t.Fatal("a failing pod list produced a reference list")
|
||||
}
|
||||
servers.podsErr = nil
|
||||
|
||||
store.err = errors.New("db down")
|
||||
if _, err := inUseImageRefs(context.Background(), store, servers, nil); err == nil {
|
||||
t.Fatal("a failing whitelist read produced a reference list")
|
||||
|
||||
Reference in new issue
Block a user