.net - 在 C#-client 中识别 kubernetes 部署规范中的错误字段
问题描述
我正在尝试使用 Kubernetes 的 C#-client 定义部署规范。我的规范字段的值是由其他一些应用程序产生的。因此,部署有时会失败并且我收到Unprocessable entity
(Microsoft.Rest.HttpOperationException) 错误。但是,很难确定哪个字段会导致 Unprocessable entity 错误。
有人可以告诉我如何识别错误的字段吗?
这是跟踪:
Microsoft.Rest.HttpOperationException: Operation returned an invalid status code 'UnprocessableEntity'
at k8s.Kubernetes.CreateNamespacedDeploymentWithHttpMessagesAsync(V1Deployment body, String namespaceParameter, String dryRun, String fieldManager, String pretty, Dictionary`2 customHeaders, CancellationToken cancellationToken)
at k8s.KubernetesExtensions.CreateNamespacedDeploymentAsync(IKubernetes operations, V1Deployment body, String namespaceParameter, String dryRun, String fieldManager, String pretty, CancellationToken cancellationToken)
at k8s.KubernetesExtensions.CreateNamespacedDeployment(IKubernetes operations, V1Deployment body, String namespaceParameter, String dryRun, String fieldManager, String pretty)
解决方案
通过打印出 Microsoft.Rest.HttpOperationException 的 Response.Content 字段,我能够得到更详细的错误。
try
{
// Code for deployment
}
catch(Microsoft.Rest.HttpOperationException e)
{
Console.WriteLine(e.Response.Content);
}
推荐阅读
- python - Python:如何在运行for语句后不仅打印最终值,还打印中间输出?
- sql-server - 如何使用具有相同 ID 的列来使用东西
- udp - UDP - 是否可以在一个接收呼叫中接收多条消息?
- angular - 如何在两个数据组件之间进行数据绑定?
- c++ - Factorial-c++ 我想以不同的方式打印
- javascript - 将值从地图传递到状态
- javascript - javascript说array.length是未定义的,但不是数组
- javascript - 点击后圆圈覆盖整个屏幕
- arrays - 类型“任何”没有下标成员错误 Json
- regex - 使用 Python 2.7.13 匹配字符串末尾的正则表达式