-
-
Notifications
You must be signed in to change notification settings - Fork 276
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merge is broken for structs with slices #33
Comments
For context on the importance of this bug, it completely breaks the configuration merging in kubernetes. |
Merging is buggy in master: darccio/mergo#33
Which suggests that the change was intentional but unfortunately completely breaks kubernetes' usage of Merge. |
I'm going to check this as soon as possible, although I'm sorry that won't be today. The change you point was intentional. Here is why:
|
First of all, sorry. Second, I will take care of this this next week. |
@imdario Status? |
I finally got time to read this issue carefully (as they are usually tricky because Mergo isn't so simple as it looks!). I wrote a test to offer a solution for this: package mergo
import (
"testing"
)
type Foo struct {
Str string
Bslice []byte
}
func TestIssue33Merge(t *testing.T) {
dest := Foo{Str: "a"}
toMerge := Foo{
Str: "b",
Bslice: []byte{1, 2},
}
if err := Merge(&dest, toMerge); err != nil {
t.Errorf("Error while merging: %s", err)
}
// Merge doesn't overwrite an attribute if in destination it doesn't have a zero value.
// In this case, Str isn't a zero value string.
if dest.Str != "a" {
t.Errorf("dest.Str should have not been override as it has a non-zero value: dest.Str(%v) != 'a'", dest.Str)
}
// If we want to override, we must use MergeWithOverwrite or Merge using WithOverride.
if err := Merge(&dest, toMerge, WithOverride); err != nil {
t.Errorf("Error while merging: %s", err)
}
if dest.Str != toMerge.Str {
t.Errorf("dest.Str should have been override: dest.Str(%v) != toMerge.Str(%v)", dest.Str, toMerge.Str)
}
} I hope @2opremio and Kubernetes' crew can use the last release available (0.3.0 as we speak). |
I since moved to other endeavors, but thanks for the effort! |
This change aligns the istioctl client config merging logic with kubectl. kubectl uses an older version of github.com/imdario/mergo where the Merge() function overwrites existing values. istioctl uses a newer version which doesn't (see linked issues below). This manifests in the k8s client loading code with multiple config sources not being merged properly. Longer term fix would be to update kubectl and k8s.io/client-go to use the latest version of github.com/imdario/mergo. Fixes istio#4938 Related upstream kubernetes issues: - darccio/mergo#33 (comment) - kubernetes/kubernetes#27543 - kubernetes/kubernetes#23789
This change aligns the istioctl client config merging logic with kubectl. kubectl uses an older version of github.com/imdario/mergo where the Merge() function overwrites existing values. istioctl uses a newer version which doesn't (see linked issues below). This manifests in the k8s client loading code with multiple config sources not being merged properly. Longer term fix would be to update kubectl and k8s.io/client-go to use the latest version of github.com/imdario/mergo. Fixes #4938 Related upstream kubernetes issues: - darccio/mergo#33 (comment) - kubernetes/kubernetes#27543 - kubernetes/kubernetes#23789
At some point after 6633656 (the version currently vendored by kubernetes, which works fine), merging broke for structs containing byteslices.
Here's a simplificed repro
The text was updated successfully, but these errors were encountered: