FieldManagedObjectTracker: Fix to work with unstructured

Prior to this patch, this fails because the skipnonappliedfieldmanager
uses the `objectcreater` (aka `*runtime.Scheme`) to create a new object
for which it never sets the GVK. In the case of
`*unstructured.Unstructured`, the GVK can not be derived from the object
itself so the operation would subsequently fail [here][0] with an
```
Object 'Kind' is missing in 'unstructured object has no kind'
```

error. Fix this by explicitly setting the GVK in case of unstructured.

[0]: 02eb7d424a/staging/src/k8s.io/apimachinery/pkg/util/managedfields/internal/structuredmerge.go (L98)

Kubernetes-commit: dbdd6a3b4358d91a064de9c0f01d3050e606d553
This commit is contained in:
Alvaro Aleman
2025-05-30 15:30:33 -04:00
committed by Kubernetes Publisher
parent e9ca982cec
commit 81ecec406a
2 changed files with 59 additions and 2 deletions

View File

@@ -19,11 +19,12 @@ package testing
import (
"fmt"
"reflect"
"sigs.k8s.io/yaml"
"sort"
"strings"
"sync"
"sigs.k8s.io/yaml"
jsonpatch "gopkg.in/evanphx/json-patch.v4"
apierrors "k8s.io/apimachinery/pkg/api/errors"
@@ -702,7 +703,6 @@ func (t *managedFieldObjectTracker) Update(gvr schema.GroupVersionResource, obj
}
gvk, err := t.mapper().KindFor(gvr)
if err != nil {
println("kindfor")
return err
}
mgr, err := t.fieldManagerFor(gvk)