Skip to content
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

fix: do not change created_at on entity updates #1061

Merged
merged 2 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion diff/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,9 @@ func (sc *Syncer) Solve(ctx context.Context, parallelism int, dry bool, isJSONOu
}
} else {
// diff mode
// return the new obj as is
// return the new obj as is but with timestamps zeroed out
utils.ZeroOutTimestamps(e.Obj)
utils.ZeroOutTimestamps(e.OldObj)
result = e.Obj
}
// record operation in both: diff and sync commands
Expand Down
22 changes: 19 additions & 3 deletions diff/diff_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/hexops/gotextdiff/myers"
"github.com/hexops/gotextdiff/span"
"github.com/kong/deck/state"
"github.com/kong/deck/utils"
)

var differ = gojsondiff.New()
Expand Down Expand Up @@ -61,8 +60,6 @@ func prettyPrintJSONString(JSONString string) (string, error) {
}

func getDiff(a, b interface{}) (string, error) {
utils.ZeroOutTimestamps(a)
utils.ZeroOutTimestamps(b)
aJSON, err := json.Marshal(a)
if err != nil {
return "", err
Expand All @@ -71,6 +68,11 @@ func getDiff(a, b interface{}) (string, error) {
if err != nil {
return "", err
}

// remove timestamps from JSON data without modifying the original data
aJSON = removeTimestamps(aJSON)
bJSON = removeTimestamps(bJSON)

d, err := differ.Compare(aJSON, bJSON)
if err != nil {
return "", err
Expand All @@ -87,6 +89,20 @@ func getDiff(a, b interface{}) (string, error) {
return diffString, err
}

func removeTimestamps(jsonData []byte) []byte {
var dataMap map[string]interface{}
if err := json.Unmarshal(jsonData, &dataMap); err != nil {
return jsonData
}
delete(dataMap, "created_at")
delete(dataMap, "updated_at")
modifiedJSON, err := json.Marshal(dataMap)
if err != nil {
return jsonData
}
return modifiedJSON
}

type EnvVar struct {
Key string
Value string
Expand Down
Loading
Loading