Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/api/api/instances_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func TestInstanceLifecycle_StopStart(t *testing.T) {

// 1. Create instance
t.Log("Creating instance...")
networkEnabled := false
networkEnabled := true
createResp, err := svc.CreateInstance(ctx(), oapi.CreateInstanceRequestObject{
Body: &oapi.CreateInstanceRequest{
Name: "test-lifecycle",
Expand Down
4 changes: 2 additions & 2 deletions lib/network/allocate.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ func (m *manager) CreateAllocation(ctx context.Context, req AllocateRequest) (*N
return nil, fmt.Errorf("get default network: %w", err)
}

// 2. Check name uniqueness
exists, err := m.NameExists(ctx, req.InstanceName)
// 2. Check name uniqueness (exclude current instance to allow restarts)
exists, err := m.NameExists(ctx, req.InstanceName, req.InstanceID)
if err != nil {
return nil, fmt.Errorf("check name exists: %w", err)
}
Expand Down
10 changes: 8 additions & 2 deletions lib/network/derive.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,20 @@ func (m *manager) ListAllocations(ctx context.Context) ([]Allocation, error) {
return allocations, nil
}

// NameExists checks if instance name is already used in the default network
func (m *manager) NameExists(ctx context.Context, name string) (bool, error) {
// NameExists checks if instance name is already used in the default network.
// excludeInstanceID allows excluding a specific instance from the check (used when
// starting an existing instance to avoid it conflicting with itself).
func (m *manager) NameExists(ctx context.Context, name string, excludeInstanceID string) (bool, error) {
allocations, err := m.ListAllocations(ctx)
if err != nil {
return false, err
}

for _, alloc := range allocations {
// Skip the excluded instance (e.g., when restarting an instance)
if excludeInstanceID != "" && alloc.InstanceID == excludeInstanceID {
continue
}
if alloc.InstanceName == name {
return true, nil
}
Expand Down
2 changes: 1 addition & 1 deletion lib/network/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type Manager interface {
// Queries (derive from CH/snapshots)
GetAllocation(ctx context.Context, instanceID string) (*Allocation, error)
ListAllocations(ctx context.Context) ([]Allocation, error)
NameExists(ctx context.Context, name string) (bool, error)
NameExists(ctx context.Context, name string, excludeInstanceID string) (bool, error)

// GetUploadBurstMultiplier returns the configured multiplier for upload burst ceiling.
GetUploadBurstMultiplier() int
Expand Down
Loading