Skip to content

Commit 0e1fef0

Browse files
authored
don't always use default silo when selecting default pool (#3191)
This PR just pulls a small fix to the mock API out of #3033, which I'll be closing shortly. I don't expect this to change much in day-to-day usage of the mock API. In short, when auto-selecting an IP Pool, the mock API currently selects the default pool from the default silo, regardless of what silo you're actually interacting with. To be clear, this is just an issue in the mock backend we use for local development / testing of the console app, not an underlying issue with Omicron. The fix here involves passing in the actual silo the project belongs to, instead of just going with the default silo's default pool.
1 parent be0d7a2 commit 0e1fef0

2 files changed

Lines changed: 11 additions & 11 deletions

File tree

mock-api/msw/db.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,23 +68,23 @@ export const resolvePoolSelector = (
6868
| { pool: string; type: 'explicit' }
6969
| { type: 'auto'; ip_version?: IpVersion | null }
7070
| undefined,
71-
poolType?: IpPoolType
71+
poolType: IpPoolType,
72+
siloId: string = defaultSilo.id
7273
) => {
7374
if (poolSelector?.type === 'explicit') {
7475
return lookup.ipPool({ pool: poolSelector.pool })
7576
}
7677

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

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

86-
// If poolType specified, filter by it
87-
if (poolType && pool.pool_type !== poolType) return false
87+
if (pool.pool_type !== poolType) return false
8888

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

107107
const link = candidateLinks[0]
108108
if (!link) {
109-
const typeStr = poolType ? ` ${poolType}` : ''
110109
const versionStr = poolSelector?.ip_version ? ` ${poolSelector.ip_version}` : ''
111-
throw notFoundErr(`default${typeStr}${versionStr} pool for silo '${defaultSilo.id}'`)
110+
throw notFoundErr(`default ${poolType}${versionStr} pool for silo '${siloId}'`)
112111
}
113112
return lookupById(db.ipPools, link.ip_pool_id)
114113
}

mock-api/msw/handlers.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -395,10 +395,10 @@ export const handlers = makeHandlers({
395395
return true // For mock purposes, just use first unicast pool
396396
})
397397
})
398-
pool = poolWithIp || resolvePoolSelector(undefined, 'unicast')
398+
pool = poolWithIp || resolvePoolSelector(undefined, 'unicast', project.silo_id)
399399
} else {
400400
// type === 'auto'
401-
pool = resolvePoolSelector(addressAllocator.pool_selector, 'unicast')
401+
pool = resolvePoolSelector(addressAllocator.pool_selector, 'unicast', project.silo_id)
402402
ip = getIpFromPool(pool)
403403
}
404404

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

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

779779
db.ephemeralIps.push({
@@ -959,8 +959,9 @@ export const handlers = makeHandlers({
959959
},
960960
instanceEphemeralIpAttach({ path, query: projectParams, body }) {
961961
const instance = lookup.instance({ ...path, ...projectParams })
962+
const instanceProject = lookup.project(projectParams)
962963
// Ephemeral IPs must use unicast pools
963-
const pool = resolvePoolSelector(body.pool_selector, 'unicast')
964+
const pool = resolvePoolSelector(body.pool_selector, 'unicast', instanceProject.silo_id)
964965
const ip = getIpFromPool(pool)
965966

966967
// Validate that external IP version matches primary NIC's IP stack

0 commit comments

Comments
 (0)