在Kubernetes的发现接口中,`discoveryfake`是如何定义的?

huangapple go评论79阅读模式
英文:

Where is the discoveryfake defined in k8s discovery interface?

问题

在我阅读关于如何在k8s上使用虚假客户端进行测试的这个链接时,我注意到了这个函数。根据我的理解,它将一个虚假的服务器版本分配给虚假的k8s集群。

k8s.clientset.Discovery().(*discoveryfake.FakeDiscovery).FakedServerVersion = &version.Info{
    Major: expectedMajor,
    Minor: expectedMinor,
}

我正在尝试理解这个 *discoveryfake.FakeDiscovery 代码的含义。k8s.clientset.Discovery() 返回 DiscoveryInterface在这里定义),但我找不到 *discoveryfake 字段。

Discovery().(*discoveryfake.FakeDiscovery) 是什么意思?

英文:

While I'm reading how to test on k8s with the fake client on this link, I noticed this function, which, IIUC, assigns a faked server version to the faked k8s cluster.

k8s.clientset.Discovery().(*discoveryfake.FakeDiscovery).FakedServerVersion = &version.Info{
                    Major: expectedMajor,
                    Minor: expectedMinor,
            }

I'm trying to understand what this *discoveryfake.FakeDiscovery code means.
k8s.clientset.Discovery() returns DiscoveryInterface (defined here), but I cannot find *discoveryfake field.

What does Discovery().(*discoveryfake.FakeDiscovery) mean?

答案1

得分: 1

这是一个类型断言,正如@peter在评论中建议的那样。

英文:

It's a type assertion, as @peter suggested in the comment.

huangapple
  • 本文由 发表于 2023年3月14日 02:47:32
  • 转载请务必保留本文链接:https://go.coder-hub.com/75725826.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定