From 433b448e8d42da70df5d50f4ce667bcb36aeeec2 Mon Sep 17 00:00:00 2001 From: Mikhail Mazurskiy Date: Tue, 8 May 2018 10:01:44 +1000 Subject: [PATCH] Remove int support from json patches --- .../pkg/util/jsonmergepatch/patch.go | 2 +- .../apimachinery/pkg/util/mergepatch/util.go | 2 +- .../pkg/util/mergepatch/util_test.go | 60 +++++++++---------- .../pkg/util/strategicpatch/patch.go | 2 +- 4 files changed, 32 insertions(+), 34 deletions(-) diff --git a/staging/src/k8s.io/apimachinery/pkg/util/jsonmergepatch/patch.go b/staging/src/k8s.io/apimachinery/pkg/util/jsonmergepatch/patch.go index 82e4b4b5704..e56e177341b 100644 --- a/staging/src/k8s.io/apimachinery/pkg/util/jsonmergepatch/patch.go +++ b/staging/src/k8s.io/apimachinery/pkg/util/jsonmergepatch/patch.go @@ -136,7 +136,7 @@ func keepOrDeleteNullInObj(m map[string]interface{}, keepNull bool) (map[string] filteredMap[key] = filteredSubMap } - case []interface{}, string, float64, bool, int, int64, nil: + case []interface{}, string, float64, bool, int64, nil: // Lists are always replaced in Json, no need to check each entry in the list. if !keepNull { filteredMap[key] = val diff --git a/staging/src/k8s.io/apimachinery/pkg/util/mergepatch/util.go b/staging/src/k8s.io/apimachinery/pkg/util/mergepatch/util.go index 9261290a76c..d09a939be30 100644 --- a/staging/src/k8s.io/apimachinery/pkg/util/mergepatch/util.go +++ b/staging/src/k8s.io/apimachinery/pkg/util/mergepatch/util.go @@ -125,7 +125,7 @@ func HasConflicts(left, right interface{}) (bool, error) { default: return true, nil } - case string, float64, bool, int, int64, nil: + case string, float64, bool, int64, nil: return !reflect.DeepEqual(left, right), nil default: return true, fmt.Errorf("unknown type: %v", reflect.TypeOf(left)) diff --git a/staging/src/k8s.io/apimachinery/pkg/util/mergepatch/util_test.go b/staging/src/k8s.io/apimachinery/pkg/util/mergepatch/util_test.go index 1b37e3ef5e0..e74dfabd4f9 100644 --- a/staging/src/k8s.io/apimachinery/pkg/util/mergepatch/util_test.go +++ b/staging/src/k8s.io/apimachinery/pkg/util/mergepatch/util_test.go @@ -30,82 +30,80 @@ func TestHasConflicts(t *testing.T) { {A: "hello", B: "hello", Ret: false}, {A: "hello", B: "hell", Ret: true}, {A: "hello", B: nil, Ret: true}, - {A: "hello", B: 1, Ret: true}, + {A: "hello", B: int64(1), Ret: true}, {A: "hello", B: float64(1.0), Ret: true}, {A: "hello", B: false, Ret: true}, - {A: 1, B: 1, Ret: false}, + {A: int64(1), B: int64(1), Ret: false}, {A: nil, B: nil, Ret: false}, {A: false, B: false, Ret: false}, {A: float64(3), B: float64(3), Ret: false}, {A: "hello", B: []interface{}{}, Ret: true}, - {A: []interface{}{1}, B: []interface{}{}, Ret: true}, + {A: []interface{}{int64(1)}, B: []interface{}{}, Ret: true}, {A: []interface{}{}, B: []interface{}{}, Ret: false}, - {A: []interface{}{1}, B: []interface{}{1}, Ret: false}, - {A: map[string]interface{}{}, B: []interface{}{1}, Ret: true}, + {A: []interface{}{int64(1)}, B: []interface{}{int64(1)}, Ret: false}, + {A: map[string]interface{}{}, B: []interface{}{int64(1)}, Ret: true}, - {A: map[string]interface{}{}, B: map[string]interface{}{"a": 1}, Ret: false}, - {A: map[string]interface{}{"a": 1}, B: map[string]interface{}{"a": 1}, Ret: false}, - {A: map[string]interface{}{"a": 1}, B: map[string]interface{}{"a": 2}, Ret: true}, - {A: map[string]interface{}{"a": 1}, B: map[string]interface{}{"b": 2}, Ret: false}, + {A: map[string]interface{}{}, B: map[string]interface{}{"a": int64(1)}, Ret: false}, + {A: map[string]interface{}{"a": int64(1)}, B: map[string]interface{}{"a": int64(1)}, Ret: false}, + {A: map[string]interface{}{"a": int64(1)}, B: map[string]interface{}{"a": int64(2)}, Ret: true}, + {A: map[string]interface{}{"a": int64(1)}, B: map[string]interface{}{"b": int64(2)}, Ret: false}, { - A: map[string]interface{}{"a": []interface{}{1}}, - B: map[string]interface{}{"a": []interface{}{1}}, + A: map[string]interface{}{"a": []interface{}{int64(1)}}, + B: map[string]interface{}{"a": []interface{}{int64(1)}}, Ret: false, }, { - A: map[string]interface{}{"a": []interface{}{1}}, + A: map[string]interface{}{"a": []interface{}{int64(1)}}, B: map[string]interface{}{"a": []interface{}{}}, Ret: true, }, { - A: map[string]interface{}{"a": []interface{}{1}}, - B: map[string]interface{}{"a": 1}, + A: map[string]interface{}{"a": []interface{}{int64(1)}}, + B: map[string]interface{}{"a": int64(1)}, Ret: true, }, // Maps and lists with multiple entries. { - A: map[string]interface{}{"a": 1, "b": 2}, - B: map[string]interface{}{"a": 1, "b": 0}, + A: map[string]interface{}{"a": int64(1), "b": int64(2)}, + B: map[string]interface{}{"a": int64(1), "b": int64(0)}, Ret: true, }, { - A: map[string]interface{}{"a": 1, "b": 2}, - B: map[string]interface{}{"a": 1, "b": 2}, + A: map[string]interface{}{"a": int64(1), "b": int64(2)}, + B: map[string]interface{}{"a": int64(1), "b": int64(2)}, Ret: false, }, { - A: map[string]interface{}{"a": 1, "b": 2}, - B: map[string]interface{}{"a": 1, "b": 0, "c": 3}, + A: map[string]interface{}{"a": int64(1), "b": int64(2)}, + B: map[string]interface{}{"a": int64(1), "b": int64(0), "c": int64(3)}, Ret: true, }, { - A: map[string]interface{}{"a": 1, "b": 2}, - B: map[string]interface{}{"a": 1, "b": 2, "c": 3}, + A: map[string]interface{}{"a": int64(1), "b": int64(2)}, + B: map[string]interface{}{"a": int64(1), "b": int64(2), "c": int64(3)}, Ret: false, }, { - A: map[string]interface{}{"a": []interface{}{1, 2}}, - B: map[string]interface{}{"a": []interface{}{1, 0}}, + A: map[string]interface{}{"a": []interface{}{int64(1), int64(2)}}, + B: map[string]interface{}{"a": []interface{}{int64(1), int64(0)}}, Ret: true, }, { - A: map[string]interface{}{"a": []interface{}{1, 2}}, - B: map[string]interface{}{"a": []interface{}{1, 2}}, + A: map[string]interface{}{"a": []interface{}{int64(1), int64(2)}}, + B: map[string]interface{}{"a": []interface{}{int64(1), int64(2)}}, Ret: false, }, // Numeric types are not interchangeable. // Callers are expected to ensure numeric types are consistent in 'left' and 'right'. - {A: int(0), B: int64(0), Ret: true}, - {A: int(0), B: float64(0), Ret: true}, {A: int64(0), B: float64(0), Ret: true}, // Other types are not interchangeable. - {A: int(0), B: "0", Ret: true}, - {A: int(0), B: nil, Ret: true}, - {A: int(0), B: false, Ret: true}, + {A: int64(0), B: "0", Ret: true}, + {A: int64(0), B: nil, Ret: true}, + {A: int64(0), B: false, Ret: true}, {A: "true", B: true, Ret: true}, {A: "null", B: nil, Ret: true}, } diff --git a/staging/src/k8s.io/apimachinery/pkg/util/strategicpatch/patch.go b/staging/src/k8s.io/apimachinery/pkg/util/strategicpatch/patch.go index 6be328f74a2..ddf998172c0 100644 --- a/staging/src/k8s.io/apimachinery/pkg/util/strategicpatch/patch.go +++ b/staging/src/k8s.io/apimachinery/pkg/util/strategicpatch/patch.go @@ -1876,7 +1876,7 @@ func mergingMapFieldsHaveConflicts( return true, nil } return slicesHaveConflicts(leftType, rightType, schema, fieldPatchStrategy, fieldPatchMergeKey) - case string, float64, bool, int, int64, nil: + case string, float64, bool, int64, nil: return !reflect.DeepEqual(left, right), nil default: return true, fmt.Errorf("unknown type: %v", reflect.TypeOf(left))