mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-28 14:07:14 +00:00
Merge pull request #5185 from smarterclayton/ignore_creation_timestamp
Ignore changes to creation timestamp from clients on update
This commit is contained in:
commit
a5ecfbfe42
@ -219,7 +219,10 @@ func ValidateObjectMetaUpdate(old, meta *api.ObjectMeta) errs.ValidationErrorLis
|
|||||||
if len(meta.UID) == 0 {
|
if len(meta.UID) == 0 {
|
||||||
meta.UID = old.UID
|
meta.UID = old.UID
|
||||||
}
|
}
|
||||||
if meta.CreationTimestamp.IsZero() {
|
// ignore changes to timestamp
|
||||||
|
if old.CreationTimestamp.IsZero() {
|
||||||
|
old.CreationTimestamp = meta.CreationTimestamp
|
||||||
|
} else {
|
||||||
meta.CreationTimestamp = old.CreationTimestamp
|
meta.CreationTimestamp = old.CreationTimestamp
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,6 +19,7 @@ package validation
|
|||||||
import (
|
import (
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors"
|
||||||
@ -53,6 +54,27 @@ func TestValidateObjectMetaCustomName(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestValidateObjectMetaUpdateIgnoresCreationTimestamp(t *testing.T) {
|
||||||
|
if errs := ValidateObjectMetaUpdate(
|
||||||
|
&api.ObjectMeta{Name: "test", CreationTimestamp: util.NewTime(time.Unix(10, 0))},
|
||||||
|
&api.ObjectMeta{Name: "test"},
|
||||||
|
); len(errs) != 0 {
|
||||||
|
t.Fatalf("unexpected errors: %v", errs)
|
||||||
|
}
|
||||||
|
if errs := ValidateObjectMetaUpdate(
|
||||||
|
&api.ObjectMeta{Name: "test"},
|
||||||
|
&api.ObjectMeta{Name: "test", CreationTimestamp: util.NewTime(time.Unix(10, 0))},
|
||||||
|
); len(errs) != 0 {
|
||||||
|
t.Fatalf("unexpected errors: %v", errs)
|
||||||
|
}
|
||||||
|
if errs := ValidateObjectMetaUpdate(
|
||||||
|
&api.ObjectMeta{Name: "test", CreationTimestamp: util.NewTime(time.Unix(11, 0))},
|
||||||
|
&api.ObjectMeta{Name: "test", CreationTimestamp: util.NewTime(time.Unix(10, 0))},
|
||||||
|
); len(errs) != 0 {
|
||||||
|
t.Fatalf("unexpected errors: %v", errs)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Ensure trailing slash is allowed in generate name
|
// Ensure trailing slash is allowed in generate name
|
||||||
func TestValidateObjectMetaTrimsTrailingSlash(t *testing.T) {
|
func TestValidateObjectMetaTrimsTrailingSlash(t *testing.T) {
|
||||||
errs := ValidateObjectMeta(&api.ObjectMeta{Name: "test", GenerateName: "foo-"}, false, nameIsDNSSubdomain)
|
errs := ValidateObjectMeta(&api.ObjectMeta{Name: "test", GenerateName: "foo-"}, false, nameIsDNSSubdomain)
|
||||||
|
Loading…
Reference in New Issue
Block a user