MCPcopy
hub / github.com/kubernetes-sigs/controller-runtime / ExampleClient_update

Function ExampleClient_update

pkg/client/example_test.go:177–201  ·  view source on GitHub ↗

This example shows how to use the client with typed and unstructured objects to update objects.

()

Source from the content-addressed store, hash-verified

175
176// This example shows how to use the client with typed and unstructured objects to update objects.
177func ExampleClient_update() {
178 // Using a typed object.
179 pod := &corev1.Pod{}
180 // c is a created client.
181 _ = c.Get(context.Background(), client.ObjectKey{
182 Namespace: "namespace",
183 Name: "name",
184 }, pod)
185 controllerutil.AddFinalizer(pod, "new-finalizer")
186 _ = c.Update(context.Background(), pod)
187
188 // Using a unstructured object.
189 u := &unstructured.Unstructured{}
190 u.SetGroupVersionKind(schema.GroupVersionKind{
191 Group: "apps",
192 Kind: "Deployment",
193 Version: "v1",
194 })
195 _ = c.Get(context.Background(), client.ObjectKey{
196 Namespace: "namespace",
197 Name: "name",
198 }, u)
199 controllerutil.AddFinalizer(u, "new-finalizer")
200 _ = c.Update(context.Background(), u)
201}
202
203// This example shows how to use the client with typed and unstructured objects to patch objects.
204func ExampleClient_patch() {

Callers

nothing calls this directly

Calls 4

AddFinalizerFunction · 0.92
GetMethod · 0.65
UpdateMethod · 0.65
SetGroupVersionKindMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…