Commit d016f478 authored by Clayton Coleman's avatar Clayton Coleman

Ignore changes to creation timestamp from clients on update

CreationTimestamp is not an authoritative field (like UID) so mismatches can be safely ignored.
parent 02590e9a
...@@ -219,7 +219,10 @@ func ValidateObjectMetaUpdate(old, meta *api.ObjectMeta) errs.ValidationErrorLis ...@@ -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 ...@@ -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) { ...@@ -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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment