Skip to content

Commit 2045cd8

Browse files
committed
Unsupport atomic to granular
1 parent f503776 commit 2045cd8

File tree

3 files changed

+6
-121
lines changed

3 files changed

+6
-121
lines changed

merge/schema_change_test.go

Lines changed: 0 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -178,75 +178,3 @@ func TestGranularToAtomicSchemaChanges(t *testing.T) {
178178
})
179179
}
180180
}
181-
182-
func TestAtomicToGranularSchemaChanges(t *testing.T) {
183-
tests := map[string]TestCase{
184-
"to-granular": {
185-
Ops: []Operation{
186-
Apply{
187-
Manager: "one",
188-
Object: `
189-
struct:
190-
numeric: 1
191-
string: "a"
192-
`,
193-
APIVersion: "v1",
194-
},
195-
Apply{
196-
Manager: "two",
197-
Object: `
198-
struct:
199-
string: "b"
200-
`,
201-
APIVersion: "v1",
202-
Conflicts: merge.Conflicts{
203-
merge.Conflict{Manager: "one", Path: _P("struct")},
204-
},
205-
},
206-
ChangeParser{Parser: structParser},
207-
Apply{
208-
Manager: "two",
209-
Object: `
210-
struct:
211-
string: "b"
212-
`,
213-
APIVersion: "v1",
214-
Conflicts: merge.Conflicts{
215-
merge.Conflict{Manager: "one", Path: _P("struct", "string")},
216-
},
217-
},
218-
ForceApply{
219-
Manager: "two",
220-
Object: `
221-
struct:
222-
string: "b"
223-
`,
224-
APIVersion: "v1",
225-
},
226-
},
227-
Object: `
228-
struct:
229-
numeric: 1
230-
string: "b"
231-
`,
232-
APIVersion: "v1",
233-
Managed: fieldpath.ManagedFields{
234-
"one": fieldpath.NewVersionedSet(_NS(
235-
_P("struct"),
236-
_P("struct", "numeric"),
237-
), "v1", true),
238-
"two": fieldpath.NewVersionedSet(_NS(
239-
_P("struct", "string"),
240-
), "v1", true),
241-
},
242-
},
243-
}
244-
245-
for name, test := range tests {
246-
t.Run(name, func(t *testing.T) {
247-
if err := test.Test(structWithAtomicParser); err != nil {
248-
t.Fatal(err)
249-
}
250-
})
251-
}
252-
}

typed/reconcile_schema.go

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -187,19 +187,14 @@ func (v *reconcileWithSchemaWalker) visitListItems(t *schema.List, element *fiel
187187
}
188188

189189
func (v *reconcileWithSchemaWalker) doList(t *schema.List) (errs ValidationErrors) {
190-
// reconcile lists changed from granular to atomic
190+
// reconcile lists changed from granular to atomic.
191+
// Note that migrations from atomic to granular are unsuported and will
192+
// be treated as if they were always granular.
191193
if !v.isAtomic && t.ElementRelationship == schema.Atomic {
192194
v.toRemove = fieldpath.NewSet(v.path) // remove all root and all children fields
193195
v.toAdd = fieldpath.NewSet(v.path) // add the root of the atomic
194196
return errs
195197
}
196-
// reconcile lists changed from atomic to granular
197-
if v.isAtomic && t.ElementRelationship == schema.Associative {
198-
v.toAdd, errs = buildGranularFieldSet(v.path, v.value)
199-
if errs != nil {
200-
return errs
201-
}
202-
}
203198
if v.fieldSet != nil {
204199
errs = v.visitListItems(t, v.fieldSet)
205200
}
@@ -231,21 +226,16 @@ func (v *reconcileWithSchemaWalker) visitMapItems(t *schema.Map, element *fieldp
231226
}
232227

233228
func (v *reconcileWithSchemaWalker) doMap(t *schema.Map) (errs ValidationErrors) {
234-
// reconcile maps and structs changed from granular to atomic
229+
// reconcile maps and structs changed from granular to atomic.
230+
// Note that migrations from atomic to granular are unsuported and will
231+
// be treated as if they were always granular.
235232
if !v.isAtomic && t.ElementRelationship == schema.Atomic {
236233
if v.fieldSet != nil && v.fieldSet.Size() > 0 {
237234
v.toRemove = fieldpath.NewSet(v.path) // remove all root and all children fields
238235
v.toAdd = fieldpath.NewSet(v.path) // add the root of the atomic
239236
}
240237
return errs
241238
}
242-
// reconcile maps changed from atomic to granular
243-
if v.isAtomic && (t.ElementRelationship == schema.Separable || t.ElementRelationship == "") {
244-
v.toAdd, errs = buildGranularFieldSet(v.path, v.value)
245-
if errs != nil {
246-
return errs
247-
}
248-
}
249239
if v.fieldSet != nil {
250240
errs = v.visitMapItems(t, v.fieldSet)
251241
}

typed/reconcile_schema_test.go

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -207,39 +207,6 @@ var reconcileCases = []reconcileTestCase{{
207207
_P("stringMap"),
208208
_P("unchanged", "numeric"),
209209
),
210-
}, {
211-
name: "atomic-to-granular",
212-
rootTypeName: "v1",
213-
oldSchema: atomicSchema("v1"),
214-
newSchema: granularSchema("v1"),
215-
liveObject: basicLiveObject,
216-
oldFields: _NS(
217-
_P("struct"),
218-
_P("list"),
219-
_P("objectList"),
220-
_P("stringMap"),
221-
_P("unchanged", "numeric"),
222-
),
223-
fixedFields: _NS(
224-
_P("struct"),
225-
_P("struct", "numeric"),
226-
_P("struct", "string"),
227-
_P("list"),
228-
_P("list", _V("one")),
229-
_P("list", _V("two")),
230-
_P("objectList"),
231-
_P("objectList", _KBF("keyA", "a1", "keyB", "b1")),
232-
_P("objectList", _KBF("keyA", "a1", "keyB", "b1"), "value"),
233-
_P("objectList", _KBF("keyA", "a1", "keyB", "b1"), "keyA"),
234-
_P("objectList", _KBF("keyA", "a1", "keyB", "b1"), "keyB"),
235-
_P("objectList", _KBF("keyA", "a2", "keyB", "b2")),
236-
_P("objectList", _KBF("keyA", "a2", "keyB", "b2"), "value"),
237-
_P("objectList", _KBF("keyA", "a2", "keyB", "b2"), "keyA"),
238-
_P("objectList", _KBF("keyA", "a2", "keyB", "b2"), "keyB"),
239-
_P("stringMap"),
240-
_P("stringMap", "key1"),
241-
_P("unchanged", "numeric"),
242-
),
243210
}, {
244211
name: "no-change-granular",
245212
rootTypeName: "v1",

0 commit comments

Comments
 (0)