mirror of https://github.com/knative/pkg.git
Change 'updater' to 'lastModifier' in webhook (#512)
* Change 'updater' to 'lastModifier' in webhook Both eventing and serving curretly use lastModifier. Nothing seems to implement the pkg 'HasSpec' interface yet so this should be a safe change. This brings the annotation in-line with currentb behavior Fixes #511 * Remove unnecessary defer * Change paths in json patches
This commit is contained in:
parent
a68e009041
commit
e2418a08c1
|
@ -31,7 +31,7 @@ const (
|
|||
|
||||
// UpdaterAnnotationSuffix is the suffix of the annotation key to describe
|
||||
// the user who last modified the resource.
|
||||
UpdaterAnnotationSuffix = "/updater"
|
||||
UpdaterAnnotationSuffix = "/lastModifier"
|
||||
)
|
||||
|
||||
// SetUserInfoAnnotations sets creator and updater annotations on a resource.
|
||||
|
@ -45,7 +45,7 @@ func SetUserInfoAnnotations(resource apis.HasSpec, ctx context.Context, groupNam
|
|||
annotations := objectMetaAccessor.GetObjectMeta().GetAnnotations()
|
||||
if annotations == nil {
|
||||
annotations = map[string]string{}
|
||||
defer objectMetaAccessor.GetObjectMeta().SetAnnotations(annotations)
|
||||
objectMetaAccessor.GetObjectMeta().SetAnnotations(annotations)
|
||||
}
|
||||
|
||||
if apis.IsInUpdate(ctx) {
|
||||
|
|
|
@ -45,7 +45,7 @@ func TestSetUserInfoAnnotationsWhenWithinCreate(t *testing.T) {
|
|||
},
|
||||
expectedAnnotations: map[string]string{
|
||||
"pkg.knative.dev/creator": user1,
|
||||
"pkg.knative.dev/updater": user1,
|
||||
"pkg.knative.dev/lastModifier": user1,
|
||||
},
|
||||
}, {
|
||||
name: "test create (should override user info annotations when they are present)",
|
||||
|
@ -55,12 +55,12 @@ func TestSetUserInfoAnnotationsWhenWithinCreate(t *testing.T) {
|
|||
setup: func(ctx context.Context, r *Resource) {
|
||||
r.Annotations = map[string]string{
|
||||
"pkg.knative.dev/creator": user2,
|
||||
"pkg.knative.dev/updater": user2,
|
||||
"pkg.knative.dev/lastModifier": user2,
|
||||
}
|
||||
},
|
||||
expectedAnnotations: map[string]string{
|
||||
"pkg.knative.dev/creator": user1,
|
||||
"pkg.knative.dev/updater": user1,
|
||||
"pkg.knative.dev/lastModifier": user1,
|
||||
},
|
||||
}, {
|
||||
name: "test create (should not touch annotations when no user info available)",
|
||||
|
@ -114,7 +114,7 @@ func TestSetUserInfoAnnotationsWhenWithinUpdate(t *testing.T) {
|
|||
},
|
||||
expectedAnnotations: map[string]string{
|
||||
"pkg.knative.dev/creator": user2,
|
||||
"pkg.knative.dev/updater": user1,
|
||||
"pkg.knative.dev/lastModifier": user1,
|
||||
},
|
||||
}, {
|
||||
name: "test update (should update updater annotation when it is present)",
|
||||
|
@ -124,14 +124,14 @@ func TestSetUserInfoAnnotationsWhenWithinUpdate(t *testing.T) {
|
|||
setup: func(ctx context.Context, r *Resource) {
|
||||
r.Annotations = map[string]string{
|
||||
"pkg.knative.dev/creator": user2,
|
||||
"pkg.knative.dev/updater": user2,
|
||||
"pkg.knative.dev/lastModifier": user2,
|
||||
}
|
||||
r.Spec.FieldWithDefault = "changing this field"
|
||||
},
|
||||
expectedAnnotations: map[string]string{
|
||||
// should not change
|
||||
"pkg.knative.dev/creator": user2,
|
||||
"pkg.knative.dev/updater": user1,
|
||||
"pkg.knative.dev/lastModifier": user1,
|
||||
},
|
||||
}, {
|
||||
name: "test update (should not touch annotations when no user info available)",
|
||||
|
|
|
@ -172,7 +172,7 @@ func TestAdmitCreates(t *testing.T) {
|
|||
r.SetDefaults(ctx)
|
||||
r.Annotations = map[string]string{
|
||||
"pkg.knative.dev/creator": user1,
|
||||
"pkg.knative.dev/updater": user1,
|
||||
"pkg.knative.dev/lastModifier": user1,
|
||||
}
|
||||
},
|
||||
patches: []jsonpatch.JsonPatchOperation{},
|
||||
|
@ -183,7 +183,7 @@ func TestAdmitCreates(t *testing.T) {
|
|||
r.SetDefaults(ctx)
|
||||
r.Annotations = map[string]string{
|
||||
"pkg.knative.dev/creator": user1,
|
||||
"pkg.knative.dev/updater": user1,
|
||||
"pkg.knative.dev/lastModifier": user1,
|
||||
}
|
||||
},
|
||||
patches: []jsonpatch.JsonPatchOperation{},
|
||||
|
@ -196,7 +196,7 @@ func TestAdmitCreates(t *testing.T) {
|
|||
Path: "/metadata/annotations",
|
||||
Value: map[string]interface{}{
|
||||
"pkg.knative.dev/creator": user1,
|
||||
"pkg.knative.dev/updater": user1,
|
||||
"pkg.knative.dev/lastModifier": user1,
|
||||
},
|
||||
}, {
|
||||
Operation: "add",
|
||||
|
@ -220,7 +220,7 @@ func TestAdmitCreates(t *testing.T) {
|
|||
Value: user1,
|
||||
}, {
|
||||
Operation: "add",
|
||||
Path: "/metadata/annotations/pkg.knative.dev~1updater",
|
||||
Path: "/metadata/annotations/pkg.knative.dev~1lastModifier",
|
||||
Value: user1,
|
||||
}, {
|
||||
Operation: "add",
|
||||
|
@ -241,7 +241,7 @@ func TestAdmitCreates(t *testing.T) {
|
|||
Path: "/metadata/annotations",
|
||||
Value: map[string]interface{}{
|
||||
"pkg.knative.dev/creator": user1,
|
||||
"pkg.knative.dev/updater": user1,
|
||||
"pkg.knative.dev/lastModifier": user1,
|
||||
},
|
||||
}, {
|
||||
Operation: "add",
|
||||
|
@ -254,12 +254,12 @@ func TestAdmitCreates(t *testing.T) {
|
|||
r.SetDefaults(ctx)
|
||||
// THIS IS NOT WHO IS CREATING IT, IT IS LIES!
|
||||
r.Annotations = map[string]string{
|
||||
"pkg.knative.dev/updater": user2,
|
||||
"pkg.knative.dev/lastModifier": user2,
|
||||
}
|
||||
},
|
||||
patches: []jsonpatch.JsonPatchOperation{{
|
||||
Operation: "replace",
|
||||
Path: "/metadata/annotations/pkg.knative.dev~1updater",
|
||||
Path: "/metadata/annotations/pkg.knative.dev~1lastModifier",
|
||||
Value: user1,
|
||||
}, {
|
||||
Operation: "add",
|
||||
|
@ -346,7 +346,7 @@ func TestAdmitUpdates(t *testing.T) {
|
|||
},
|
||||
patches: []jsonpatch.JsonPatchOperation{{
|
||||
Operation: "replace",
|
||||
Path: "/metadata/annotations/pkg.knative.dev~1updater",
|
||||
Path: "/metadata/annotations/pkg.knative.dev~1lastModifier",
|
||||
Value: user2,
|
||||
}},
|
||||
}, {
|
||||
|
@ -400,7 +400,7 @@ func TestAdmitUpdates(t *testing.T) {
|
|||
|
||||
old.Annotations = map[string]string{
|
||||
"pkg.knative.dev/creator": user1,
|
||||
"pkg.knative.dev/updater": user1,
|
||||
"pkg.knative.dev/lastModifier": user1,
|
||||
}
|
||||
|
||||
tc.setup(ctx, old)
|
||||
|
@ -789,7 +789,7 @@ func setUserAnnotation(userC, userU string) jsonpatch.JsonPatchOperation {
|
|||
Path: "/metadata/annotations",
|
||||
Value: map[string]interface{}{
|
||||
"pkg.knative.dev/creator": userC,
|
||||
"pkg.knative.dev/updater": userU,
|
||||
"pkg.knative.dev/lastModifier": userU,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue