feat(admin): reconciler marks reaped instances deleted

Without this the row stays active forever, the reconciler re-logs the
same miss every fifteen minutes, and the lifecycle sweep keeps emailing
about an instance that no longer exists.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
mrhid6
2026-07-26 13:24:44 +01:00
co-authored by Claude Opus 5
parent 4e90e8619f
commit a940390791
+15
View File
@@ -7,6 +7,7 @@ package inject
import (
"context"
"errors"
"fmt"
"log"
"time"
@@ -16,6 +17,7 @@ import (
"github.com/mrhid6/vantage/shared/license"
sharedmodels "github.com/mrhid6/vantage/shared/models"
"go.mongodb.org/mongo-driver/v2/bson"
"go.mongodb.org/mongo-driver/v2/mongo"
)
// ReconcileInterval is how often every cloud instance is compared against what
@@ -103,6 +105,19 @@ func Reconcile(ctx context.Context) (checked, repaired int, err error) {
var remote sharedmodels.Instance
if err := db.Control("instances").FindOne(ctx,
bson.M{"instance_id": inst.InstanceID}).Decode(&remote); err != nil {
// The control plane's reaper deletes lapsed Free instances. Record
// that here rather than re-logging it every fifteen minutes forever,
// and so the lifecycle sweep stops emailing about it.
if errors.Is(err, mongo.ErrNoDocuments) {
if _, uErr := db.Admin("admin_instances").UpdateOne(ctx,
bson.M{"instance_id": inst.InstanceID},
bson.M{"$set": bson.M{"status": models.StatusDeleted}}); uErr != nil {
log.Printf("reconcile: mark %s deleted: %v", inst.InstanceID, uErr)
} else {
log.Printf("reconcile: instance %s is gone from the control plane; marked deleted", inst.InstanceID)
}
continue
}
log.Printf("reconcile: no control-plane instance %s: %v", inst.InstanceID, err)
continue
}