-2

我希望将新规范与实际状态进行比较,看看我是否允许进行一些更改(比如升级)

我从 etcd 操作员那里找到了这个例子,我想知道是否有更常见的方法来检索我的 CRD (statefulset) 的某些资源:

podList, err := c.config.KubeCli.Core().Pods(c.cluster.Namespace).List(k8sutil.ClusterListOpt(c.cluster.Name))

示例来自:https ://github.com/coreos/etcd-operator/blob/534a00a970975a66b15e2ea3cd90eb6d5104c71b/pkg/cluster/cluster.go#L285

4

1 回答 1

0

解决方案是使用 Get 函数: https ://github.com/operator-framework/operator-sdk/blob/master/pkg/sdk/query.go

示例(https://github.com/operator-framework/operator-sdk/blob/master/doc/design/milestone-0.0.2/query-api.md):

d := &apps_v1.Deployment{
    TypeMeta: meta_v1.TypeMeta{
        Kind:       "Deployment",
        APIVersion: "apps/v1",
    }
    ObjectMeta: metav_1.ObjectMeta{
        Name:      "example",
        Namespace: "default",
    }
}
// Get with default options
err := sdk.Get(d)
// Get with custom options 
o := &meta_v1.GetOptions{ResourceVersion: "0"}
err := sdk.Get(d, sdk.WithGetOptions(o))
于 2018-07-04T11:08:27.680 回答