Skip to content

Commit

Permalink
Merge pull request #109 from depot/feat/use-ceph-image-spec
Browse files Browse the repository at this point in the history
feat: begin to use image spec rather than building from volume name
  • Loading branch information
goller authored May 16, 2024
2 parents cd4b64d + 3d02d21 commit f5a6cd2
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 8 deletions.
2 changes: 2 additions & 0 deletions proto/depot/cloud/v3/machine.proto
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ message RegisterMachineResponse {
string key = 3;
// Store at /etc/ceph/ceph.conf
string ceph_conf = 4;
// If the image_spec is set use instead of constructing with the volume_name.
string image_spec = 5;
}
}

Expand Down
8 changes: 8 additions & 0 deletions src/gen/ts/depot/cloud/v3/machine_pb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,13 @@ export class RegisterMachineResponse_Mount_CephVolume extends Message<RegisterMa
*/
cephConf = ''

/**
* If the image_spec is set use instead of constructing with the volume_name.
*
* @generated from field: string image_spec = 5;
*/
imageSpec = ''

constructor(data?: PartialMessage<RegisterMachineResponse_Mount_CephVolume>) {
super()
proto3.util.initPartial(data, this)
Expand All @@ -389,6 +396,7 @@ export class RegisterMachineResponse_Mount_CephVolume extends Message<RegisterMa
{no: 2, name: 'client_name', kind: 'scalar', T: 9 /* ScalarType.STRING */},
{no: 3, name: 'key', kind: 'scalar', T: 9 /* ScalarType.STRING */},
{no: 4, name: 'ceph_conf', kind: 'scalar', T: 9 /* ScalarType.STRING */},
{no: 5, name: 'image_spec', kind: 'scalar', T: 9 /* ScalarType.STRING */},
])

static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): RegisterMachineResponse_Mount_CephVolume {
Expand Down
2 changes: 1 addition & 1 deletion src/tasks/buildkit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ keepBytes = ${cacheSizeBytes}
await fstrim(mount.path)
}
await unmountDevice(mount.path)
await unmapBlockDevice(mount.cephVolume.volumeName)
await unmapBlockDevice(mount.cephVolume.volumeName, mount.cephVolume.imageSpec)
} else {
await unmountDevice(mount.path)
}
Expand Down
2 changes: 1 addition & 1 deletion src/tasks/engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export async function startEngine(message: RegisterMachineResponse, task: Regist
for (const mount of task.mounts) {
if (mount.cephVolume) {
await unmountDevice(mount.path)
await unmapBlockDevice(mount.cephVolume.volumeName)
await unmapBlockDevice(mount.cephVolume.volumeName, mount.cephVolume.imageSpec)
} else {
await unmountDevice(mount.path)
}
Expand Down
15 changes: 9 additions & 6 deletions src/utils/mounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ async function attachCeph(cephVolume: RegisterMachineResponse_Mount_CephVolume):
}
} catch {}

console.log(`Attaching ceph ${volumeName} for ${clientName}`)
// Temporarily continue to use the volumeName until we switch entirely to imageSpec.
const imageSpec = cephVolume.imageSpec ? cephVolume.imageSpec : `rbd/${volumeName}/${volumeName}`

console.log(`Attaching ceph ${imageSpec} for ${clientName}`)
const keyringPath = `/etc/ceph/ceph.${clientName}.keyring`
// NOTE: The API sends the device name as `/dev/rbd/rbd/${volumeName}/${volumeName}`
// This means we ignore the device name returned from mapping.

const imageSpec = `rbd/${volumeName}/${volumeName}`
const keyringPath = `/etc/ceph/ceph.${clientName}.keyring`
await execa('rbd', ['map', imageSpec, '--name', clientName, '--keyring', keyringPath], {stdio: 'inherit'})
console.log(`Mapped ${imageSpec}`)
const device = await getCephDeviceName(cephVolume)
Expand Down Expand Up @@ -202,8 +202,11 @@ async function writeCephConf(clientName: string, cephConf: string, key: string)
await fsp.chmod(keyringPath, 0o600)
}

export async function unmapBlockDevice(volumeName: string) {
const imageSpec = `rbd/${volumeName}/${volumeName}`
export async function unmapBlockDevice(volumeName: string, imageSpec?: string) {
// Temporarily continue to use the volumeName until we switch entirely to imageSpec.
if (!imageSpec) {
imageSpec = `rbd/${volumeName}/${volumeName}`
}
const {exitCode, stderr} = await execa('rbd', ['unmap', imageSpec], {reject: false, stdio: 'inherit'})
console.log(`Unmapped ${imageSpec} with exit code ${exitCode}`)
// 22 means that the device is not mapped a.k.a EINVAL.
Expand Down

0 comments on commit f5a6cd2

Please sign in to comment.