Skip to content

Commit

Permalink
Merge pull request #91648 from apelisse/automated-cherry-pick-of-#905…
Browse files Browse the repository at this point in the history
…34-kubernetes-release-1.18

Automated cherry pick of #90534: Changes to ManagedFields is not mutation for GC
  • Loading branch information
k8s-ci-robot committed Jun 10, 2020
2 parents ab928c7 + db3ed2a commit 22a86a7
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pkg/registry/rbac/BUILD
Expand Up @@ -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",
],
)
1 change: 1 addition & 0 deletions pkg/registry/rbac/helpers.go
Expand Up @@ -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)
}
50 changes: 50 additions & 0 deletions pkg/registry/rbac/helpers_test.go
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
}
}

0 comments on commit 22a86a7

Please sign in to comment.