-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use UTC for timestamps consistently to avoid proto merge panics #5712
Conversation
lib/services/services_test.go
Outdated
@@ -108,7 +108,7 @@ func (s *ServicesSuite) TestLabelKeyValidation(c *check.C) { | |||
func TestServerDeepCopy(t *testing.T) { | |||
t.Parallel() | |||
// setup | |||
now := time.Date(1984, time.April, 4, 0, 0, 0, 0, time.UTC) | |||
now := time.Date(1984, time.April, 4, 0, 0, 0, 0, time.Local) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This tests the proto-based implementation deficiency (if we continued to use the implementation).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reverted to use UTC again as this triggers panic.
api/types/server.go
Outdated
@@ -335,7 +334,18 @@ func (s *ServerV2) CheckAndSetDefaults() error { | |||
|
|||
// DeepCopy creates a clone of this server value | |||
func (s *ServerV2) DeepCopy() Server { | |||
return proto.Clone(s).(*ServerV2) | |||
newServer := *s |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Potential drawback is this needs attention if the server type is modified to include more pointer fields that would require cloning.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reverted to proto.Clone
provided that timestamps are all UTC.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a real shame we can't use proto.Clone
, this manual cloning adds maintenance burden and subtle bug risks.
I think the main reason is that we use gogoprotobuf
generator, mixed with the official protobuf
libraries. If we could use only the official one, a lot of these problems could go away.
But gogoproto
adds some conveniences that would be hard to give up.
got, err := UnmarshalServerResource([]byte(tt.in), KindKubeService, &MarshalConfig{}) | ||
got, err := UnmarshalServer([]byte(tt.in), KindKubeService) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: update the test name accordingly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated in aec288b
api/types/server.go
Outdated
@@ -335,7 +334,18 @@ func (s *ServerV2) CheckAndSetDefaults() error { | |||
|
|||
// DeepCopy creates a clone of this server value | |||
func (s *ServerV2) DeepCopy() Server { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few other things to copy manually:
s.Spec.CmdLabels
s.Spec.Apps
s.Spec.KubernetesClusters
In fact, I may have rushed things a bit - the reason I removed the |
2345412
to
aec288b
Compare
manual implementation to avoid issues with proto-based type merge panics. Fixes #5691.
aec288b
to
c03cb31
Compare
@fspmarshall Can you review? |
Use UTC for timestamps when unmarshaling server values to avoid issues with proto-based type merge panics.
Fixes #5691.