python - 在 Kubernetes API 客户端操作中为 Python 试运行
问题描述
我一直在编写一些需要在Kubernetes中使用Python Client官方库执行的操作。
一个例子是更新标签值的服务补丁:
# Code to instantiate the api object.
config.load_kube_config()
self.v1 = client.CoreV1Api()
# Code to call the patch function
def patch_namespaced_service(self, name, namespace, body, dry_run=True):
logging.debug(body)
response = self.v1.patch_namespaced_service(name, namespace, body, dry_run=dry_run)
logging.info("Service patched. status='%s'" % str(response.status))
它就像一个魅力,但该dry_run
选项永远不会应用,无论我发送什么值,它总是执行补丁。
这是记录dry_run
参数的源代码:
def patch_namespaced_service(self, name, namespace, body, **kwargs): # noqa: E501
"""patch_namespaced_service # noqa: E501
partially update the specified Service # noqa: E501
This method makes a synchronous HTTP request by default. To make an
asynchronous HTTP request, please pass async_req=True
>>> thread = api.patch_namespaced_service(name, namespace, body, async_req=True)
>>> result = thread.get()
:param async_req bool
:param str name: name of the Service (required)
:param str namespace: object name and auth scope, such as for teams and projects (required)
:param UNKNOWN_BASE_TYPE body: (required)
:param str pretty: If 'true', then the output is pretty printed.
:param str dry_run: When present, indicates that modifications should not be persisted. An invalid or unrecognized dryRun directive will result in an error response and no further processing of the request. Valid values are: - All: all dry run stages will be processed
:param str field_manager: fieldManager is a name associated with the actor or entity that is making these changes. The value must be less than or 128 characters long, and only contain printable characters, as defined by https://golang.org/pkg/unicode/#IsPrint. This field is required for apply requests (application/apply-patch) but optional for non-apply patch types (JsonPatch, MergePatch, StrategicMergePatch).
:param bool force: Force is going to \"force\" Apply requests. It means user will re-acquire conflicting fields owned by other people. Force flag must be unset for non-apply patch requests.
:return: V1Service
If the method is called asynchronously,
returns the request thread.
"""
我想评论这部分:
Valid values are: - All: all dry run stages will be processed
dry_run
在他们用作列表
的文档的其他部分: https ://github.com/kubernetes-client/python/blob/master/kubernetes/docs/V1DeleteOptions.md
但是我试过了,dry_run=True
没有成功。dry_run="All"
dry_run=["All"]
有谁知道如何使用 a 执行此操作dry_run
?
解决方案
推荐阅读
- java - 将一个庞大的循环分解为多种方法?
- python - 如何在正则表达式的括号中获取分号
- python - 在 Shopify 中按变体 SKU 更新库存
- database - 无论我使用 --dbpath,MongoDB 都在访问相同的数据,这正常吗?
- sql - Azure SQLDW Translate 在 Informatica SQL Query 中无法识别,但可以在 SSMS 中使用
- android - 如何将抽屉连接到颤动的动画图标按钮?
- javascript - 我怎样才能创建一个带有框阴影的箭头弹出框?
- powershell - PowerShell 和 TFS | 使用本地路径与使用服务器路径的 PowerShell ISE 从 TFS 获取更改集列表
- c - static const int 和 static int const 有什么区别?
- python - 根据索引范围插入列值