From 8443f342fd5368931696363c0d16fc11eb14f5d9 Mon Sep 17 00:00:00 2001 From: Joe Betz Date: Wed, 30 Sep 2020 18:55:21 -0700 Subject: [PATCH] Fix noop granular case for atomic<->granular schema changes --- typed/reconcile_schema.go | 7 ++++--- typed/reconcile_schema_test.go | 23 +++++++++++++++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/typed/reconcile_schema.go b/typed/reconcile_schema.go index fa67714c..5a8214ae 100644 --- a/typed/reconcile_schema.go +++ b/typed/reconcile_schema.go @@ -258,12 +258,13 @@ func buildGranularFieldSet(path fieldpath.Path, value *TypedValue) (*fieldpath.S if err != nil { return nil, errorf("toFieldSet: %v", err) } - result := fieldpath.NewSet(path) - resultAtPath := descendToPath(result, path) if valueFieldSetAtPath, ok := fieldSetAtPath(valueFieldSet, path); ok { + result := fieldpath.NewSet(path) + resultAtPath := descendToPath(result, path) *resultAtPath = *valueFieldSetAtPath + return result, nil } - return result, nil + return nil, nil } func fieldSetAtPath(node *fieldpath.Set, path fieldpath.Path) (*fieldpath.Set, bool) { diff --git a/typed/reconcile_schema_test.go b/typed/reconcile_schema_test.go index 29d30719..c4171412 100644 --- a/typed/reconcile_schema_test.go +++ b/typed/reconcile_schema_test.go @@ -267,6 +267,29 @@ var reconcileCases = []reconcileTestCase{{ _P("unchanged", "numeric"), ), fixedFields: nil, // indicates no change +}, { + name: "no-change-empty-granular", + rootTypeName: "v1", + oldSchema: granularSchema("v1"), + newSchema: granularSchema("v1"), + liveObject: typed.YAMLObject(` +struct: {} +list: [] +objectList: + - keyA: a1 + keyB: b1 +stringMap: {} +unchanged: {} +`), + oldFields: _NS( + _P("struct"), + _P("list"), + _P("objectList"), + _P("objectList", _KBF("keyA", "a1", "keyB", "b1")), + _P("objectList", _KBF("keyA", "a1", "keyB", "b1"), "value"), + _P("unchanged"), + ), + fixedFields: nil, // indicates no change }} func TestReconcileFieldSetWithSchema(t *testing.T) {