Skip to content

Commit

Permalink
Remove unions logic, keep schema components
Browse files Browse the repository at this point in the history
This removes the generally unused union code from the library in a
non-backward incompatible way since the API was not used anyways. The
schema isn't changed since we don't want to break existing schema (the
unions fields will continue to be just ignored).
  • Loading branch information
apelisse committed Oct 25, 2023
1 parent 9c99f49 commit 35d4e8c
Show file tree
Hide file tree
Showing 6 changed files with 0 additions and 938 deletions.
14 changes: 0 additions & 14 deletions internal/fixture/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -535,8 +535,6 @@ type TestCase struct {
// Managed, if not nil, is the ManagedFields as expected
// after all operations are run.
Managed fieldpath.ManagedFields
// Set to true if the test case needs the union behavior enabled.
RequiresUnions bool
// ReportInputOnNoop if we don't want to compare the output and
// always return it.
ReturnInputOnNoop bool
Expand Down Expand Up @@ -576,7 +574,6 @@ func (tc TestCase) BenchWithConverter(parser Parser, converter merge.Converter)
Converter: converter,
IgnoredFields: tc.IgnoredFields,
ReturnInputOnNoop: tc.ReturnInputOnNoop,
EnableUnions: tc.RequiresUnions,
}
state := State{
Updater: updaterBuilder.BuildUpdater(),
Expand All @@ -599,7 +596,6 @@ func (tc TestCase) TestWithConverter(parser Parser, converter merge.Converter) e
Converter: converter,
IgnoredFields: tc.IgnoredFields,
ReturnInputOnNoop: tc.ReturnInputOnNoop,
EnableUnions: tc.RequiresUnions,
}
state := State{
Updater: updaterBuilder.BuildUpdater(),
Expand Down Expand Up @@ -636,15 +632,5 @@ func (tc TestCase) TestWithConverter(parser Parser, converter merge.Converter) e
}
}

if !tc.RequiresUnions {
// Re-run the test with unions on.
tc2 := tc
tc2.RequiresUnions = true
err := tc2.TestWithConverter(parser, converter)
if err != nil {
return fmt.Errorf("fails if unions are on: %v", err)
}
}

return nil
}
234 changes: 0 additions & 234 deletions merge/union_test.go

This file was deleted.

31 changes: 0 additions & 31 deletions merge/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ type UpdaterBuilder struct {
Converter Converter
IgnoredFields map[fieldpath.APIVersion]*fieldpath.Set

EnableUnions bool

// Stop comparing the new object with old object after applying.
// This was initially used to avoid spurious etcd update, but
// since that's vastly inefficient, we've come-up with a better
Expand All @@ -49,7 +47,6 @@ func (u *UpdaterBuilder) BuildUpdater() *Updater {
return &Updater{
Converter: u.Converter,
IgnoredFields: u.IgnoredFields,
enableUnions: u.EnableUnions,
returnInputOnNoop: u.ReturnInputOnNoop,
}
}
Expand All @@ -63,19 +60,9 @@ type Updater struct {
// Deprecated: This will eventually become private.
IgnoredFields map[fieldpath.APIVersion]*fieldpath.Set

enableUnions bool

returnInputOnNoop bool
}

// EnableUnionFeature turns on union handling. It is disabled by default until the
// feature is complete.
//
// Deprecated: Use the builder instead.
func (s *Updater) EnableUnionFeature() {
s.enableUnions = true
}

func (s *Updater) update(oldObject, newObject *typed.TypedValue, version fieldpath.APIVersion, managers fieldpath.ManagedFields, workflow string, force bool) (fieldpath.ManagedFields, *typed.Comparison, error) {
conflicts := fieldpath.ManagedFields{}
removed := fieldpath.ManagedFields{}
Expand Down Expand Up @@ -160,12 +147,6 @@ func (s *Updater) Update(liveObject, newObject *typed.TypedValue, version fieldp
if err != nil {
return nil, fieldpath.ManagedFields{}, err
}
if s.enableUnions {
newObject, err = liveObject.NormalizeUnions(newObject)
if err != nil {
return nil, fieldpath.ManagedFields{}, err
}
}
managers, compare, err := s.update(liveObject, newObject, version, managers, manager, true)
if err != nil {
return nil, fieldpath.ManagedFields{}, err
Expand Down Expand Up @@ -198,22 +179,10 @@ func (s *Updater) Apply(liveObject, configObject *typed.TypedValue, version fiel
if err != nil {
return nil, fieldpath.ManagedFields{}, err
}
if s.enableUnions {
configObject, err = configObject.NormalizeUnionsApply(configObject)
if err != nil {
return nil, fieldpath.ManagedFields{}, err
}
}
newObject, err := liveObject.Merge(configObject)
if err != nil {
return nil, fieldpath.ManagedFields{}, fmt.Errorf("failed to merge config: %v", err)
}
if s.enableUnions {
newObject, err = configObject.NormalizeUnionsApply(newObject)
if err != nil {
return nil, fieldpath.ManagedFields{}, err
}
}
lastSet := managers[manager]
set, err := configObject.ToFieldSet()
if err != nil {
Expand Down
Loading

0 comments on commit 35d4e8c

Please sign in to comment.