Skip to content
This repository was archived by the owner on Mar 22, 2024. It is now read-only.

Commit b158032

Browse files
authored
[E2E] CreateOrUpdate: work on copies of objects (elastic#5571)
1 parent 6f6ba23 commit b158032

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

test/e2e/test/k8s_client.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"k8s.io/client-go/kubernetes/scheme"
2424
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp" // auth on gke
2525
"k8s.io/client-go/tools/remotecommand"
26+
"sigs.k8s.io/controller-runtime/pkg/client"
2627
k8sclient "sigs.k8s.io/controller-runtime/pkg/client"
2728
"sigs.k8s.io/controller-runtime/pkg/client/config"
2829

@@ -350,8 +351,10 @@ func (k K8sClient) CreateOrUpdateSecrets(secrets ...corev1.Secret) error {
350351
return nil
351352
}
352353

353-
func (k K8sClient) CreateOrUpdate(objs ...k8sclient.Object) error {
354+
func (k K8sClient) CreateOrUpdate(objs ...client.Object) error {
354355
for _, obj := range objs {
356+
// create a copy to ensure that the original object is not modified
357+
obj := k8s.DeepCopyObject(obj)
355358
// optimistic creation
356359
err := k.Client.Create(context.Background(), obj)
357360
if err != nil {

0 commit comments

Comments
 (0)