-
Notifications
You must be signed in to change notification settings - Fork 339
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
Feat/#661 - Exposing creationTime and modificationTime #677
Changes from 24 commits
665fd13
5706587
dd2e5b1
cc845a1
af336c9
fbc8468
7f55289
a3198ed
e8a7445
6fe53f3
d8dc012
fd0ba3c
e104eb0
6acce39
0d80de7
080c42e
1527053
99117f7
84162e1
522f1e8
f57aa4f
e5ed83b
0df63c9
196d6ea
8589237
dc0c940
a5b7ad4
93171c8
c072066
ac3636c
64a28e7
87cdfdc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -110,7 +110,7 @@ func NewApplyCmd(pctx *kumactl_cmd.RootContext) *cobra.Command { | |
return err | ||
} | ||
|
||
if err := upsert(rs, res); err != nil { | ||
if err := upsert(pctx.Now(), rs, res); err != nil { | ||
return err | ||
} | ||
return nil | ||
|
@@ -154,23 +154,23 @@ func processConfigTemplate(config string, values map[string]string) ([]byte, err | |
return []byte(data), nil | ||
} | ||
|
||
func upsert(rs store.ResourceStore, res model.Resource) error { | ||
func upsert(now time.Time, rs store.ResourceStore, res model.Resource) error { | ||
newRes, err := registry.Global().NewObject(res.GetType()) | ||
if err != nil { | ||
return err | ||
} | ||
meta := res.GetMeta() | ||
if err := rs.Get(context.Background(), newRes, store.GetByKey(meta.GetName(), meta.GetMesh())); err != nil { | ||
if store.IsResourceNotFound(err) { | ||
return rs.Create(context.Background(), res, store.CreateByKey(meta.GetName(), meta.GetMesh())) | ||
return rs.Create(context.Background(), res, store.CreateByKey(meta.GetName(), meta.GetMesh()), store.CreatedAt(now)) | ||
} else { | ||
return err | ||
} | ||
} | ||
if err := newRes.SetSpec(res.GetSpec()); err != nil { | ||
return err | ||
} | ||
return rs.Update(context.Background(), newRes) | ||
return rs.Update(context.Background(), newRes, store.ModifiedAt(now)) | ||
} | ||
|
||
func parseResource(bytes []byte) (model.Resource, error) { | ||
|
@@ -201,8 +201,10 @@ func parseResource(bytes []byte) (model.Resource, error) { | |
var _ model.ResourceMeta = &meta{} | ||
|
||
type meta struct { | ||
Name string | ||
Mesh string | ||
Name string | ||
Mesh string | ||
CreationTime time.Time | ||
ModificationTime time.Time | ||
} | ||
|
||
func (m meta) GetName() string { | ||
|
@@ -222,9 +224,9 @@ func (m meta) GetMesh() string { | |
} | ||
|
||
func (m meta) GetCreationTime() time.Time { | ||
return time.Unix(0, 0) // the date doesn't matter since it is set on server side anyways | ||
return m.CreationTime | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comment is still relevant. This should be set on the server-side. |
||
} | ||
|
||
func (m meta) GetModificationTime() time.Time { | ||
return time.Unix(0, 0) // the date doesn't matter since it is set on server side anyways | ||
return m.ModificationTime | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ import ( | |
"io/ioutil" | ||
"path/filepath" | ||
"strings" | ||
"time" | ||
|
||
"github.com/Kong/kuma/app/kumactl/cmd" | ||
|
||
|
@@ -30,8 +31,10 @@ import ( | |
var _ = Describe("kumactl get dataplanes", func() { | ||
|
||
var dataplanes []*mesh_core.DataplaneResource | ||
|
||
var t1 time.Time | ||
BeforeEach(func() { | ||
t1, _ = time.Parse(time.RFC3339, "2018-07-17T16:05:36.995+00:00") | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you revert such files (I see a couple of them) with an empty line change to master? |
||
dataplanes = []*mesh_core.DataplaneResource{ | ||
{ | ||
Meta: &test_model.ResourceMeta{ | ||
|
@@ -111,7 +114,7 @@ var _ = Describe("kumactl get dataplanes", func() { | |
Mesh: pt.Meta.GetMesh(), | ||
Name: pt.Meta.GetName(), | ||
} | ||
err := store.Create(context.Background(), pt, core_store.CreateBy(key)) | ||
err := store.Create(context.Background(), pt, core_store.CreateBy(key), core_store.CreatedAt(t1)) | ||
Expect(err).ToNot(HaveOccurred()) | ||
} | ||
|
||
|
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.
Is it needed though? I think we can revert this file to master
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.
but not sure if I revert it to master,
GetCreationTime()
istime.Unix
and it will be different for each machine and the test will fail in ci.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.
time.Unix(0, 0)
indicates the constant timeThere 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.
changed