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

[1.17] Add support for listener level warnings #10490

Merged
merged 2 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions changelog/v1.17.17/allow-listener-warnings.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
changelog:
- type: NON_USER_FACING
issueLink: https://github.com/k8sgateway/k8sgateway/issues/10293
resolvesIssue: false
description: Adds support for listener level warnings. This way when a listener or its plugin returns an error, it can be checked if it is a configuration error that can be treated as a warning and processed accordingly.
- type: FIX
issueLink: https://github.com/k8sgateway/k8sgateway/issues/10293
resolvesIssue: false
description: Fixes an issue where an error is thrown instead of an InvalidDestinationWarning when a tracing collector references a missing upstream.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 34 additions & 4 deletions projects/gateway/pkg/reporting/add_proxy_validation_result.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,14 +179,44 @@ func getListenerLevelErrors(listenerReport *validation.ListenerReport) []error {
listenerErrs = append(listenerErrs, validationutils.GetHttpListenerErr(httpListenerReport)...)
}
}

return listenerErrs
}

func getListenerLevelWarnings(listenerReport *validation.ListenerReport) []string {
listenerWarnings := validationutils.GetListenerWarning(listenerReport)
listenerWarnings := validationutils.GetListenerWarn(listenerReport)

switch listenerType := listenerReport.GetListenerTypeReport().(type) {
case *validation.ListenerReport_HttpListenerReport:
httpListener := listenerType.HttpListenerReport
listenerWarnings = append(listenerWarnings, validationutils.GetHttpListenerWarning(httpListener)...)

case *validation.ListenerReport_TcpListenerReport:
tcpListener := listenerType.TcpListenerReport
listenerWarnings = append(listenerWarnings, validationutils.GetTcpListenerWarning(tcpListener)...)

// TODO(jbohanon) implement warnings on various listener types and account for them here
// similarly to the errors aggregation func above.
for _, hostReport := range tcpListener.GetTcpHostReports() {
listenerWarnings = append(listenerWarnings, validationutils.GetTcpHostWarning(hostReport)...)
}
case *validation.ListenerReport_HybridListenerReport:
for _, matchedListenerReport := range listenerType.HybridListenerReport.GetMatchedListenerReports() {
switch matchedListenerType := matchedListenerReport.GetListenerReportType().(type) {
case *validation.MatchedListenerReport_HttpListenerReport:
httpListener := matchedListenerType.HttpListenerReport
listenerWarnings = append(listenerWarnings, validationutils.GetHttpListenerWarning(httpListener)...)
case *validation.MatchedListenerReport_TcpListenerReport:
tcpListener := matchedListenerType.TcpListenerReport
listenerWarnings = append(listenerWarnings, validationutils.GetTcpListenerWarning(tcpListener)...)

for _, hostReport := range tcpListener.GetTcpHostReports() {
listenerWarnings = append(listenerWarnings, validationutils.GetTcpHostWarning(hostReport)...)
}
}
}
case *validation.ListenerReport_AggregateListenerReport:
for _, httpListenerReport := range listenerType.AggregateListenerReport.GetHttpListenerReports() {
listenerWarnings = append(listenerWarnings, validationutils.GetHttpListenerWarning(httpListenerReport)...)
}
}

return listenerWarnings
}
Expand Down
16 changes: 16 additions & 0 deletions projects/gateway/pkg/reporting/add_proxy_validation_result_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ var _ = Describe("AddProxyValidationResult", func() {
validationapi.ListenerReport_Error_ProcessingError,
"bad listener")

validation.AppendListenerWarning(lis,
validationapi.ListenerReport_Warning_SSLConfigWarning,
"misconfigured listener")

availableVirtualHostReports := lis.GetHttpListenerReport().GetVirtualHostReports()
for _, httpReport := range lis.GetAggregateListenerReport().GetHttpListenerReports() {
availableVirtualHostReports = append(availableVirtualHostReports, httpReport.GetVirtualHostReports()...)
Expand All @@ -57,6 +61,11 @@ var _ = Describe("AddProxyValidationResult", func() {
"bad route",
"route-0",
)

validation.AppendRouteWarning(route,
validationapi.RouteReport_Warning_Type(validationapi.RouteReport_Warning_InvalidDestinationWarning),
"invalid route route-0",
)
}
}
}
Expand All @@ -68,6 +77,9 @@ var _ = Describe("AddProxyValidationResult", func() {
Expect(reports[gw].Errors).To(HaveOccurred())
Expect(reports[gw].Errors.Error()).To(ContainSubstring(`1 error occurred:
* Listener Error: ProcessingError. Reason: bad listener`))

Expect(reports[gw].Warnings).To(HaveLen(1))
Expect(reports[gw].Warnings[0]).To(ContainSubstring(`Listener Warning: SSLConfigWarning. Reason: misconfigured listener`))
}

for _, vs := range snap.VirtualServices {
Expand All @@ -76,6 +88,10 @@ var _ = Describe("AddProxyValidationResult", func() {
Expect(reports[vs].Errors.Error()).To(ContainSubstring(`4 errors occurred:
* VirtualHost Error: DomainsNotUniqueError. Reason: bad vhost
* Route Error: InvalidMatcherError. Reason: bad route. Route Name: route-0`))

Expect(reports[vs].Warnings).To(HaveLen(2))
Expect(reports[vs].Warnings[0]).To(ContainSubstring(`Route Warning: InvalidDestinationWarning. Reason: invalid route route-0`))
Expect(reports[vs].Warnings[1]).To(ContainSubstring(`Route Warning: InvalidDestinationWarning. Reason: invalid route route-0`))
}
},
Entry("default translators", translator.Opts{
Expand Down
32 changes: 32 additions & 0 deletions projects/gloo/api/grpc/validation/gloo_validation.proto
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,22 @@ message HttpListenerReport {

// report for nested virtual hosts
repeated VirtualHostReport virtual_host_reports = 2;

// warning types for the given listener
message Warning {
enum Type {
UnknownWarning = 0;
InvalidDestinationWarning = 1;
}

// the type of the warning
Type type = 1;
// any extra info as a string
string reason = 2;
}

// warnings on the config of listener
repeated Warning warnings = 3;
}

message VirtualHostReport {
Expand Down Expand Up @@ -251,6 +267,22 @@ message TcpListenerReport {
// errors on top-level config of the listener
repeated Error errors = 1;
repeated TcpHostReport tcp_host_reports = 2;

// warning types for the given listener
message Warning {
enum Type {
UnknownWarning = 0;
InvalidDestinationWarning = 1;
}

// the type of the warning
Type type = 1;
// any extra info as a string
string reason = 2;
}

// warnings on the config of listener
repeated Warning warnings = 3;
}

message TcpHostReport {
Expand Down
56 changes: 56 additions & 0 deletions projects/gloo/pkg/api/grpc/validation/gloo_validation.pb.clone.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading