in src/Azure.Deployments.Extensibility.Extensions.Kubernetes/KubernetesExtension.cs [93:128]
public async Task<IResult> GetResourceAsync(HttpContext httpContext, ResourceReference resourceReference, CancellationToken cancellationToken)
{
this.resourceReferenceValidator.ValidateAndThrow(resourceReference);
var groupVersionKind = ModelMapper.MapToGroupVersionKind(resourceReference.Type, resourceReference.ApiVersion);
var identifiers = ModelMapper.MapToK8sObjectIdentifiers(resourceReference.Identifiers);
using var client = await this.k8sClientFactory.CreateAsync(resourceReference.Config);
// Do config ID checksum validation if one is supplied.
if (resourceReference.ConfigId is not null && !TryMatchConfigurationId(resourceReference.ConfigId, CalculateConfigId(client), out var configIdErrorResult))
{
return configIdErrorResult;
}
var api = await new K8sApiDiscovery(client).FindApiAsync(groupVersionKind, cancellationToken);
if (await api.GetObjectAsync(identifiers, cancellationToken) is { } k8sObject)
{
var configId = CalculateConfigId(client);
return Results.Ok(ModelMapper.MapToResource(identifiers, k8sObject, configId));
}
var @namespace = api.Namespaced ? identifiers.Namespace ?? client.DefaultNamespace : null;
return Results.NotFound(new ErrorData
{
Error = new()
{
Code = "ObjectNotFound",
Message = @namespace is null
? $"The referenced Kubernetes object (GroupVersionKind={groupVersionKind}, Name={identifiers.Name}) was not found."
: $"The referenced Kubernetes object (GroupVersionKind={groupVersionKind}, Name={identifiers.Name}, Namespace={@namespace}) was not found.",
},
});
}