Compiler Warning ASPIRECOMPUTE002
Kubernetes persistent volume APIs are for evaluation purposes only and are subject to change or removal in future updates. Suppress this diagnostic to proceed.
This diagnostic warning is reported when using the experimental Kubernetes persistent volume APIs: KubernetesPersistentVolumeExtensions, KubernetesPersistentVolumeResource, PersistentVolumeAccessMode, and AzureKubernetesPersistentVolumeExtensions.
Endpoint-mapping contracts
Section titled “Endpoint-mapping contracts”GetHostAddressExpression returns a ReferenceExpression for the host only, without scheme, port, or path. It isn’t a full URL. GetEndpointPropertyExpression composes the host, scheme, and port expressions by default, and compute environments can override it with platform-specific mappings.
The default GetHostAddressExpression implementation throws NotImplementedException, so environments that don’t provide host mapping (for example, AzureKubernetesEnvironmentResource) still inherit that behavior.
var builder = DistributedApplication.CreateBuilder(args);
var environment = builder.AddDockerComposeEnvironment("env");var api = builder.AddContainer("api", "nginx") .WithHttpEndpoint(targetPort: 80);
IComputeEnvironmentResource compute = environment.Resource;var endpoint = api.GetEndpoint("http");ReferenceExpression host = compute.GetHostAddressExpression(endpoint);ReferenceExpression url = compute.GetEndpointPropertyExpression( endpoint.Property(EndpointProperty.Url));To suppress this warning
Section titled “To suppress this warning”Suppress the warning with either of the following methods:
-
Set the severity of the rule in the .editorconfig file.
.editorconfig [*.{cs,vb}]dotnet_diagnostic.ASPIRECOMPUTE002.severity = noneFor more information about editor config files, see Configuration files for code analysis rules.
-
Add the following
PropertyGroupto your project file:C# project file <PropertyGroup><NoWarn>$(NoWarn);ASPIRECOMPUTE002</NoWarn></PropertyGroup> -
Suppress in code with the
#pragma warning disable ASPIRECOMPUTE002directive:Suppressing the warning #pragma warning disable ASPIRECOMPUTE002var k8s = builder.AddKubernetesEnvironment("k8s");var data = k8s.AddPersistentVolume("data").WithAccessMode(PersistentVolumeAccessMode.ReadWriteOnce);#pragma warning restore ASPIRECOMPUTE002
See also
Section titled “See also”- ASPIRECOMPUTE001 — Compute environment resource creation
- ASPIRECOMPUTE003 — Container registry resources