K8s/Dashboard: DeepCopy should deep copy (#102258)

This commit is contained in:
Ryan McKinley 2025-03-17 14:29:18 +03:00 committed by GitHub
parent 1700a8aa9f
commit c46565f652
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 20 additions and 3 deletions

View File

@ -219,7 +219,7 @@ func (o *Dashboard) Copy() resource.Object {
}
func (o *Dashboard) DeepCopyObject() runtime.Object {
return o.Copy()
return o.DeepCopy()
}
// Interface compliance compile-time check

View File

@ -219,7 +219,7 @@ func (o *Dashboard) Copy() resource.Object {
}
func (o *Dashboard) DeepCopyObject() runtime.Object {
return o.Copy()
return o.DeepCopy()
}
// Interface compliance compile-time check

View File

@ -219,7 +219,7 @@ func (o *Dashboard) Copy() resource.Object {
}
func (o *Dashboard) DeepCopyObject() runtime.Object {
return o.Copy()
return o.DeepCopy()
}
// Interface compliance compile-time check

View File

@ -45,3 +45,20 @@ func TestConversionMatrixExist(t *testing.T) {
})
}
}
func TestDeepCopyValid(t *testing.T) {
dash1 := &v0alpha1.Dashboard{}
meta1, err := utils.MetaAccessor(dash1)
require.NoError(t, err)
meta1.SetFolder("f1")
require.Equal(t, "f1", dash1.Annotations[utils.AnnoKeyFolder])
dash1Copy := dash1.DeepCopyObject()
metaCopy, err := utils.MetaAccessor(dash1Copy)
require.NoError(t, err)
require.Equal(t, "f1", metaCopy.GetFolder())
// Changing a property on the copy should not effect the original
metaCopy.SetFolder("XYZ")
require.Equal(t, "f1", meta1.GetFolder()) // 💣💣💣
}