Skip to content

Commit

Permalink
fix(*) fix builtin gateway when adding to insights (#2980)
Browse files Browse the repository at this point in the history
* fix(*) fix builtin gateway when adding to insights

As according to our validators
(https://github.com/kumahq/kuma/blob/c89ac43e1d46a16ad37f8898dbd932cda4b034dd/pkg/core/resources/apis/mesh/dataplane_validator.go#L34-L63)
both gateways (delegated and builtin) cannot contain inbounds
I added builtin gateway to skip trying to add its inbounds to the
dataplane list of insight resources.

I also refactored this parts of code to use protobuf's builtin
associate `Get[...]` functions which handles nils better (i.e.
in `dpOverview.Spec.GetDataplane().GetNetworking()` if
`dpOverview.Spec.Dataplane` will be `nil` it won't crash.

Also removed nested if statement and used `continue` to skip
to the next loop iteration instead of using `else` branch.

Signed-off-by: Bart Smykla <bartek@smykla.com>
  • Loading branch information
bartsmykla authored Oct 20, 2021
1 parent 4461e71 commit f131b07
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions pkg/insights/resyncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,15 +213,14 @@ func (r *resyncer) createOrUpdateServiceInsight(mesh string) error {

for _, dpOverview := range dpOverviews.Items {
status, _ := dpOverview.GetStatus()
networking := dpOverview.Spec.GetDataplane().GetNetworking()

// Builtin gateways have inbounds
if dpOverview.Spec.Dataplane.IsDelegatedGateway() {
svcName := dpOverview.Spec.Dataplane.Networking.GetGateway().GetTags()[mesh_proto.ServiceTag]
addDpToInsight(insight, svcName, status)
} else {
for _, inbound := range dpOverview.Spec.Dataplane.Networking.Inbound {
addDpToInsight(insight, inbound.GetService(), status)
}
if svc := networking.GetGateway().GetTags()[mesh_proto.ServiceTag]; svc != "" {
addDpToInsight(insight, svc, status)
}

for _, inbound := range networking.GetInbound() {
addDpToInsight(insight, inbound.GetService(), status)
}
}

Expand Down Expand Up @@ -338,14 +337,14 @@ func (r *resyncer) createOrUpdateMeshInsight(mesh string) error {
updateTotal(envoyVersion, insight.DpVersions.Envoy)
updateMTLS(dpInsight.GetMTLS(), status, insight.MTLS)

// Builtin gateways have inbounds
if dpOverview.Spec.Dataplane.IsDelegatedGateway() {
svcName := dpOverview.Spec.Dataplane.Networking.GetGateway().GetTags()[mesh_proto.ServiceTag]
internalServices[svcName] = struct{}{}
} else {
for _, inbound := range dpOverview.Spec.Dataplane.Networking.Inbound {
internalServices[inbound.GetService()] = struct{}{}
}
networking := dpOverview.Spec.GetDataplane().GetNetworking()

if svc := networking.GetGateway().GetTags()[mesh_proto.ServiceTag]; svc != "" {
internalServices[svc] = struct{}{}
}

for _, inbound := range networking.GetInbound() {
internalServices[inbound.GetService()] = struct{}{}
}
}

Expand Down

0 comments on commit f131b07

Please sign in to comment.