【发布时间】:2021-07-11 06:32:50
【问题描述】:
我有一个使用sigs.k8s.io/controller-runtime 编写的运算符,我正在尝试为其编写端到端测试。测试看起来像:
Feature: Operator deletes pods in a namespace when asked
Scenario: Operator deletes pods on label updated to deletionRequested
Given the target K8s cluster has got a namespace called "a525bb67-fda5-42cd-84e4-5d604e9f0156"
And the namespace "a525bb67-fda5-42cd-84e4-5d604e9f0156" has got the following labels
| state | active |
And the namespace "a525bb67-fda5-42cd-84e4-5d604e9f0156" has got the following releases installed with Helm
| my-service | 1.1.1 | https://example.com/artifactory/helm-test |
And operator is running
When the state label of "a525bb67-fda5-42cd-84e4-5d604e9f0156" is updated to "toBeDeleted"
Then the namespace "a525bb67-fda5-42cd-84e4-5d604e9f0156" has the following labels
| state | deleted |
And the namespace "a525bb67-fda5-42cd-84e4-5d604e9f0156" has no releases installed with Helm
发生的情况是标签更新为“toBeDeleted”的事件,操作员根据定义的谓词获取该事件。然后操作员将清除 pod 并将标签更新为“已删除”。预计这不会是即时的,因此“Then”步骤会轮询直到 true 并超时。
在系统的其他部分,k8s.io/client-go/kubernetes/fake 可以很好地完成设置和获取标签等操作,但我正在努力寻找一种将其与控制器运行时测试集成的方法。
有没有办法将假客户端传递给控制器运行时管理器? (从我对源代码的挖掘来看,它似乎使用了一个休息客户端和客户端对象来进行通信......)或者我应该为这个测试设置和更新标签吗?
谢谢!
【问题讨论】:
标签: go kubernetes kubernetes-helm acceptance-testing client-go