Skip to content

Commit b51ec45

Browse files
committed
replace use of instance client id in places where placement node id is needed
1 parent 22a0705 commit b51ec45

File tree

7 files changed

+16
-19
lines changed

7 files changed

+16
-19
lines changed

packages/api/internal/cache/instance/sync.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func (c *InstanceCache) Sync(ctx context.Context, instances []*InstanceInfo, nod
6565

6666
// Delete instances that are not in Orchestrator anymore
6767
for _, item := range c.cache.Items() {
68-
if item.Instance.ClientID != nodeID {
68+
if item.Node.ID != nodeID {
6969
continue
7070
}
7171
if time.Since(item.StartTime) <= syncSandboxRemoveGracePeriod {

packages/api/internal/handlers/sandbox_create.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,6 @@ func (a *APIStore) PostSandboxes(c *gin.Context) {
170170
return
171171
}
172172

173-
c.Set("nodeID", sbx.ClientID)
174-
175173
c.JSON(http.StatusCreated, &sbx)
176174
}
177175

packages/api/internal/orchestrator/cache.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -311,11 +311,10 @@ func (o *Orchestrator) getDeleteInstanceFunction(
311311
duration,
312312
)
313313

314-
node := o.GetNode(info.Instance.ClientID)
314+
node := o.GetNode(info.Node.ID)
315315
if node == nil {
316-
zap.L().Error("failed to get node", zap.String("node_id", info.Instance.ClientID))
317-
318-
return fmt.Errorf("node '%s' not found", info.Instance.ClientID)
316+
zap.L().Error("failed to get node", logger.WithNodeID(info.Node.ID))
317+
return fmt.Errorf("node '%s' not found", info.Node.ID)
319318
}
320319

321320
node.CPUUsage.Add(-info.VCpu)
@@ -324,9 +323,8 @@ func (o *Orchestrator) getDeleteInstanceFunction(
324323
o.dns.Remove(ctx, info.Instance.SandboxID, node.Info.IPAddress)
325324

326325
if node.Client == nil {
327-
zap.L().Error("client for node not found", zap.String("node_id", info.Instance.ClientID))
328-
329-
return fmt.Errorf("client for node '%s' not found", info.Instance.ClientID)
326+
zap.L().Error("client for node not found", logger.WithNodeID(info.Node.ID))
327+
return fmt.Errorf("client for node '%s' not found", info.Node.ID)
330328
}
331329

332330
if ct == ClosePause {
@@ -416,9 +414,9 @@ func (o *Orchestrator) getInsertInstanceFunction(parentCtx context.Context, time
416414
zap.Bool("auto_pause", info.AutoPause.Load()),
417415
)
418416

419-
node := o.GetNode(info.Instance.ClientID)
417+
node := o.GetNode(info.Node.ID)
420418
if node == nil {
421-
zap.L().Error("failed to get node", zap.String("node_id", info.Instance.ClientID))
419+
zap.L().Error("failed to get node", logger.WithNodeID(info.Node.ID))
422420
} else {
423421
node.CPUUsage.Add(info.VCpu)
424422
node.RamUsage.Add(info.RamMB)

packages/api/internal/orchestrator/keep_alive.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func (o *Orchestrator) KeepAliveFor(ctx context.Context, sandboxID string, durat
1717
return apiErr
1818
}
1919

20-
err := o.UpdateSandbox(ctx, sbx.Instance.SandboxID, sbx.GetEndTime(), sbx.Instance.ClientID)
20+
err := o.UpdateSandbox(ctx, sbx.Instance.SandboxID, sbx.GetEndTime(), sbx.Node.ID)
2121
if err != nil {
2222
zap.L().Error("Error when setting sandbox timeout", zap.Error(err), logger.WithSandboxID(sandboxID))
2323
return &api.APIError{Code: http.StatusInternalServerError, ClientMsg: "Error when setting sandbox timeout", Err: err}

packages/api/internal/orchestrator/list_instances.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func (o *Orchestrator) getSandboxes(ctx context.Context, node *nNode.NodeInfo) (
7171
SandboxID: config.SandboxId,
7272
TemplateID: config.TemplateId,
7373
Alias: config.Alias,
74-
ClientID: node.ID, // to prevent mismatch use the node ID which we use for the request
74+
ClientID: sbx.ClientId,
7575
},
7676
config.ExecutionId,
7777
&teamID,

packages/api/internal/orchestrator/node.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"github.com/e2b-dev/infra/packages/shared/pkg/consts"
2121
"github.com/e2b-dev/infra/packages/shared/pkg/grpc/orchestrator"
2222
orchestratorinfo "github.com/e2b-dev/infra/packages/shared/pkg/grpc/orchestrator-info"
23+
"github.com/e2b-dev/infra/packages/shared/pkg/logger"
2324
"github.com/e2b-dev/infra/packages/shared/pkg/smap"
2425
)
2526

@@ -183,9 +184,9 @@ func (o *Orchestrator) GetNodes() []*api.Node {
183184
}
184185

185186
for _, sbx := range o.instanceCache.Items() {
186-
n, ok := nodes[sbx.Instance.ClientID]
187+
n, ok := nodes[sbx.Node.ID]
187188
if !ok {
188-
zap.L().Error("node for sandbox wasn't found", zap.String("client_id", sbx.Instance.ClientID), zap.String("sandbox_id", sbx.Instance.SandboxID))
189+
zap.L().Error("node for sandbox wasn't found", logger.WithNodeID(sbx.Node.ID), logger.WithSandboxID(sbx.Instance.SandboxID))
189190
continue
190191
}
191192

@@ -232,7 +233,7 @@ func (o *Orchestrator) GetNodeDetail(nodeID string) *api.NodeDetail {
232233
}
233234

234235
for _, sbx := range o.instanceCache.Items() {
235-
if sbx.Instance.ClientID == nodeID {
236+
if sbx.Node.ID == nodeID {
236237
var metadata *api.SandboxMetadata
237238
if sbx.Metadata != nil {
238239
meta := api.SandboxMetadata(sbx.Metadata)

packages/api/internal/orchestrator/pause_instance.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ func snapshotInstance(ctx context.Context, orch *Orchestrator, sbx *instance.Ins
8585
_, childSpan := orch.tracer.Start(ctx, "snapshot-instance")
8686
defer childSpan.End()
8787

88-
client, clientMd, err := orch.GetClient(sbx.Instance.ClientID)
88+
client, clientMd, err := orch.GetClient(sbx.Node.ID)
8989
if err != nil {
90-
return fmt.Errorf("failed to get client '%s': %w", sbx.Instance.ClientID, err)
90+
return fmt.Errorf("failed to get client '%s': %w", sbx.Node.ID, err)
9191
}
9292

9393
reqCtx := metadata.NewOutgoingContext(ctx, clientMd)

0 commit comments

Comments
 (0)