-
Notifications
You must be signed in to change notification settings - Fork 590
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
spike: create warning events for parsing errors #3088
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,41 @@ const ( | |
// Parser - Public Types | ||
// ----------------------------------------------------------------------------- | ||
|
||
type ParsingError struct { | ||
relatedObjects []client.Object | ||
reason string | ||
} | ||
Comment on lines
+42
to
+45
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Every parsing error has a human-readable reason string and related kubernetes objects. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Apart from this deserving its own file I feel this is a good approach. |
||
|
||
func NewParsingError(reason string, relatedObjects ...client.Object) ParsingError { | ||
if reason == "" { | ||
reason = "unknown" | ||
} | ||
return ParsingError{ | ||
relatedObjects: relatedObjects, | ||
reason: reason, | ||
} | ||
} | ||
|
||
func (p ParsingError) RelatedObjects() []client.Object { | ||
return p.relatedObjects | ||
} | ||
|
||
func (p ParsingError) Reason() string { | ||
return p.reason | ||
} | ||
|
||
type parsingErrorsCollector struct { | ||
errors []ParsingError | ||
} | ||
|
||
func newParsingErrorsCollector() *parsingErrorsCollector { | ||
return &parsingErrorsCollector{} | ||
} | ||
|
||
func (c *parsingErrorsCollector) ParsingError(reason string, relatedObjects ...client.Object) { | ||
c.errors = append(c.errors, NewParsingError(reason, relatedObjects...)) | ||
} | ||
Comment on lines
+73
to
+75
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
// Parser parses Kubernetes objects and configurations into their | ||
// equivalent Kong objects and configurations, producing a complete | ||
// state configuration for the Kong Admin API. | ||
|
@@ -51,6 +86,7 @@ type Parser struct { | |
featureEnabledCombinedServiceRoutes bool | ||
|
||
flagEnabledRegexPathPrefix bool | ||
errorsCollector *parsingErrorsCollector | ||
} | ||
|
||
// NewParser produces a new Parser object provided a logging mechanism | ||
|
@@ -60,8 +96,9 @@ func NewParser( | |
storer store.Storer, | ||
) *Parser { | ||
return &Parser{ | ||
logger: logger, | ||
storer: storer, | ||
logger: logger, | ||
storer: storer, | ||
errorsCollector: newParsingErrorsCollector(), | ||
} | ||
} | ||
|
||
|
@@ -118,7 +155,7 @@ func (p *Parser) Build() *kongstate.KongState { | |
result.Certificates = mergeCerts(p.logger, ingressCerts, gatewayCerts) | ||
|
||
// populate CA certificates in Kong | ||
result.CACertificates = getCACerts(p.logger, p.storer, result.Plugins) | ||
result.CACertificates = p.getCACerts(p.logger, p.storer) | ||
|
||
return &result | ||
} | ||
|
@@ -154,6 +191,13 @@ func (p *Parser) GenerateKubernetesObjectReport() []client.Object { | |
return report | ||
} | ||
|
||
// PopParsingErrors pops all the parsing errors collected during the last parsing round. | ||
func (p *Parser) PopParsingErrors() []ParsingError { | ||
errors := p.errorsCollector.errors | ||
p.errorsCollector.errors = nil | ||
Comment on lines
+196
to
+197
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This would ideally be placed in |
||
return errors | ||
} | ||
|
||
// ----------------------------------------------------------------------------- | ||
// Parser - Public Methods - Other Optional Features | ||
// ----------------------------------------------------------------------------- | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,14 +4,14 @@ import ( | |
"testing" | ||
|
||
"github.com/kong/go-kong/kong" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/kong/kubernetes-ingress-controller/v2/internal/dataplane/kongstate" | ||
) | ||
|
||
func TestGetPluginsAssociatedWithCACertSecret(t *testing.T) { | ||
secretID := "8a3753e0-093b-43d9-9d39-27985c987d92" //nolint:gosec | ||
plugins := []kongstate.Plugin{ | ||
// todo: adapt to implementation | ||
_ = []kongstate.Plugin{ | ||
Comment on lines
+13
to
+14
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Given the PR is already marked as ready to review, I believe this needs addressing. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please note it's marked as ready for review (as Michał has suggested doing), but still is not meant to be merged to main in this form. I can adapt the tests but IMO it's not worth it for now until we decide that we wanna go with this approach. The key output I wanted to get out of reviewing this is whether the team thinks it's the way we wanna go regarding events publishing (mainly, if it's ok to do that directly from Parser). |
||
{ | ||
Plugin: kong.Plugin{ | ||
Name: kong.String("associated-plugin"), | ||
|
@@ -35,6 +35,6 @@ func TestGetPluginsAssociatedWithCACertSecret(t *testing.T) { | |
}, | ||
} | ||
|
||
associatedPlugins := getPluginsAssociatedWithCACertSecret(plugins, secretID) | ||
require.ElementsMatch(t, []string{"associated-plugin", "another-associated-plugin"}, associatedPlugins) | ||
// associatedPlugins := getPluginsAssociatedWithCACertSecret(plugins, secretID) | ||
// require.ElementsMatch(t, []string{"associated-plugin", "another-associated-plugin"}, associatedPlugins) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -144,7 +144,18 @@ func Run(ctx context.Context, c *Config, diagnostic util.ConfigDumpDiagnostic) e | |
if err != nil { | ||
return fmt.Errorf("%f is not a valid number of seconds to the timeout config for the kong client: %w", c.ProxyTimeoutSeconds, err) | ||
} | ||
dataplaneClient, err := dataplane.NewKongClient(deprecatedLogger, timeoutDuration, c.IngressClassName, c.EnableReverseSync, c.SkipCACertificates, diagnostic, kongConfig) | ||
|
||
dataplaneEventRecorder := mgr.GetEventRecorderFor("kubernetes-ingress-controller-data-plane") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's straightforward to create an event recorder from the controller manager. |
||
dataplaneClient, err := dataplane.NewKongClient( | ||
deprecatedLogger, | ||
timeoutDuration, | ||
c.IngressClassName, | ||
c.EnableReverseSync, | ||
c.SkipCACertificates, | ||
diagnostic, | ||
kongConfig, | ||
dataplaneEventRecorder, | ||
) | ||
if err != nil { | ||
return fmt.Errorf("failed to initialize kong data-plane client: %w", err) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
eventsRecorder
creates KubernetesEvent
object associated with theobj
.