Skip to content

Deleting external subnets is overly-complicated #9797

@bnaecker

Description

@bnaecker

The code for deleting external subnets looks like this:

pub async fn delete_external_subnet(
&self,
opctx: &OpContext,
authz_subnet: &authz::ExternalSubnet,
) -> DeleteResult {
opctx.authorize(authz::Action::Delete, authz_subnet).await?;
let id = authz_subnet.id().into_untyped_uuid();
delete_external_subnet_query(&id)
.execute_async(&*self.pool_connection_authorized(opctx).await?)
.await
.map_err(decode_delete_external_subnet_error)
.and_then(|count| {
if count == 0 {
Err(Error::not_found_by_id(
ResourceType::ExternalSubnet,
&id,
))
} else {
Ok(())
}
})
}

That delegates to a custom query, which checks that the subnet isn't attached to an instance before deleting it. This is much more complicated than in needs to be. I forgot about the UpdateAndCheck trait we have for exactly this kind of conditional delete. The code is correct, but we should just use the standard mechanism.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions