Skip to content

Commit 9965f5a

Browse files
authored
Merge pull request #3390 from aerfio/aerfio/client-apply-docs
📖 Update client.Apply example
2 parents 8539590 + ea4566f commit 9965f5a

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

pkg/client/example_test.go

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import (
2525
corev1 "k8s.io/api/core/v1"
2626
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2727
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
28-
"k8s.io/apimachinery/pkg/runtime"
2928
"k8s.io/apimachinery/pkg/runtime/schema"
3029
"k8s.io/apimachinery/pkg/types"
3130
corev1ac "k8s.io/client-go/applyconfigurations/core/v1"
@@ -218,10 +217,23 @@ func ExampleClient_patch() {
218217
func ExampleClient_apply() {
219218
// Using a typed object.
220219
configMap := corev1ac.ConfigMap("name", "namespace").WithData(map[string]string{"key": "value"})
221-
// c is a created client.
222-
u := &unstructured.Unstructured{}
223-
u.Object, _ = runtime.DefaultUnstructuredConverter.ToUnstructured(configMap)
224-
_ = c.Patch(context.Background(), u, client.Apply, client.ForceOwnership, client.FieldOwner("field-owner"))
220+
_ = c.Apply(context.Background(), configMap)
221+
222+
// Using a unstructured object.
223+
u := &unstructured.Unstructured{
224+
Object: map[string]any{
225+
"apiVersion": "v1",
226+
"kind": "ConfigMap",
227+
"metadata": map[string]any{
228+
"name": "name",
229+
"namespace": "namespace",
230+
},
231+
"data": map[string]any{
232+
"key": "value",
233+
},
234+
},
235+
}
236+
_ = c.Apply(context.Background(), client.ApplyConfigurationFromUnstructured(u))
225237
}
226238

227239
// This example shows how to use the client with typed and unstructured objects to patch objects' status.

0 commit comments

Comments
 (0)