m/p/common: use protobuf.Timestamp in NodeStatus
This updates NodeStatus to use google.protobuf.Timestamp.
See: issue #129.
Change-Id: I7902908a885a909d5ad6e232333037add5fb02e2
Reviewed-on: https://review.monogon.dev/c/monogon/+/831
Tested-by: Jenkins CI
Reviewed-by: Sergiusz Bazanski <serge@monogon.tech>
diff --git a/metropolis/node/core/curator/BUILD.bazel b/metropolis/node/core/curator/BUILD.bazel
index 57ed4ec..972beca 100644
--- a/metropolis/node/core/curator/BUILD.bazel
+++ b/metropolis/node/core/curator/BUILD.bazel
@@ -45,6 +45,7 @@
"@org_golang_google_grpc//status",
"@org_golang_google_protobuf//proto",
"@org_golang_google_protobuf//types/known/durationpb",
+ "@org_golang_google_protobuf//types/known/timestamppb",
],
)
diff --git a/metropolis/node/core/curator/impl_leader_curator.go b/metropolis/node/core/curator/impl_leader_curator.go
index 792c951..9978c7e 100644
--- a/metropolis/node/core/curator/impl_leader_curator.go
+++ b/metropolis/node/core/curator/impl_leader_curator.go
@@ -12,6 +12,7 @@
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/proto"
+ tpb "google.golang.org/protobuf/types/known/timestamppb"
common "source.monogon.dev/metropolis/node"
ipb "source.monogon.dev/metropolis/node/core/curator/proto/api"
@@ -249,7 +250,7 @@
}
// ... update its' status ...
node.status = req.Status
- node.status.Timestamp = time.Now().UnixNano()
+ node.status.Timestamp = tpb.Now()
// ... and save it to etcd.
if err := nodeSave(ctx, l.leadership, node); err != nil {
return nil, err
diff --git a/metropolis/proto/common/BUILD.bazel b/metropolis/proto/common/BUILD.bazel
index 45dafd8..21ca6a5 100644
--- a/metropolis/proto/common/BUILD.bazel
+++ b/metropolis/proto/common/BUILD.bazel
@@ -6,6 +6,9 @@
name = "common_proto",
srcs = ["common.proto"],
visibility = ["//metropolis:__subpackages__"],
+ deps = [
+ "@com_google_protobuf//:timestamp_proto",
+ ],
)
go_proto_library(
diff --git a/metropolis/proto/common/common.proto b/metropolis/proto/common/common.proto
index c25736b..ca4bfea 100644
--- a/metropolis/proto/common/common.proto
+++ b/metropolis/proto/common/common.proto
@@ -18,6 +18,8 @@
package metropolis.proto.common;
option go_package = "source.monogon.dev/metropolis/proto/common";
+import "google/protobuf/timestamp.proto";
+
// NodeRoles are the possible roles that a Metropolis Node should run within the
// cluster. These are configured by the cluster and can be retrieved through the
// Curator.
@@ -141,7 +143,7 @@
RunningCurator running_curator = 3;
// timestamp is an epoch number associated with the last status update.
// It's set with a nanosecond granularity.
- int64 timestamp = 2;
+ google.protobuf.Timestamp timestamp = 2;
}
// The Cluster Directory is information about the network addressing of nodes
diff --git a/metropolis/test/launch/cluster/cluster.go b/metropolis/test/launch/cluster/cluster.go
index 0c85fc3..b3049e3 100644
--- a/metropolis/test/launch/cluster/cluster.go
+++ b/metropolis/test/launch/cluster/cluster.go
@@ -912,7 +912,7 @@
if cs.Status == nil {
continue
}
- if cs.Status.Timestamp > is.Status.Timestamp {
+ if cs.Status.Timestamp.AsTime().Sub(is.Status.Timestamp.AsTime()) > 0 {
break
}
time.Sleep(time.Second)