微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

有没有办法结合客户端假 kubernetes 客户端集对控制器运行时操作符进行端到端测试?

如何解决有没有办法结合客户端假 kubernetes 客户端集对控制器运行时操作符进行端到端测试?

我有一个使用 sigs.k8s.io/controller-runtime 用 go 编写的运算符,我正在尝试为它编写端到端测试。测试看起来像:

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 并将标签更新为“已删除”。预计这不会是即时的,因此“然后”步骤轮询直到超时为止。

在系统的其他部分,k8s.io/client-go/kubernetes/fake 可以很好地完成设置和获取标签等操作,但我正在努力寻找将其与控制器运行时测试集成的方法

有没有办法将伪造的客户端集传递给控制器​​运行时管理器? (从我在源代码中的挖掘来看,它似乎使用了一个休息客户端和客户端对象来进行通信......)或者我应该为这个测试设置和更新不同的标签

谢谢!

解决方法

不幸的是,据我所知,推荐的测试管理器的方法是通过 envtest

我尝试通过 ClientBuilder 使用 fake client,但这似乎不起作用。

但是,您应该能够以某种方式构建您的代码,即 e2e 测试仅测试控制器循环正在运行、领导者选举正在发生等。控制器循环逻辑本身可以使用 fake client 进行测试,通过传递无论您通常使用 manager.GetClient() 传递什么。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。