Conversation
Summary of ChangesHello @Abirdcfly, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request resolves a critical bug in the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
There was a problem hiding this comment.
Code Review
This pull request addresses a panic caused by accessing an empty Spec.Gateways slice in a virtual service. The fix correctly adds a bounds check before accessing the slice. My review includes a suggestion to further improve the logic by iterating through all gateways in the list, rather than just checking the first one, to ensure correct behavior when a virtual service is associated with multiple gateways.
| if len(vs.Spec.Gateways) > 0 && vs.Spec.Gateways[0] == srv.options.GwName && | ||
| reflect.DeepEqual(vs.Spec.Hosts, srv.options.Hosts) { | ||
| vss = append(vss, vs) | ||
| } |
There was a problem hiding this comment.
While your change correctly prevents the panic, it only considers the first gateway listed in vs.Spec.Gateways. A VirtualService can be bound to multiple gateways, and this implementation will fail to find a match if the intended gateway is not the first in the list.
To make the logic more robust and align with the intended behavior of virtual services, I suggest iterating over the vs.Spec.Gateways slice to check for a match.
for _, gw := range vs.Spec.Gateways {
if gw == srv.options.GwName && reflect.DeepEqual(vs.Spec.Hosts, srv.options.Hosts) {
vss = append(vss, vs)
break
}
}Signed-off-by: Abirdcfly <fp544037857@gmail.com>
What type of PR is this?
/kind bug
What this PR does / why we need it:
I1010 16:32:46.078267 1 tunnel.go:131] [MDNS] Discovery found peer: {12D3KooWFzqKr5PhTuKCsry9Cyo3DtvMDrK5HenyTfRMzDgyCraL: [/ip4/172.31.10.125/tcp/20006 /ip4/169.254.25.10/tcp/20006 /ip4/127.0.0.1/tcp/20006 /ip4/10.62.48.116/tcp/20006]} panic: runtime error: index out of range [0] with length 0 goroutine 764 [running]: github.com/kubeedge/edgemesh/pkg/gateway.(*Server).newProto.func1({0x3b01d68?, 0x1f55d80?}, {0x2153880?, 0xc0008ee880?}) /code/pkg/gateway/server.go:164 +0x1a7 sync.(*Map).Range(0x3b01d60?, 0xc000717b38) /usr/local/go/src/sync/map.go:354 +0x2b8 github.com/kubeedge/edgemesh/pkg/gateway/cache.RangeVirtualServices(...) /code/pkg/gateway/cache/cache.go:73 github.com/kubeedge/edgemesh/pkg/gateway.(*Server).newProto(0xc00066d5f0, {0x2737c98?, 0xc00037a078}) /code/pkg/gateway/server.go:171 +0xa6 github.com/kubeedge/edgemesh/pkg/gateway.(*Server).serve(0xc00066d5f0) /code/pkg/gateway/server.go:142 +0x925 created by github.com/kubeedge/edgemesh/pkg/gateway.NewServer /code/pkg/gateway/server.go:68 +0x165when there is a gw that Spec.Gateways is empty, there is a panic, note this gateway may not related with kubeedge, it is may just normal istio gateway
Which issue(s) this PR fixes:
Fixes #
Special notes for your reviewer:
Does this PR introduce a user-facing change?: