Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
11 changes: 5 additions & 6 deletions mock-api/msw/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,23 +68,23 @@ export const resolvePoolSelector = (
| { pool: string; type: 'explicit' }
| { type: 'auto'; ip_version?: IpVersion | null }
| undefined,
poolType?: IpPoolType
poolType: IpPoolType,
siloId: string = defaultSilo.id
) => {
if (poolSelector?.type === 'explicit') {
return lookup.ipPool({ pool: poolSelector.pool })
}

// For 'auto' type, find the default pool for the specified IP version and pool type
const silo = lookup.silo({ silo: defaultSilo.id })
const silo = lookup.silo({ silo: siloId })
const links = db.ipPoolSilos.filter((ips) => ips.silo_id === silo.id && ips.is_default)

// Filter candidate pools by both IP version and pool type
const candidateLinks = links.filter((ips) => {
const pool = db.ipPools.find((p) => p.id === ips.ip_pool_id)
if (!pool) return false

// If poolType specified, filter by it
if (poolType && pool.pool_type !== poolType) return false
if (pool.pool_type !== poolType) return false

// If IP version specified, filter by it
if (poolSelector?.ip_version && pool.ip_version !== poolSelector.ip_version) {
Expand All @@ -106,9 +106,8 @@ export const resolvePoolSelector = (

const link = candidateLinks[0]
if (!link) {
const typeStr = poolType ? ` ${poolType}` : ''
const versionStr = poolSelector?.ip_version ? ` ${poolSelector.ip_version}` : ''
throw notFoundErr(`default${typeStr}${versionStr} pool for silo '${defaultSilo.id}'`)
throw notFoundErr(`default ${poolType}${versionStr} pool for silo '${siloId}'`)
}
return lookupById(db.ipPools, link.ip_pool_id)
}
Expand Down
11 changes: 6 additions & 5 deletions mock-api/msw/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -395,10 +395,10 @@ export const handlers = makeHandlers({
return true // For mock purposes, just use first unicast pool
})
})
pool = poolWithIp || resolvePoolSelector(undefined, 'unicast')
pool = poolWithIp || resolvePoolSelector(undefined, 'unicast', project.silo_id)
} else {
// type === 'auto'
pool = resolvePoolSelector(addressAllocator.pool_selector, 'unicast')
pool = resolvePoolSelector(addressAllocator.pool_selector, 'unicast', project.silo_id)
ip = getIpFromPool(pool)
}

Expand Down Expand Up @@ -640,7 +640,7 @@ export const handlers = makeHandlers({
// which aren't quite as good as checking that there are actually IPs
// available, but they are good things to check
// Ephemeral IPs must use unicast pools
const pool = resolvePoolSelector(ip.pool_selector, 'unicast')
const pool = resolvePoolSelector(ip.pool_selector, 'unicast', project.silo_id)
getIpFromPool(pool)

// Validate that external IP version matches NIC's IP stack
Expand Down Expand Up @@ -773,7 +773,7 @@ export const handlers = makeHandlers({
floatingIp.instance_id = instanceId
} else if (ip.type === 'ephemeral') {
// Ephemeral IPs must use unicast pools
const pool = resolvePoolSelector(ip.pool_selector, 'unicast')
const pool = resolvePoolSelector(ip.pool_selector, 'unicast', project.silo_id)
const firstAvailableAddress = getIpFromPool(pool)

db.ephemeralIps.push({
Expand Down Expand Up @@ -959,8 +959,9 @@ export const handlers = makeHandlers({
},
instanceEphemeralIpAttach({ path, query: projectParams, body }) {
const instance = lookup.instance({ ...path, ...projectParams })
const instanceProject = lookup.project(projectParams)
// Ephemeral IPs must use unicast pools
const pool = resolvePoolSelector(body.pool_selector, 'unicast')
const pool = resolvePoolSelector(body.pool_selector, 'unicast', instanceProject.silo_id)
const ip = getIpFromPool(pool)

// Validate that external IP version matches primary NIC's IP stack
Expand Down
Loading