fix(archied): label OpenShell gateway providers and sweep leftovers at boot (#1970)
This commit is contained in:
5 files changed
+74
-11
No files matched your search
@@ -23,10 +23,10 @@ import (
|
||||
"github.com/samcharles93/archie-core/internal/storage"
|
||||
)
|
||||
|
||||
// instanceLabel marks the sandboxes one archie instance owns; its value is
|
||||
// the instance name, so instances sharing a gateway never remove each
|
||||
// other's.
|
||||
const instanceLabel = "archie.instance"
|
||||
// InstanceLabel marks the sandboxes and gateway providers one archie instance
|
||||
// owns; its value is the instance name, so instances sharing a gateway never
|
||||
// remove each other's.
|
||||
const InstanceLabel = "archie.instance"
|
||||
|
||||
// agentBinary is where the agent image installs archie-agent. The sandbox's
|
||||
// main process names it, since OpenShell replaces the image's entrypoint,
|
||||
@@ -200,7 +200,7 @@ func (r *Runtime) Sweep(ctx context.Context) error {
|
||||
}
|
||||
var errs []error
|
||||
for _, sb := range all {
|
||||
if sb.Spec.Template == nil || sb.Spec.Template.Labels[instanceLabel] != r.instance {
|
||||
if sb.Spec.Template == nil || sb.Spec.Template.Labels[InstanceLabel] != r.instance {
|
||||
continue
|
||||
}
|
||||
r.log.InfoContext(ctx, "removing orphaned sandbox", "sandbox", sb.Name)
|
||||
@@ -277,7 +277,7 @@ func (r *Runtime) spec(l Launch) (*v1.SandboxSpec, error) {
|
||||
return &v1.SandboxSpec{
|
||||
Template: &v1.SandboxTemplate{
|
||||
Image: l.Image,
|
||||
Labels: map[string]string{instanceLabel: r.instance},
|
||||
Labels: map[string]string{InstanceLabel: r.instance},
|
||||
DriverConfig: map[string]any{"docker": map[string]any{"mounts": driverMounts}},
|
||||
},
|
||||
Environment: environment,
|
||||
|
||||
@@ -81,8 +81,8 @@ func TestSweepRemovesOnlyThisInstancesSandboxes(t *testing.T) {
|
||||
client := fake.NewClient()
|
||||
defer func() { _ = client.Close() }()
|
||||
for name, labels := range map[string]map[string]string{
|
||||
"archie-agent-1": {instanceLabel: "archie"},
|
||||
"staging-agent-1": {instanceLabel: "staging"},
|
||||
"archie-agent-1": {InstanceLabel: "archie"},
|
||||
"staging-agent-1": {InstanceLabel: "staging"},
|
||||
"someone-else": nil,
|
||||
} {
|
||||
client.AddSandbox("default", &v1.Sandbox{Name: name, Spec: v1.SandboxSpec{Template: &v1.SandboxTemplate{Labels: labels}}})
|
||||
|
||||
Reference in new issue
Block a user