in src/Azure.Deployments.Extensibility.Extensions.Kubernetes/KubernetesExtension.cs [130:163]
public async Task<IResult> DeleteResourceAsync(HttpContext httpContext, ResourceReference resourceReference, CancellationToken cancellationToken)
{
this.resourceReferenceValidator.ValidateAndThrow(resourceReference);
var identifiers = ModelMapper.MapToK8sObjectIdentifiers(resourceReference.Identifiers);
// This can only be invoked by Deployment Stacks. ConfigId must be preserved
// to ensure that the operation is performed on the correct cluster.
if (resourceReference.ConfigId is null)
{
return Results.BadRequest(new ErrorData
{
Error = new()
{
Code = "InvalidConfigId",
Message = "The resource reference is missing a config ID.",
},
});
}
var groupVersionKind = ModelMapper.MapToGroupVersionKind(resourceReference.Type, resourceReference.ApiVersion);
using var client = await this.k8sClientFactory.CreateAsync(resourceReference.Config);
if (!TryMatchConfigurationId(resourceReference.ConfigId, CalculateConfigId(client), out var configIdErrorResult))
{
return configIdErrorResult;
}
var api = await new K8sApiDiscovery(client).FindApiAsync(groupVersionKind, cancellationToken);
await api.DeleteObjectAsync(identifiers, cancellationToken);
return Results.NoContent();
}