-
Notifications
You must be signed in to change notification settings - Fork 129
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: restore Gateway API generation (issue #1427). #1431
Conversation
Separate integration tests in kong2kic_integration_test.go and must be explicitly invoked with -tags=integration. Fix tests to evaluate all yaml objects.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1431 +/- ##
==========================================
+ Coverage 27.58% 29.43% +1.84%
==========================================
Files 61 61
Lines 6285 6537 +252
==========================================
+ Hits 1734 1924 +190
- Misses 4423 4474 +51
- Partials 128 139 +11 ☔ View full report in Codecov by Sentry. |
Adding @randmonkey for reviews here as I don't have much context about KIC. Tao will be able to help out in that area. |
@randmonkey Please review when you can |
@randmonkey let me know if any changes needed. |
Hi @randmonkey , sorry to ping you again. Let please know by when can I expect a review. Just to manage expectations with users. |
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.
Kubernetes changes LGTM. Please take a look at code and PR quality @Prashansa-K
@battlebyte Could you take a look at the failed CI pipelines please? |
for _, service := range content.Services { | ||
for _, route := range service.Routes { | ||
httpRoute, err := createHTTPRoute(service, route) | ||
if err != nil { |
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.
Just curious: why are we continuing here even with the 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.
The input Kong configuration may have many routes that must be converted to HTTPRoute objects. There may be an error when converting one of the routes. If that is the case, we inform of the error and continue processing the next route object.
httpRoute.APIVersion = GatewayAPIVersionV1Beta1 | ||
} | ||
if service.Name != nil && route.Name != nil { | ||
httpRoute.ObjectMeta.Name = calculateSlug(*service.Name + "-" + *route.Name) |
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.
Are we sure that httpRoute.ObjectMeta
is always non-nil?
I am unaware about the underlying struct but if it ever comes nil, our code can panic here.
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.
ObjectMeta is a struct so it is always initialized.
return nil | ||
} | ||
|
||
func createHTTPRoute(service file.FService, route *file.FRoute) (k8sgwapiv1.HTTPRoute, error) { |
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.
We do a lot of dereferencing for service and route here. Can we do a nil check beforehand to avoid potential panics?
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.
Provided comments on the concrete potential nil-checking.
func addHosts(httpRoute *k8sgwapiv1.HTTPRoute, route *file.FRoute) { | ||
if route.Hosts != nil { | ||
for _, host := range route.Hosts { | ||
httpRoute.Spec.Hostnames = append(httpRoute.Spec.Hostnames, k8sgwapiv1.Hostname(*host)) |
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.
Same concern as on line 322
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.
Spec is a struct, so it is initialized.
httpRoute.ObjectMeta.Annotations["konghq.com/tags"] = strings.Join(tags, ",") | ||
} | ||
if route.SNIs != nil { | ||
var snis string |
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.
Performance wise, it would be better to use a string builder.
I will leave the choice to you. If this piece of code isn't accessed much, we can leave it as is.
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.
Good point, refactored as a string builder.
}) | ||
} | ||
|
||
func addBackendRefs(httpRoute *k8sgwapiv1.HTTPRoute, service file.FService, route *file.FRoute) { |
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.
Can we please add some comments in this function to ensure that future contributors can understand what needs to be done and why?
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.
Comments added. Let me know if it is clear.
kong2kic/route.go
Outdated
|
||
func addAnnotations(httpRoute *k8sgwapiv1.HTTPRoute, route *file.FRoute) { | ||
if route.PreserveHost != nil { | ||
httpRoute.ObjectMeta.Annotations["konghq.com/preserve-host"] = strconv.FormatBool(*route.PreserveHost) |
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.
Shouldn't we treat the annotation names as constants?
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.
There are two diff functions using the same sort of annotations. It would be better to make these top level constants in my opinion.
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.
Refactored as constants.
kong2kic/route.go
Outdated
|
||
func createHTTPRoute(service file.FService, route *file.FRoute) (k8sgwapiv1.HTTPRoute, error) { | ||
var httpRoute k8sgwapiv1.HTTPRoute | ||
httpRoute.Kind = "HTTPRoute" |
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.
Should we treat this string as a constant?
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.
Refactored as a constant.
kong2kic/route.go
Outdated
ExtensionRef: &k8sgwapiv1.LocalObjectReference{ | ||
Name: k8sgwapiv1.ObjectName(kongPlugin.ObjectMeta.Name), | ||
Kind: KongPluginKind, | ||
Group: "configuration.konghq.com", |
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.
Const string
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.
Refactored as constant.
@battlebyte Just one comment and some linting issues that need to be addressed. |
I don't see the linting issue when running the linter locally, so not sure why it is complaining here. |
That could either be due to difference in local linter version vs the one used here. Could you just resolve it based on the error it is showing in the pipeline? I think a comment regarding nolint needs to be removed and it should work fine.
|
@Prashansa-K linter issue fixed. |
KongHQWriteTimeout = "konghq.com/write-timeout" | ||
) | ||
|
||
const ( |
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.
why aren't all constants in one block?
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.
I separated the ones that belong to annotations from the rest.
* fix: restore Gateway API generation (issue #1427). Separate integration tests in kong2kic_integration_test.go and must be explicitly invoked with -tags=integration. Fix tests to evaluate all yaml objects. * refactor: replace hardcoded strings with constants in KIC components * fix: remove nolint directive for service port assignment in createIngressPaths --------- Co-authored-by: Prashansa Kulshrestha <[email protected]>
Fixes #1427
Separate integration tests in
kong2kic_integration_test.go
and must be explicitly invoked with -tags=integration.Fix tests to evaluate all yaml objects.