Merge pull request #5185 from smarterclayton/ignore_creation_timestamp

Ignore changes to creation timestamp from clients on update
This commit is contained in:
Brian Grant 2015-03-10 11:21:13 -07:00
commit a5ecfbfe42
2 changed files with 26 additions and 1 deletions

View File

@ -219,7 +219,10 @@ func ValidateObjectMetaUpdate(old, meta *api.ObjectMeta) errs.ValidationErrorLis
if len(meta.UID) == 0 {
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
}

View File

@ -19,6 +19,7 @@ package validation
import (
"strings"
"testing"
"time"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"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
func TestValidateObjectMetaTrimsTrailingSlash(t *testing.T) {
errs := ValidateObjectMeta(&api.ObjectMeta{Name: "test", GenerateName: "foo-"}, false, nameIsDNSSubdomain)