mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 19:56:01 +00:00
Merge pull request #90534 from apelisse/mutatinggcfields-fieldmanager
Changes to ManagedFields is not mutation for GC
This commit is contained in:
commit
68ade56a47
@ -57,5 +57,7 @@ go_test(
|
||||
"//pkg/apis/core/helper:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/types:go_default_library",
|
||||
"//vendor/github.com/google/gofuzz:go_default_library",
|
||||
],
|
||||
)
|
||||
|
@ -44,6 +44,7 @@ func IsOnlyMutatingGCFields(obj, old runtime.Object, equalities conversion.Equal
|
||||
copiedMeta.SetOwnerReferences(oldMeta.GetOwnerReferences())
|
||||
copiedMeta.SetFinalizers(oldMeta.GetFinalizers())
|
||||
copiedMeta.SetSelfLink(oldMeta.GetSelfLink())
|
||||
copiedMeta.SetManagedFields(oldMeta.GetManagedFields())
|
||||
|
||||
return equalities.DeepEqual(copied, old)
|
||||
}
|
||||
|
@ -17,12 +17,16 @@ limitations under the License.
|
||||
package rbac
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
kapi "k8s.io/kubernetes/pkg/apis/core"
|
||||
kapihelper "k8s.io/kubernetes/pkg/apis/core/helper"
|
||||
|
||||
fuzz "github.com/google/gofuzz"
|
||||
)
|
||||
|
||||
func newPod() *kapi.Pod {
|
||||
@ -53,6 +57,22 @@ func TestIsOnlyMutatingGCFields(t *testing.T) {
|
||||
},
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
name: "different managedFields",
|
||||
obj: func() runtime.Object {
|
||||
return newPod()
|
||||
},
|
||||
old: func() runtime.Object {
|
||||
obj := newPod()
|
||||
obj.ManagedFields = []metav1.ManagedFieldsEntry{
|
||||
{
|
||||
Manager: "manager",
|
||||
},
|
||||
}
|
||||
return obj
|
||||
},
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
name: "only annotations",
|
||||
obj: func() runtime.Object {
|
||||
@ -150,3 +170,33 @@ func TestIsOnlyMutatingGCFields(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewMetadataFields(t *testing.T) {
|
||||
f := fuzz.New().NilChance(0.0).NumElements(1, 1)
|
||||
for i := 0; i < 100; i++ {
|
||||
objMeta := metav1.ObjectMeta{}
|
||||
f.Fuzz(&objMeta)
|
||||
objMeta.Name = ""
|
||||
objMeta.GenerateName = ""
|
||||
objMeta.Namespace = ""
|
||||
objMeta.SelfLink = ""
|
||||
objMeta.UID = types.UID("")
|
||||
objMeta.ResourceVersion = ""
|
||||
objMeta.Generation = 0
|
||||
objMeta.CreationTimestamp = metav1.Time{}
|
||||
objMeta.DeletionTimestamp = nil
|
||||
objMeta.DeletionGracePeriodSeconds = nil
|
||||
objMeta.Labels = nil
|
||||
objMeta.Annotations = nil
|
||||
objMeta.OwnerReferences = nil
|
||||
objMeta.Finalizers = nil
|
||||
objMeta.ClusterName = ""
|
||||
objMeta.ManagedFields = nil
|
||||
|
||||
if !reflect.DeepEqual(metav1.ObjectMeta{}, objMeta) {
|
||||
t.Fatalf(`A new field was introduced in ObjectMeta, add the field to
|
||||
IsOnlyMutatingGCFields if necessary, and update this test:
|
||||
%#v`, objMeta)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user