k8s Operator SDK - how to get actual CRD state

7/3/2018

I wish to compare the new spec to the actual state to see if I allow some change (say upgrade)

I found this example from etcd operator and i was wondering if there are more common ways to retrieve some resource of my CRD (statefulset) :

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

exmaple from: https://github.com/coreos/etcd-operator/blob/534a00a970975a66b15e2ea3cd90eb6d5104c71b/pkg/cluster/cluster.go#L285

-- Mika R
controller
kubernetes
kubernetes-custom-resources

1 Answer

7/4/2018

solution is using Get function: https://github.com/operator-framework/operator-sdk/blob/master/pkg/sdk/query.go

example (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))
-- Mika R
Source: StackOverflow