fix: Added a flag to reduce deduplication while handling route server path#294
Conversation
…services in paths.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #294 +/- ##
==========================================
+ Coverage 64.98% 65.07% +0.08%
==========================================
Files 25 25
Lines 3119 3204 +85
==========================================
+ Hits 2027 2085 +58
- Misses 881 905 +24
- Partials 211 214 +3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
08395a7 to
3b0fc7e
Compare
3b0fc7e to
2ffd94a
Compare
There was a problem hiding this comment.
Pull request overview
Adds an opt-in --reuse-services conversion mode to reduce duplicate Kong services when multiple OpenAPI path/operation server blocks resolve to the same upstream, while attempting to avoid plugin conflicts by keeping plugin attachment behavior consistent with existing service-vs-route rules.
Changes:
- Introduces
O2kOptions.ReuseServicesand a--reuse-servicesCLI flag to enable caching/reuse of generated services. - Implements path-level and operation-level service caches keyed by server config + service/upstream defaults, with special handling for path-level plugin extensions.
- Adds/updates tests and fixtures to validate service reuse behavior (including plugin-related cases).
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| openapi2kong/openapi2kong.go | Adds the reuse-services option, cache/keying logic, and plugin-flow adjustments when reusing services. |
| openapi2kong/openapi2kong_test.go | Plumbs reuseServices through fixture-driven tests and adds a focused unit test for reuse behavior. |
| openapi2kong/oas3_testfiles/30-reuse-identical-services.yaml | New fixture covering path-level reuse with identical servers. |
| openapi2kong/oas3_testfiles/30-reuse-identical-services.expected.json | Expected output for path-level reuse fixture. |
| openapi2kong/oas3_testfiles/31-reuse-with-plugins-on-routes.yaml | New fixture ensuring path-level plugin extensions prevent reuse. |
| openapi2kong/oas3_testfiles/31-reuse-with-plugins-on-routes.expected.json | Expected output for “no reuse when path plugins exist” fixture. |
| openapi2kong/oas3_testfiles/32-reuse-operation-level-services.yaml | New fixture covering operation-level reuse with identical servers. |
| openapi2kong/oas3_testfiles/32-reuse-operation-level-services.expected.json | Expected output for operation-level reuse fixture. |
| openapi2kong/oas3_testfiles/33-reuse-operation-services-with-plugins.yaml | New fixture covering operation-level reuse while keeping plugins on routes. |
| openapi2kong/oas3_testfiles/33-reuse-operation-services-with-plugins.expected.json | Expected output for operation-level reuse with plugins fixture. |
| cmd/openapi2kong.go | Adds the --reuse-services CLI flag and wires it into O2kOptions. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 21 out of 21 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (2)
openapi2kong/openapi2kong.go:1185
- These calls to
getPluginsListdiscard the returned error. If doc/path-level plugin parsing fails, the conversion can proceed with an incomplete/incorrect plugin list instead of returning a failure. Capture and propagate errors for all threegetPluginsListcalls (doc, path, operation).
} else if newOperationService || reusedOperationService {
// we're operating on an operation-level service entity, so we need the plugins
// from the document, path, and operation.
operationPluginList, _ = getPluginsList(doc.Extensions, nil, nil, opts.UUIDNamespace,
operationBaseName, kongComponents, kongTags, opts.SkipID)
operationPluginList, _ = getPluginsList(pathitem.Extensions, nil, operationPluginList, opts.UUIDNamespace,
operationBaseName, kongComponents, kongTags, opts.SkipID)
operationPluginList, err = getPluginsList(operation.Extensions, nil, operationPluginList, opts.UUIDNamespace,
operationBaseName, kongComponents, kongTags, opts.SkipID)
openapi2kong/openapi2kong_test.go:110
- This failure path builds an error string using
fmt.Sprintfwith a literal "%%w" and then passeserras a separate argument tot.Error, so the formatted message never includes the error in a useful way. Prefert.Errorf("%s didn't expect error: %v", ..., err)(ort.Fatalf) so the actual error is included.
})
if err != nil {
t.Error(fmt.Sprintf("'%s' didn't expect error: %%w", fixturePath+fileNameIn), err)
} else {
FTI: https://konghq.atlassian.net/browse/FTI-7457
Summary:
When multiple OAS paths or operations defined identical servers blocks, we were creating separate Kong services for each path and operation even though they pointed to the same upstream, resulting in unnecessary duplicate services in Kong.
We added a
--reuse-servicesflag to cache and reuse services based on server URL and defaults.x-kong-plugin-*extensions are present, with plugins attached to routes to avoid conflicts.https://kongstrong.slack.com/archives/C07AQH7SAF8/p1778764775374189