Skip to content

Commit fed2256

Browse files
authored
fix(meshservice): fix inbound port selecting logic on MeshService (#13108)
## Motivation Fixing an issue on the MeshService updater ## Implementation information > update MeshService updater to take into account target port ## Supporting documentation <!-- Is there a MADR? An Issue? A related PR? --> fixes #12042 <!-- > Changelog: skip --> <!-- Uncomment the above section to explicitly set a [`> Changelog:` entry here](https://github.com/kumahq/kuma/blob/master/CONTRIBUTING.md#submitting-a-patch)? --> --------- Signed-off-by: Jay Chen <[email protected]>
1 parent c90a83b commit fed2256

File tree

4 files changed

+23
-29
lines changed

4 files changed

+23
-29
lines changed

pkg/core/resources/apis/meshservice/match.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package meshservice
22

33
import (
4+
"k8s.io/apimachinery/pkg/util/intstr"
5+
46
mesh_proto "github.com/kumahq/kuma/api/mesh/v1alpha1"
57
core_mesh "github.com/kumahq/kuma/pkg/core/resources/apis/mesh"
68
meshservice_api "github.com/kumahq/kuma/pkg/core/resources/apis/meshservice/api/v1alpha1"
@@ -140,3 +142,13 @@ func matchByTags(
140142
}
141143
return dpps
142144
}
145+
146+
func MatchInboundWithMeshServicePort(inbound *mesh_proto.Dataplane_Networking_Inbound, meshServicePort meshservice_api.Port) bool {
147+
switch meshServicePort.TargetPort.Type {
148+
case intstr.Int:
149+
return uint32(meshServicePort.TargetPort.IntVal) == inbound.Port
150+
case intstr.String:
151+
return meshServicePort.TargetPort.StrVal == inbound.Name
152+
}
153+
return false
154+
}

pkg/core/resources/apis/meshservice/status/updater.go

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ func (s *StatusUpdater) updateStatus(ctx context.Context) error {
165165
func buildDataplaneProxies(
166166
dpps []*core_mesh.DataplaneResource,
167167
insightsByKey map[core_model.ResourceKey]*core_mesh.DataplaneInsightResource,
168-
ports []meshservice_api.Port,
168+
meshServicePorts []meshservice_api.Port,
169169
) meshservice_api.DataplaneProxies {
170170
result := meshservice_api.DataplaneProxies{}
171171
for _, dpp := range dpps {
@@ -176,32 +176,22 @@ func buildDataplaneProxies(
176176
}
177177
}
178178
healthyInbounds := 0
179-
for _, port := range ports {
180-
if inbound := dpInboundForMeshServicePort(dpp.Spec.GetNetworking().Inbound, port); inbound != nil {
181-
if inbound.State == mesh_proto.Dataplane_Networking_Inbound_Ready {
179+
for _, meshServicePort := range meshServicePorts {
180+
for _, dpInbound := range dpp.Spec.GetNetworking().Inbound {
181+
if dpInbound.State == mesh_proto.Dataplane_Networking_Inbound_Ready &&
182+
meshservice.MatchInboundWithMeshServicePort(dpInbound, meshServicePort) {
182183
healthyInbounds++
184+
break
183185
}
184186
}
185187
}
186-
if healthyInbounds == len(ports) {
188+
if healthyInbounds == len(meshServicePorts) {
187189
result.Healthy++
188190
}
189191
}
190192
return result
191193
}
192194

193-
func dpInboundForMeshServicePort(inbounds []*mesh_proto.Dataplane_Networking_Inbound, port meshservice_api.Port) *mesh_proto.Dataplane_Networking_Inbound {
194-
for _, inbound := range inbounds {
195-
if port.Name != "" && inbound.Name == port.Name {
196-
return inbound
197-
}
198-
if port.Port == inbound.Port {
199-
return inbound
200-
}
201-
}
202-
return nil
203-
}
204-
205195
func buildTLS(
206196
existing meshservice_api.TLS,
207197
dpps []*core_mesh.DataplaneResource,

pkg/core/resources/apis/meshservice/status/updater_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,10 +230,10 @@ var _ = Describe("Updater", func() {
230230
Total: 3,
231231
},
232232
}),
233-
Entry("should count healthy DPPs", dpProxiesTestCase{
233+
Entry("should count healthy DPPs and use MeshService.ports[].targetPort to select DP inbound", dpProxiesTestCase{
234234
meshService: samples.MeshServiceBackendBuilder().
235235
WithDataplaneTagsSelectorKV("app", "backend").
236-
AddIntPort(builders.FirstInboundPort+1, builders.FirstInboundServicePort+1, core_mesh.ProtocolHTTP),
236+
AddIntPort(builders.FirstInboundServicePort+1, builders.FirstInboundPort+1, core_mesh.ProtocolHTTP),
237237
dpps: []*builders.DataplaneBuilder{
238238
builders.Dataplane().
239239
WithName("dp-all-inbounds-healthy").

pkg/xds/topology/outbound.go

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88

99
"github.com/asaskevich/govalidator"
1010
"github.com/pkg/errors"
11-
"k8s.io/apimachinery/pkg/util/intstr"
1211

1312
common_tls "github.com/kumahq/kuma/api/common/v1alpha1/tls"
1413
mesh_proto "github.com/kumahq/kuma/api/mesh/v1alpha1"
@@ -339,15 +338,8 @@ func fillLocalMeshServices(
339338
dpNetworking := dpp.Spec.GetNetworking()
340339
for _, inbound := range dpNetworking.GetHealthyInbounds() {
341340
for _, port := range meshSvc.Spec.Ports {
342-
switch port.TargetPort.Type {
343-
case intstr.Int:
344-
if uint32(port.TargetPort.IntVal) != inbound.Port {
345-
continue
346-
}
347-
case intstr.String:
348-
if port.TargetPort.StrVal != inbound.Name {
349-
continue
350-
}
341+
if !meshservice.MatchInboundWithMeshServicePort(inbound, port) {
342+
continue
351343
}
352344

353345
inboundTags := maps.Clone(inbound.GetTags())

0 commit comments

Comments
 (0)