bcs-hook-operator是蓝鲸自定义workload扩展的一部分,它的主要功能用来处理应用扩缩容和发布更新过程中的 各种 hook操作。主要包含两个 crd:HookTemplate 和 HookRun。
我们在深刻挖掘业务需求和调研解决方案后,在 kubernetes 层面抽象出了一个通用的 operator: bcs-hook-operator。 bcs-hook-operator 主要职责是根据 hook 模板执行 hook 操作并记录 hook 的状态,GameDeployment 或 GameStatefulSet watch hook 的最终状态,根据 hook 结果来决定下一步执行何种操作。
GameDeployment/GameStatefulSet 与 bcs-hook-operator 在应用发布过程中使用 hook 时的交互架构图:
helm chart信息位于bk-bcs/install/helm/bcs-hook-operator
helm upgrade bcs-hook-operator helm/bcs-hook-operator -n bcs-system --install
下面是一个 HookTemplate 的定义:
apiVersion: tkex.tencent.com/v1alpha1
kind: HookTemplate
metadata:
name: test
spec:
args:
- name: service-name
value: test-gamedeployment-svc.default.svc.cluster.local
- name: PodName
metrics:
- name: webtest
count: 2
interval: 60s
failureLimit: 0
successCondition: "asInt(result) < 30"
provider:
web:
url: http://1.1.1.1:9091
jsonPath: "{$.age}"
以上面这个HookTemplate为例,定义了一个Webhook类型的metric,url地址为 http://1.1.1.1:9091,web调用的结果返回示例如下:
$ curl http://1.1.1.1:9091
{"name":"bryan","male":"yes","age":45}
jsonPath 定义为 "{$.age}",表示 result 的值取返回 json 中的 age 字段,successCondition 为 "asInt(result) < 30", 表示如果返回的 age小于 30,那么这次 hook 调用的结果就是符合预期的。
hookrun-controller 通过 HookRun crd 的定义来实际维护和控制一个 HookRun 的状态和生命周期。
下面是 HookRun controller 创建和维护的一个 HookRun 的示例:
apiVersion: tkex.tencent.com/v1alpha1
kind: HookRun
metadata:
creationTimestamp: "2020-11-09T10:08:49Z"
generation: 2
labels:
gamedeployment-revision: test-gamedeployment-67864c6f65
gamedeployment-type: Step
step-index: "4"
name: test-gamedeployment-67864c6f65-4-test
namespace: default
ownerReferences:
- apiVersion: tkex.tencent.com/v1alpha1
blockOwnerDeletion: true
controller: true
kind: GameDeployment
name: test-gamedeployment
uid: 08db1c6b-4b0a-4fda-86c4-04327f9a788f
resourceVersion: "40202398"
selfLink: /apis/tkex.tencent.com/v1alpha1/namespaces/default/hookruns/test-gamedeployment-67864c6f65-4-test
uid: b3334c79-1d93-4b60-bf88-6583ee3dbfe4
spec:
metrics:
- name: webtest
provider:
web:
jsonPath: '{$.age}'
url: http://1.1.1.1:9091
successCondition: asInt(result) < 30
terminate: true
status:
metricResults:
- count: 1
failed: 1
measurements:
- finishedAt: "2020-11-09T10:08:49Z"
phase: Failed
startedAt: "2020-11-09T10:08:49Z"
value: "32"
name: webtest
phase: Failed
phase: Failed
startedAt: "2020-11-09T10:08:49Z"
status.phase 定义了该 HookRun 最后的运行状态。
HookRun 是根据模板 HookTemplate 创建的一个实际运行的 hook CRD,bcs-hook-operator 监测并控制 HookRun 的运行状态和生命周期,根据其 metrics 中的定义来执行 hook 操作,并实时记录 hook 调用的结果。
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。