Commit df7f4b35 authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

Merge pull request #47975 from deads2k/api-14-proto

Automatic merge from submit-queue (batch tested with PRs 46425, 47975) make proto time precision match json json readers/writers see second precision, but protobuf readers/writers seen nanosecond precision. This means that a json client can read and write and accidentally mutate fields as seen by protobuf clients. This makes the precision consistent. @kubernetes/sig-api-machinery-misc @smarterclayton ```release-note Update protobuf time serialization for a one second granularity ```
parents 49b83c6c 5b8a483a
......@@ -42,7 +42,10 @@ func (m *Time) ProtoTime() *Timestamp {
}
return &Timestamp{
Seconds: m.Time.Unix(),
Nanos: int32(m.Time.Nanosecond()),
// leaving this here for the record. our JSON only handled seconds, so this results in writes by
// protobuf clients storing values that aren't read by json clients, which results in unexpected
// field mutation, which fails various validation and equality code.
// Nanos: int32(m.Time.Nanosecond()),
}
}
......@@ -64,7 +67,11 @@ func (m *Time) Unmarshal(data []byte) error {
if err := p.Unmarshal(data); err != nil {
return err
}
m.Time = time.Unix(p.Seconds, int64(p.Nanos)).Local()
// leaving this here for the record. our JSON only handled seconds, so this results in writes by
// protobuf clients storing values that aren't read by json clients, which results in unexpected
// field mutation, which fails various validation and equality code.
// m.Time = time.Unix(p.Seconds, int64(p.Nanos)).Local()
m.Time = time.Unix(p.Seconds, int64(0)).Local()
return nil
}
......
......@@ -152,7 +152,7 @@ func TestTimeProto(t *testing.T) {
input Time
}{
{Time{}},
{Date(1998, time.May, 5, 1, 5, 5, 50, time.Local)},
{Date(1998, time.May, 5, 1, 5, 5, 0, time.Local)},
{Date(1998, time.May, 5, 5, 5, 5, 0, time.Local)},
}
......
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