This documentation is for a release that is no longer maintained
See documentation for the latest supported version 3 or the latest supported version 4.5.4.4. 使用 operator_sdk.util Ansible 集合来管理自定义资源状态
基于 Ansible 的 Operator 会自动将上一次 Ansible 运行的一般信息更新到自定义资源 (CR) status
子资源中。其中包括成功和失败任务的数量以及相关的错误消息,如下所示:
基于 Ansible 的 Operator 还支持 Operator 作者通过 k8s_status
Ansible 模块提供自定义状态值,该模块包含在 operator_sdk.util
集中。作者可以根据需要使用任意键值对从 Ansible 内部更新 status
。
基于 Ansible 的 Operator 默认始终包含如上所示的通用 Ansible 运行输出。如果不希望您的应用程序使用 Ansible 输出来更新状态,您可以通过应用程序来手动跟踪状态。
流程
要通过应用程序手动跟踪 CR 状态,请更新
watches.yaml
文件,并将manageStatus
字段设置为false
:- version: v1 group: api.example.com kind: Test1 role: Test1 manageStatus: false
- version: v1 group: api.example.com kind: Test1 role: Test1 manageStatus: false
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 使用
operator_sdk.util.k8s_status
Ansible 模块来更新子资源。例如:要使用键test1
和值test2
更新,可使用operator_sdk.util
,如下所示:Copy to Clipboard Copied! Toggle word wrap Toggle overflow 集合也可以在角色的
meta/main.yml
中声明,用于新构建的 Ansible Operator:collections: - operator_sdk.util
collections: - operator_sdk.util
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 在角色 meta 中声明集合可让您直接调用
k8s_status
模块:k8s_status: <snip> status: test1: test2
k8s_status: <snip> status: test1: test2
Copy to Clipboard Copied! Toggle word wrap Toggle overflow