【问题标题】:Is there a way to end-to-end test a controller-runtime operator in conjunction with a client-go fake kubernetes clientset?有没有一种方法可以端到端测试控制器运行时操作员和客户端假 kubernetes 客户端集?
【发布时间】: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


    【解决方案1】:

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

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

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

    【讨论】:

      猜你喜欢
      • 2018-07-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-09
      • 2017-01-08
      • 2019-10-25
      • 2023-03-25
      • 2017-12-23
      相关资源
      最近更新 更多