mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 03:41:45 +00:00
Do not reset managedFields in status update strategy
This commit is contained in:
parent
94cb60e0e8
commit
dfe1703ffa
@ -94,7 +94,12 @@ var StatusStrategy = flowSchemaStatusStrategy{Strategy}
|
|||||||
func (flowSchemaStatusStrategy) PrepareForUpdate(ctx context.Context, obj, old runtime.Object) {
|
func (flowSchemaStatusStrategy) PrepareForUpdate(ctx context.Context, obj, old runtime.Object) {
|
||||||
newFlowSchema := obj.(*flowcontrol.FlowSchema)
|
newFlowSchema := obj.(*flowcontrol.FlowSchema)
|
||||||
oldFlowSchema := old.(*flowcontrol.FlowSchema)
|
oldFlowSchema := old.(*flowcontrol.FlowSchema)
|
||||||
|
|
||||||
|
// managedFields must be preserved since it's been modified to
|
||||||
|
// track changed fields in the status update.
|
||||||
|
managedFields := newFlowSchema.ManagedFields
|
||||||
newFlowSchema.ObjectMeta = oldFlowSchema.ObjectMeta
|
newFlowSchema.ObjectMeta = oldFlowSchema.ObjectMeta
|
||||||
|
newFlowSchema.ManagedFields = managedFields
|
||||||
newFlowSchema.Spec = oldFlowSchema.Spec
|
newFlowSchema.Spec = oldFlowSchema.Spec
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,7 +94,12 @@ var StatusStrategy = priorityLevelConfigurationStatusStrategy{Strategy}
|
|||||||
func (priorityLevelConfigurationStatusStrategy) PrepareForUpdate(ctx context.Context, obj, old runtime.Object) {
|
func (priorityLevelConfigurationStatusStrategy) PrepareForUpdate(ctx context.Context, obj, old runtime.Object) {
|
||||||
newPriorityLevelConfiguration := obj.(*flowcontrol.PriorityLevelConfiguration)
|
newPriorityLevelConfiguration := obj.(*flowcontrol.PriorityLevelConfiguration)
|
||||||
oldPriorityLevelConfiguration := old.(*flowcontrol.PriorityLevelConfiguration)
|
oldPriorityLevelConfiguration := old.(*flowcontrol.PriorityLevelConfiguration)
|
||||||
|
|
||||||
|
// managedFields must be preserved since it's been modified to
|
||||||
|
// track changed fields in the status update.
|
||||||
|
managedFields := newPriorityLevelConfiguration.ManagedFields
|
||||||
newPriorityLevelConfiguration.ObjectMeta = oldPriorityLevelConfiguration.ObjectMeta
|
newPriorityLevelConfiguration.ObjectMeta = oldPriorityLevelConfiguration.ObjectMeta
|
||||||
|
newPriorityLevelConfiguration.ManagedFields = managedFields
|
||||||
newPriorityLevelConfiguration.Spec = oldPriorityLevelConfiguration.Spec
|
newPriorityLevelConfiguration.Spec = oldPriorityLevelConfiguration.Spec
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,6 +38,10 @@ func (a statusStrategy) PrepareForUpdate(ctx context.Context, obj, old runtime.O
|
|||||||
newCustomResource := newCustomResourceObject.UnstructuredContent()
|
newCustomResource := newCustomResourceObject.UnstructuredContent()
|
||||||
status, ok := newCustomResource["status"]
|
status, ok := newCustomResource["status"]
|
||||||
|
|
||||||
|
// managedFields must be preserved since it's been modified to
|
||||||
|
// track changed fields in the status update.
|
||||||
|
managedFields := newCustomResourceObject.GetManagedFields()
|
||||||
|
|
||||||
// copy old object into new object
|
// copy old object into new object
|
||||||
oldCustomResourceObject := old.(*unstructured.Unstructured)
|
oldCustomResourceObject := old.(*unstructured.Unstructured)
|
||||||
// overridding the resourceVersion in metadata is safe here, we have already checked that
|
// overridding the resourceVersion in metadata is safe here, we have already checked that
|
||||||
@ -45,6 +49,7 @@ func (a statusStrategy) PrepareForUpdate(ctx context.Context, obj, old runtime.O
|
|||||||
*newCustomResourceObject = *oldCustomResourceObject.DeepCopy()
|
*newCustomResourceObject = *oldCustomResourceObject.DeepCopy()
|
||||||
|
|
||||||
// set status
|
// set status
|
||||||
|
newCustomResourceObject.SetManagedFields(managedFields)
|
||||||
newCustomResource = newCustomResourceObject.UnstructuredContent()
|
newCustomResource = newCustomResourceObject.UnstructuredContent()
|
||||||
if ok {
|
if ok {
|
||||||
newCustomResource["status"] = status
|
newCustomResource["status"] = status
|
||||||
|
@ -252,7 +252,9 @@ func ResetObjectMetaForStatus(meta, existingMeta Object) {
|
|||||||
meta.SetAnnotations(existingMeta.GetAnnotations())
|
meta.SetAnnotations(existingMeta.GetAnnotations())
|
||||||
meta.SetFinalizers(existingMeta.GetFinalizers())
|
meta.SetFinalizers(existingMeta.GetFinalizers())
|
||||||
meta.SetOwnerReferences(existingMeta.GetOwnerReferences())
|
meta.SetOwnerReferences(existingMeta.GetOwnerReferences())
|
||||||
meta.SetManagedFields(existingMeta.GetManagedFields())
|
// managedFields must be preserved since it's been modified to
|
||||||
|
// track changed fields in the status update.
|
||||||
|
//meta.SetManagedFields(existingMeta.GetManagedFields())
|
||||||
}
|
}
|
||||||
|
|
||||||
// MarshalJSON implements json.Marshaler
|
// MarshalJSON implements json.Marshaler
|
||||||
|
@ -189,6 +189,7 @@ func TestResetObjectMetaForStatus(t *testing.T) {
|
|||||||
existingMeta.SetCreationTimestamp(Time{})
|
existingMeta.SetCreationTimestamp(Time{})
|
||||||
existingMeta.SetDeletionTimestamp(nil)
|
existingMeta.SetDeletionTimestamp(nil)
|
||||||
existingMeta.SetDeletionGracePeriodSeconds(nil)
|
existingMeta.SetDeletionGracePeriodSeconds(nil)
|
||||||
|
existingMeta.SetManagedFields(nil)
|
||||||
|
|
||||||
if !reflect.DeepEqual(meta, existingMeta) {
|
if !reflect.DeepEqual(meta, existingMeta) {
|
||||||
t.Error(diff.ObjectDiff(meta, existingMeta))
|
t.Error(diff.ObjectDiff(meta, existingMeta))
|
||||||
|
Loading…
Reference in New Issue
Block a user