Skip to content

Commit

Permalink
Fix mergo bug
Browse files Browse the repository at this point in the history
By default mergo doesn't allow merging a non empty value with an
empty value. For example if a field is a string "hello" it would not
override it, if the to be merged object contains the same field with "".

This works well until someone wants to override a true boolean with a
false boolean, in which case the merge doesn't happen.

By setting `mergo.WithOverwriteWithEmptyValue`, we can force mergo to
merge empty values into noni empty values.

darccio/mergo#249
  • Loading branch information
Kidswiss committed Mar 5, 2024
1 parent 9d2837b commit e8da38e
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions pkg/comp-functions/functions/vshnkeycloak/deploy.go
Expand Up @@ -161,16 +161,12 @@ func addPostgreSQL(svc *runtime.ServiceRuntime, comp *vshnv1.VSHNKeycloak) error
}

if comp.Spec.Parameters.Service.PostgreSQLParameters != nil {
err := mergo.Merge(params, comp.Spec.Parameters.Service.PostgreSQLParameters, mergo.WithOverride)
// Mergo currently has a bug with merging bools: https://github.com/darccio/mergo/issues/249
// We need to pass `mergo.WithOverwriteWithEmptyValue` to override a boolean from true to false.
err := mergo.Merge(params, comp.Spec.Parameters.Service.PostgreSQLParameters, mergo.WithOverwriteWithEmptyValue)
if err != nil {
return err
}

// Mergo currently has a bug with merging bools: https://github.com/darccio/mergo/issues/249
// It's not possible to override true with false, so it won't merge this if the users disables it.
if !comp.Spec.Parameters.Service.PostgreSQLParameters.Backup.DeletionProtection {
params.Backup.DeletionProtection = false
}
}

pg := &vshnv1.XVSHNPostgreSQL{
Expand Down

0 comments on commit e8da38e

Please sign in to comment.