Skip to content

Commit

Permalink
* added createdAt and modifiedAt params to upsert function in apply
Browse files Browse the repository at this point in the history
Feature #661
  • Loading branch information
tharun208 committed Apr 15, 2020
1 parent f57aa4f commit 2701594
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions app/kumactl/cmd/apply/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 2701594

Please sign in to comment.