mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-21 19:01:49 +00:00
Drop managed fields entries with unknown fields
This is aligned to the behaviour of server-side apply on main resources.
This commit is contained in:
parent
8e4b5c849b
commit
c10dd884c4
@ -68,7 +68,12 @@ func (h *ScaleHandler) ToSubresource() ([]metav1.ManagedFieldsEntry, error) {
|
|||||||
f := fieldpath.ManagedFields{}
|
f := fieldpath.ManagedFields{}
|
||||||
t := map[string]*metav1.Time{}
|
t := map[string]*metav1.Time{}
|
||||||
for manager, versionedSet := range managed.Fields() {
|
for manager, versionedSet := range managed.Fields() {
|
||||||
path := h.mappings[string(versionedSet.APIVersion())]
|
path, ok := h.mappings[string(versionedSet.APIVersion())]
|
||||||
|
// Drop the field if the APIVersion of the managed field is unknown
|
||||||
|
if !ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
if versionedSet.Set().Has(path) {
|
if versionedSet.Set().Has(path) {
|
||||||
newVersionedSet := fieldpath.NewVersionedSet(
|
newVersionedSet := fieldpath.NewVersionedSet(
|
||||||
fieldpath.NewSet(replicasPathInScale),
|
fieldpath.NewSet(replicasPathInScale),
|
||||||
@ -104,7 +109,11 @@ func (h *ScaleHandler) ToParent(scaleEntries []metav1.ManagedFieldsEntry) ([]met
|
|||||||
|
|
||||||
for manager, versionedSet := range parentFields {
|
for manager, versionedSet := range parentFields {
|
||||||
// Get the main resource "replicas" path
|
// Get the main resource "replicas" path
|
||||||
path := h.mappings[string(versionedSet.APIVersion())]
|
path, ok := h.mappings[string(versionedSet.APIVersion())]
|
||||||
|
// Drop the field if the APIVersion of the managed field is unknown
|
||||||
|
if !ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
// If the parent entry does not have the replicas path, just keep it as it is
|
// If the parent entry does not have the replicas path, just keep it as it is
|
||||||
if !versionedSet.Set().Has(path) {
|
if !versionedSet.Set().Has(path) {
|
||||||
|
@ -117,6 +117,19 @@ func TestTransformManagedFieldsToSubresource(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
desc: "drops fields if the api version is unknown",
|
||||||
|
input: []metav1.ManagedFieldsEntry{
|
||||||
|
{
|
||||||
|
Manager: "manager-1",
|
||||||
|
Operation: metav1.ManagedFieldsOperationApply,
|
||||||
|
APIVersion: "apps/v10",
|
||||||
|
FieldsType: "FieldsV1",
|
||||||
|
FieldsV1: &metav1.FieldsV1{Raw: []byte(`{"f:spec":{"f:replicas":{}}}`)},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expected: nil,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
@ -564,6 +577,43 @@ func TestTransformingManagedFieldsToParent(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
desc: "drops other fields if the api version is unknown",
|
||||||
|
parent: []metav1.ManagedFieldsEntry{
|
||||||
|
{
|
||||||
|
Manager: "test",
|
||||||
|
Operation: metav1.ManagedFieldsOperationApply,
|
||||||
|
APIVersion: "apps/v1",
|
||||||
|
FieldsType: "FieldsV1",
|
||||||
|
FieldsV1: &metav1.FieldsV1{Raw: []byte(`{"f:spec":{"f:replicas":{}}}`)},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Manager: "another-manager",
|
||||||
|
Operation: metav1.ManagedFieldsOperationApply,
|
||||||
|
APIVersion: "apps/v10",
|
||||||
|
FieldsType: "FieldsV1",
|
||||||
|
FieldsV1: &metav1.FieldsV1{Raw: []byte(`{"f:spec":{"f:selector":{}}}`)},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
subresource: []metav1.ManagedFieldsEntry{
|
||||||
|
{
|
||||||
|
Manager: "scale",
|
||||||
|
Operation: metav1.ManagedFieldsOperationUpdate,
|
||||||
|
APIVersion: "autoscaling/v1",
|
||||||
|
FieldsType: "FieldsV1",
|
||||||
|
FieldsV1: &metav1.FieldsV1{Raw: []byte(`{"f:spec":{"f:replicas":{}}}`)},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expected: []metav1.ManagedFieldsEntry{
|
||||||
|
{
|
||||||
|
Manager: "scale",
|
||||||
|
Operation: metav1.ManagedFieldsOperationUpdate,
|
||||||
|
APIVersion: "apps/v1",
|
||||||
|
FieldsType: "FieldsV1",
|
||||||
|
FieldsV1: &metav1.FieldsV1{Raw: []byte(`{"f:spec":{"f:replicas":{}}}`)},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
|
Loading…
Reference in New Issue
Block a user