Skip to content
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
2 changes: 1 addition & 1 deletion RELEASE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Generated by `make release` command.
# DO NOT EDIT.
tag: v0.51.2
tag: v0.51.3

releaseNoteGenerator:
showCommitter: false
Expand Down
1 change: 1 addition & 0 deletions pkg/app/piped/driftdetector/cloudrun/detector.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ func (d *detector) checkApplication(ctx context.Context, app *model.Application,
diff.WithEquateEmpty(),
diff.WithIgnoreAddingMapKeys(),
diff.WithCompareNumberAndNumericString(),
diff.WithCompareBooleanAndBooleanString(),
)
if err != nil {
return err
Expand Down
1 change: 1 addition & 0 deletions pkg/app/piped/planpreview/cloudrundiff.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ func (b *builder) cloudrundiff(
newManifest,
diff.WithEquateEmpty(),
diff.WithCompareNumberAndNumericString(),
diff.WithCompareBooleanAndBooleanString(),
)
if err != nil {
fmt.Fprintf(buf, "failed to compare manifests (%v)\n", err)
Expand Down
50 changes: 45 additions & 5 deletions pkg/diff/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ import (
)

type differ struct {
ignoreAddingMapKeys bool
equateEmpty bool
compareNumberAndNumericString bool
ignoredPaths map[string]struct{}
ignoreConfig map[string][]string
ignoreAddingMapKeys bool
equateEmpty bool
compareNumberAndNumericString bool
compareBooleanAndBooleanString bool
ignoredPaths map[string]struct{}
ignoreConfig map[string][]string

result *Result
}
Expand Down Expand Up @@ -60,6 +61,15 @@ func WithCompareNumberAndNumericString() Option {
}
}

// WithCompareBooleanAndBooleanString configures differ to compare a boolean with a string.
// Differ parses the string to boolean before comparing their values.
// e.g. true == "true"
func WithCompareBooleanAndBooleanString() Option {
return func(d *differ) {
d.compareBooleanAndBooleanString = true
}
}

// WithIgnoreConfig configures ignored fields.
func WithIgnoreConfig(config map[string][]string) Option {
return func(d *differ) {
Expand Down Expand Up @@ -170,6 +180,24 @@ func (d *differ) diff(path []PathStep, vx, vy reflect.Value) error {
}
}

if isBooleanValue(vx) && isBooleanValue(vy) {
return d.diffBool(path, vx, vy)
}

if d.compareBooleanAndBooleanString {
if isBooleanValue(vx) {
if y, ok := convertToBoolean(vy); ok {
return d.diffBool(path, vx, y)
}
}

if isBooleanValue(vy) {
if x, ok := convertToBoolean(vx); ok {
return d.diffBool(path, x, vy)
}
}
}

if vx.Type() != vy.Type() {
d.addNode(path, vx.Type(), vy.Type(), vx, vy)
return nil
Expand Down Expand Up @@ -360,6 +388,18 @@ func convertToNumber(v reflect.Value) (reflect.Value, bool) {
}
}

func isBooleanValue(v reflect.Value) bool {
return v.Kind() == reflect.Bool
}

func convertToBoolean(v reflect.Value) (reflect.Value, bool) {
if v.Kind() == reflect.String {
b, err := strconv.ParseBool(v.String())
return reflect.ValueOf(b), err == nil
}
return v, false
}

func newSlicePath(path []PathStep, index int) []PathStep {
next := make([]PathStep, len(path))
copy(next, path)
Expand Down
1 change: 1 addition & 0 deletions pkg/diff/diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func TestDiff(t *testing.T) {
WithEquateEmpty(),
WithIgnoreAddingMapKeys(),
WithCompareNumberAndNumericString(),
WithCompareBooleanAndBooleanString(),
},
diffNum: 0,
},
Expand Down
3 changes: 3 additions & 0 deletions pkg/diff/renderer.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,9 @@ func renderNodeValue(v reflect.Value, prefix string) (string, bool) {
case reflect.Float32, reflect.Float64:
return strconv.FormatFloat(v.Float(), 'f', -1, 64), false

case reflect.Bool:
return strconv.FormatBool(v.Bool()), false

default:
return v.String(), false
}
Expand Down
20 changes: 20 additions & 0 deletions pkg/diff/renderer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ func TestRenderNodeValue(t *testing.T) {
"one": []string{"one-1", "one-2"},
"two": []string{"two-1", "two-2"},
}
mapOfBool = map[string]interface{}{
"false": false,
"true": true,
}
)

testcases := []struct {
Expand All @@ -65,6 +69,16 @@ func TestRenderNodeValue(t *testing.T) {
value: reflect.ValueOf("hello"),
expected: "hello",
},
{
name: "bool value (true)",
value: reflect.ValueOf(true),
expected: "true",
},
{
name: "bool value (false)",
value: reflect.ValueOf(false),
expected: "false",
},
{
name: "slice of primitive elements",
value: func() reflect.Value {
Expand Down Expand Up @@ -142,6 +156,12 @@ two: two-value`,
- b
7-string: hi`,
},
{
name: "map of bool",
value: reflect.ValueOf(mapOfBool),
expected: `false: false
true: true`,
},
}

for _, tc := range testcases {
Expand Down
8 changes: 8 additions & 0 deletions pkg/diff/testdata/no_diff.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ metadata:
zeroString1: ""
zeroInt1: 0
zeroFloat1: 0.0
booleanString1: "true"
booleanString2: true
booleanString3: "false"
booleanString4: false
spec:
replicas: 2
number: 1
Expand Down Expand Up @@ -53,6 +57,10 @@ metadata:
zeroString2: ""
zeroInt2: 0
zeroFloat2: 0.0
booleanString1: true
booleanString2: "true"
booleanString3: false
booleanString4: "false"
spec:
replicas: 2
number: 1.0
Expand Down
50 changes: 45 additions & 5 deletions pkg/plugin/diff/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ import (
)

type differ struct {
ignoreAddingMapKeys bool
equateEmpty bool
compareNumberAndNumericString bool
ignoredPaths map[string]struct{}
ignoreConfig map[string][]string
ignoreAddingMapKeys bool
equateEmpty bool
compareNumberAndNumericString bool
compareBooleanAndBooleanString bool
ignoredPaths map[string]struct{}
ignoreConfig map[string][]string

result *Result
}
Expand Down Expand Up @@ -59,6 +60,15 @@ func WithCompareNumberAndNumericString() Option {
}
}

// WithCompareBooleanAndBooleanString configures differ to compare a boolean with a string.
// Differ parses the string to boolean before comparing their values.
// e.g. true == "true"
func WithCompareBooleanAndBooleanString() Option {
return func(d *differ) {
d.compareBooleanAndBooleanString = true
}
}

// WithIgnoreConfig configures ignored fields.
func WithIgnoreConfig(config map[string][]string) Option {
return func(d *differ) {
Expand Down Expand Up @@ -135,6 +145,24 @@ func (d *differ) diff(path []PathStep, vx, vy reflect.Value) error {
}
}

if isBooleanValue(vx) && isBooleanValue(vy) {
return d.diffBool(path, vx, vy)
}

if d.compareBooleanAndBooleanString {
if isBooleanValue(vx) {
if y, ok := convertToBoolean(vy); ok {
return d.diffBool(path, vx, y)
}
}

if isBooleanValue(vy) {
if x, ok := convertToBoolean(vx); ok {
return d.diffBool(path, x, vy)
}
}
}

if vx.Type() != vy.Type() {
d.addNode(path, vx.Type(), vy.Type(), vx, vy)
return nil
Expand Down Expand Up @@ -325,6 +353,18 @@ func convertToNumber(v reflect.Value) (reflect.Value, bool) {
}
}

func isBooleanValue(v reflect.Value) bool {
return v.Kind() == reflect.Bool
}

func convertToBoolean(v reflect.Value) (reflect.Value, bool) {
if v.Kind() == reflect.String {
b, err := strconv.ParseBool(v.String())
return reflect.ValueOf(b), err == nil
}
return v, false
}

func newSlicePath(path []PathStep, index int) []PathStep {
next := make([]PathStep, len(path))
copy(next, path)
Expand Down
1 change: 1 addition & 0 deletions pkg/plugin/diff/diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func TestDiff(t *testing.T) {
WithEquateEmpty(),
WithIgnoreAddingMapKeys(),
WithCompareNumberAndNumericString(),
WithCompareBooleanAndBooleanString(),
},
diffNum: 0,
},
Expand Down
3 changes: 3 additions & 0 deletions pkg/plugin/diff/renderer.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,9 @@ func renderNodeValue(v reflect.Value, prefix string) (string, bool) {
case reflect.Float32, reflect.Float64:
return strconv.FormatFloat(v.Float(), 'f', -1, 64), false

case reflect.Bool:
return strconv.FormatBool(v.Bool()), false

default:
return v.String(), false
}
Expand Down
20 changes: 20 additions & 0 deletions pkg/plugin/diff/renderer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ func TestRenderNodeValue(t *testing.T) {
"one": []string{"one-1", "one-2"},
"two": []string{"two-1", "two-2"},
}
mapOfBool = map[string]interface{}{
"false": false,
"true": true,
}
)

testcases := []struct {
Expand All @@ -65,6 +69,16 @@ func TestRenderNodeValue(t *testing.T) {
value: reflect.ValueOf("hello"),
expected: "hello",
},
{
name: "bool value (true)",
value: reflect.ValueOf(true),
expected: "true",
},
{
name: "bool value (false)",
value: reflect.ValueOf(false),
expected: "false",
},
{
name: "slice of primitive elements",
value: func() reflect.Value {
Expand Down Expand Up @@ -142,6 +156,12 @@ two: two-value`,
- b
7-string: hi`,
},
{
name: "map of bool",
value: reflect.ValueOf(mapOfBool),
expected: `false: false
true: true`,
},
}

for _, tc := range testcases {
Expand Down
8 changes: 8 additions & 0 deletions pkg/plugin/diff/testdata/no_diff.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ metadata:
zeroString1: ""
zeroInt1: 0
zeroFloat1: 0.0
booleanString1: "true"
booleanString2: true
booleanString3: "false"
booleanString4: false
spec:
replicas: 2
number: 1
Expand Down Expand Up @@ -53,6 +57,10 @@ metadata:
zeroString2: ""
zeroInt2: 0
zeroFloat2: 0.0
booleanString1: true
booleanString2: "true"
booleanString3: false
booleanString4: "false"
spec:
replicas: 2
number: 1.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ const useGroupedDeploymentTrace = (): GroupedDeploymentTrace => {
}, [traceList]);

const dates = useMemo(
() => Object.keys(deploymentTracesMap).sort(sortDateFunc),
() =>
Object.keys(deploymentTracesMap).sort((a, b) =>
sortDateFunc(a, b, "DESC")
),
[deploymentTracesMap]
);

Expand Down
6 changes: 3 additions & 3 deletions web/src/modules/deploymentTrace/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,13 @@ export const fetchMoreDeploymentTraces = createAsyncThunk<
DeploymentTraceFilterOptions,
{ state: AppState }
>("deploymentTrace/fetchMoreList", async (options, thunkAPI) => {
const { deployments } = thunkAPI.getState();
const { deploymentTrace } = thunkAPI.getState();

const response = await deploymentTracesApi.getDeploymentTraces({
options: convertFilterOptions(options),
pageSize: FETCH_MORE_ITEMS_PER_PAGE,
cursor: deployments.cursor,
pageMinUpdatedAt: deployments.minUpdatedAt,
cursor: deploymentTrace.cursor,
pageMinUpdatedAt: deploymentTrace.minUpdatedAt,
});

return response;
Expand Down