Skip to content
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

fix(*) fix builtin gateway when adding to insights #2980

Merged

Conversation

bartsmykla
Copy link
Contributor

@bartsmykla bartsmykla commented Oct 20, 2021

Summary

As according to our validators

case d.Spec.IsDelegatedGateway():
if len(d.Spec.GetNetworking().GetInbound()) > 0 {
err.AddViolationAt(net.Field("inbound"),
"inbound cannot be defined for delegated gateways")
}
err.AddErrorAt(net.Field("gateway"), validateGateway(d.Spec.GetNetworking().GetGateway()))
err.Add(validateNetworking(d.Spec.GetNetworking()))
err.Add(validateProbes(d.Spec.GetProbes()))
case d.Spec.IsBuiltinGateway():
if !allowBuiltinGateways {
err.AddViolationAt(net.Field("gateway"), "unsupported gateway type")
return err.OrNil()
}
if len(d.Spec.GetNetworking().GetInbound()) > 0 {
err.AddViolationAt(net.Field("inbound"), "inbound cannot be defined for builtin gateways")
}
if len(d.Spec.GetNetworking().GetOutbound()) > 0 {
err.AddViolationAt(net.Field("outbound"), "outbound cannot be defined for builtin gateways")
}
if d.Spec.GetProbes() != nil {
err.AddViolationAt(net.Field("probes"), "probes cannot be defined for builtin gateways")
}
err.AddErrorAt(net.Field("gateway"), validateGateway(d.Spec.GetNetworking().GetGateway()))
err.Add(validateNetworking(d.Spec.GetNetworking()))

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.

Full changelog

n/a

Issues resolved

n/a

Documentation

n/a

Testing

  • Unit tests
  • E2E tests
  • Manual testing on Universal
  • Manual testing on Kubernetes

Backwards compatibility

  • Add backport-to-stable label if the code is backwards compatible. Otherwise, list breaking changes.

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>
@bartsmykla bartsmykla requested a review from a team as a code owner October 20, 2021 05:07
pkg/insights/resyncer.go Outdated Show resolved Hide resolved
Signed-off-by: Bart Smykla <bartek@smykla.com>
Signed-off-by: Bart Smykla <bartek@smykla.com>
Signed-off-by: Bart Smykla <bartek@smykla.com>
Copy link
Contributor

@jpeach jpeach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice.

@codecov-commenter
Copy link

Codecov Report

Merging #2980 (e6e3bda) into master (704c57c) will increase coverage by 0.05%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2980      +/-   ##
==========================================
+ Coverage   52.33%   52.38%   +0.05%     
==========================================
  Files         912      912              
  Lines       52583    52581       -2     
==========================================
+ Hits        27517    27546      +29     
+ Misses      22876    22837      -39     
- Partials     2190     2198       +8     
Impacted Files Coverage Δ
pkg/insights/resyncer.go 67.85% <100.00%> (+2.60%) ⬆️
pkg/plugins/leader/postgres/leader_elector.go 93.61% <0.00%> (-4.26%) ⬇️
pkg/core/resources/manager/cache.go 88.31% <0.00%> (+2.59%) ⬆️
api/mesh/v1alpha1/dataplane_overview.pb.go 47.76% <0.00%> (+4.47%) ⬆️
pkg/plugins/runtime/gateway/route/sorter.go 66.66% <0.00%> (+5.12%) ⬆️
pkg/events/eventbus.go 92.59% <0.00%> (+7.40%) ⬆️
pkg/core/runtime/component/component.go 88.67% <0.00%> (+7.54%) ⬆️
pkg/core/bootstrap/autoconfig.go 54.46% <0.00%> (+8.03%) ⬆️
pkg/insights/components.go 100.00% <0.00%> (+30.00%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 704c57c...e6e3bda. Read the comment docs.

@bartsmykla bartsmykla merged commit f131b07 into kumahq:master Oct 20, 2021
@bartsmykla bartsmykla deleted the fix/insights-resyncer-gateway-inbounds branch October 20, 2021 06:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants