From 27015944ce2b8d963f7080a90c715a8c8447ebeb Mon Sep 17 00:00:00 2001 From: Tharun Date: Wed, 15 Apr 2020 20:30:28 +0530 Subject: [PATCH] * added createdAt and modifiedAt params to upsert function in apply Feature #661 --- app/kumactl/cmd/apply/apply.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/kumactl/cmd/apply/apply.go b/app/kumactl/cmd/apply/apply.go index 75e54d62d72e..43382ecc8fce 100644 --- a/app/kumactl/cmd/apply/apply.go +++ b/app/kumactl/cmd/apply/apply.go @@ -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,7 +154,7 @@ 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 @@ -162,7 +162,7 @@ func upsert(rs store.ResourceStore, res model.Resource) error { 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 } @@ -170,7 +170,7 @@ func upsert(rs store.ResourceStore, res model.Resource) error { 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) {