有没有办法结合客户端假 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() 传递什么。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...