fix(status): omit waypoint in service dump when none is configured - #1915
AswaniSahoo wants to merge 2 commits into
Conversation
|
[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 |
|
Welcome @AswaniSahoo! It looks like this is your first PR to kmesh-net/kmesh 🎉 |
There was a problem hiding this comment.
Pull request overview
Fixes the status API service conversion so that services with no configured waypoint marshal "waypoint": null (instead of a waypoint object with an empty destination), aligning the JSON shape with how loadBalancer is represented and avoiding ambiguous client-side interpretation.
Changes:
- Update
ConvertServiceto only allocate/setService.Waypointwhen a non-empty waypoint destination is present. - Add
pkg/status/api_test.goto cover waypoint conversion cases and verify the resulting marshaled JSON shape (plus basicvips/loadBalancerconversion).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| pkg/status/api.go | Conditionally sets Waypoint only when a real destination is present, so JSON shows null when absent. |
| pkg/status/api_test.go | Adds unit tests for waypoint conversion and JSON output shape for absent vs present waypoint. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| assert.Contains(t, decoded, "waypoint") | ||
| assert.Nil(t, decoded["waypoint"]) | ||
| assert.Nil(t, decoded["loadBalancer"]) |
There was a problem hiding this comment.
Good catch. assert.Nil on a missing key passes for the wrong reason, so that test would have stayed green even if loadBalancer had been dropped entirely. Added the assert.Contains before it so presence is checked first, the same way the waypoint assertion above already does. Pushed in 6e45bea.
Codecov Report✅ All modified and coverable lines are covered by tests.
... and 3 files with indirect coverage changes Continue to review full report in Codecov by Harness.
🚀 New features to boost your workflow:
|
|
Saw this on a live cluster today, not just from reading kind with istio in ambient mode and kmesh in dual-engine, using the published image. Three services, none of them with a waypoint or a load balancer configured: So every service on a default install carries the empty waypoint object, and a client still has to check for the empty string to know there is no waypoint. Happy to share the setup if that is useful. |
| for _, tc := range testcases { | ||
| t.Run(tc.name, func(t *testing.T) { | ||
| got := ConvertService(&workloadapi.Service{ | ||
| Name: "productpage", | ||
| Namespace: "default", | ||
| Hostname: "productpage.default.svc.cluster.local", | ||
| Waypoint: tc.waypoint, | ||
| }) | ||
| assert.Equal(t, tc.expect, got.Waypoint) | ||
| }) | ||
| } |
| // service without load balancing already serialises loadBalancer as null. | ||
| // Otherwise a consumer cannot tell "no waypoint" apart from "waypoint whose | ||
| // destination happens to be empty". | ||
| func TestConvertServiceOmitsEmptyWaypointInJSON(t *testing.T) { |
| data, err := json.Marshal(got) | ||
| assert.NoError(t, err) | ||
|
|
||
| var decoded map[string]interface{} | ||
| assert.NoError(t, json.Unmarshal(data, &decoded)) |
Signed-off-by: AswaniSahoo <aswanisahoo1012@gmail.com>
…it is null Signed-off-by: AswaniSahoo <aswanisahoo1012@gmail.com>
5d3cd67 to
21f90c1
Compare
|
@hzxuzhonghu @Okabe-Rintarou-0 Could you please take a look at this PR when you get a chance? Regarding the single failing CI check ( Could you please trigger a |
|
@hzxuzhonghu @Okabe-Rintarou-0 Could you please take a look at this PR when you get a chance? Regarding the single failing CI check ( Could you please trigger a |
What type of PR is this?
/kind bug
What this PR does / why we need it:
ConvertServicealways allocates aWaypoint, even when the service does not have one. TheLoadBalancerbranch three lines below already guards for the empty case, andConvertWorkloadusesomitemptyfor the same concept. So a service with neither currently dumps as:Two optional fields, two different shapes. A client reading the dump cannot tell "no waypoint" from "a waypoint whose destination happens to be empty" without special-casing the empty string.
This guards the waypoint the same way
s.LoadBalancingis guarded immediately below, so it serialises asnull.Also adds
pkg/status/api_test.go, which the package did not have. It covers the three waypoint cases (absent, by address, by hostname), the resulting JSON shape, and thevipsandloadBalancerconversion.How I found it:
I was building an MCP client against
/debug/config_dump/dual-engineand shaping test fixtures from the marshalled output. I wanted to list the services routed through a waypoint, checked fornull, and got nothing back because every service had a waypoint object. Traced it toConvertService.Which issue(s) this PR fixes:
None, found while reading the code.
Special notes for your reviewer:
I could not run
go test ./pkg/status/...locally. The package reaches the bpf2go packages that//go:embedthe compiled.oartifacts, and those are not in the tree, so it does not build outside a full eBPF build. I checked the test's types, enum names and assertions against the realworkloadapitypes in a scratch harness and am relying on CI for the real run. Flagging it rather than implying I ran it.If you would rather keep emitting the object for compatibility, I am happy to drop the
api.gochange and keep the tests documenting the current behaviour instead.Does this PR introduce a user-facing change?: