MCPcopy Create free account
hub / github.com/cloudnative-pg/cloudnative-pg / NewControllerRuntimeClient

Function NewControllerRuntimeClient

pkg/management/client.go:73–102  ·  view source on GitHub ↗

NewControllerRuntimeClient creates a new typed K8s client where the PostgreSQL CRD and some basic k8s resources have been already registered. While using the typed client you may encounter an error like this: no matches for kind "X" in version "Y". This means that the runtime.Object is missing and

()

Source from the content-addressed store, hash-verified

71//
72// This means that the runtime.Object is missing and needs to registered in the client.
73func NewControllerRuntimeClient() (client.WithWatch, error) {
74 config, err := rest.InClusterConfig()
75 if err != nil {
76 return nil, err
77 }
78
79 mapper := meta.NewDefaultRESTMapper([]schema.GroupVersion{apiv1.SchemeGroupVersion})
80 // add here any resource that need to be registered.
81 objectsToRegister := []runtime.Object{
82 // custom resources
83 &apiv1.Cluster{}, &apiv1.Backup{}, &apiv1.Pooler{}, &apiv1.ImageCatalog{}, &apiv1.ClusterImageCatalog{},
84 // k8s resources needed for the typedClient to work properly
85 &corev1.ConfigMap{}, &corev1.Secret{},
86 }
87
88 // we register the resources
89 for _, obj := range objectsToRegister {
90 gvk, err := apiutil.GVKForObject(obj, Scheme)
91 if err != nil {
92 return nil, err
93 }
94
95 mapper.Add(gvk, meta.RESTScopeNamespace)
96 }
97
98 return client.NewWithWatch(config, client.Options{
99 Scheme: Scheme,
100 Mapper: mapper,
101 })
102}
103
104// newClientGoClient creates a new client-go kubernetes interface.
105// It is used only to create event recorders, as controller-runtime do.

Callers 8

BootstrapMethod · 0.92
NewRemoteWebServerFunction · 0.92
NewPgBouncerReconcilerFunction · 0.92
NewCmdFunction · 0.92
joinSubCommandFunction · 0.92
upgradeSubCommandMethod · 0.92
statusSubCommandFunction · 0.92
WaitForGetClusterFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected