-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Fix Property Override Services parsing #17584
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,7 @@ import ( | |
| envoy_endpoint_v3 "github.com/envoyproxy/go-control-plane/envoy/config/endpoint/v3" | ||
| envoy_listener_v3 "github.com/envoyproxy/go-control-plane/envoy/config/listener/v3" | ||
| envoy_route_v3 "github.com/envoyproxy/go-control-plane/envoy/config/route/v3" | ||
| "github.com/hashicorp/consul/lib/decode" | ||
| "github.com/hashicorp/go-multierror" | ||
| "github.com/mitchellh/mapstructure" | ||
| "google.golang.org/protobuf/proto" | ||
|
|
@@ -73,7 +74,7 @@ func matchesResourceFilter[K proto.Message](rf ResourceFilter, resourceType Reso | |
| } | ||
|
|
||
| type ServiceName struct { | ||
| api.CompoundServiceName | ||
| api.CompoundServiceName `mapstructure:",squash"` | ||
| } | ||
|
|
||
| // ResourceType is the type of Envoy resource being patched. | ||
|
|
@@ -275,7 +276,21 @@ func Constructor(ext api.EnvoyExtension) (extensioncommon.EnvoyExtender, error) | |
| if name := ext.Name; name != api.BuiltinPropertyOverrideExtension { | ||
| return nil, fmt.Errorf("expected extension name %q but got %q", api.BuiltinPropertyOverrideExtension, name) | ||
| } | ||
| if err := mapstructure.WeakDecode(ext.Arguments, &p); err != nil { | ||
| // This avoids issues with decoding nested slices, which are error-prone | ||
| // due to slice<->map coercion by mapstructure. See HookWeakDecodeFromSlice | ||
| // and WeaklyTypedInput docs for more details. | ||
| d, err := mapstructure.NewDecoder(&mapstructure.DecoderConfig{ | ||
| DecodeHook: mapstructure.ComposeDecodeHookFunc( | ||
| decode.HookWeakDecodeFromSlice, | ||
| decode.HookTranslateKeys, | ||
| ), | ||
| WeaklyTypedInput: true, | ||
| Result: &p, | ||
| }) | ||
|
Comment on lines
279
to
289
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd be happy to have someone highly familiar w/ this code review it, since I'm halfway between cargo culting and having a full understanding of these decoder patterns. That said, I'm pretty confident that we need both the hook and The difference between this and the prior version is the inclusion of the Hand-testing indicates normal patching continues to work as expected. |
||
| if err != nil { | ||
| return nil, fmt.Errorf("error configuring decoder: %v", err) | ||
| } | ||
| if err := d.Decode(ext.Arguments); err != nil { | ||
| return nil, fmt.Errorf("error decoding extension arguments: %v", err) | ||
| } | ||
| if err := p.validate(); err != nil { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| # Copyright (c) HashiCorp, Inc. | ||
| # SPDX-License-Identifier: MPL-2.0 | ||
|
|
||
| services { | ||
| name = "s3" | ||
| port = 8181 | ||
| connect { sidecar_service {} } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See https://github.com/mitchellh/mapstructure/blob/bf980b35cac4dfd34e05254ee5aba086504c3f96/mapstructure.go#L37