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

refactor(nginx-templates): reduce redundancy #11354

Merged
merged 2 commits into from
Aug 16, 2023
Merged

Conversation

samugi
Copy link
Member

@samugi samugi commented Aug 3, 2023

Summary

Currently integration tests use dedicated templates that are manually kept in sync with the base nginx_kong.lua and nginx_kong_stream.lua configurations (should a change be made to those files it has to be manually replicated in custom_nginx.template and default_nginx.template). This is error prone and can lead to inconsistencies between the standard config and the one used in tests.

This PR tries to unify as much of the configuration as possible in a single place to reduce duplication and consequently the chances of forgetting to update one of the files, which may result in running tests with a configuration that differs from the "production" one.

Implementation

nginx_kong.lua is compiled into nginx-kong.conf, while all the .lua files in fixtures/template_inject are compiled into .test.conf configuration files in the prefix folder. During compilation, chunks that are only meant for the tests are rendered, if needed (this is controlled by the test flag in the template environment). Config flags are set in the template rendering environment based on the --conf-template-flags input of the start cmd.

When the template is rendered, nginx-kong.conf and the other partial configs are loaded in the http section using the include directive. A similar approach is followed for the stream configuration.

Checklist

Full changelog

  • [Implement ...]

Issue reference

KAG-1962

@samugi samugi marked this pull request as draft August 3, 2023 21:47
@samugi samugi force-pushed the feat/nginx-conf-templates branch 2 times, most recently from de175a4 to 6f135a0 Compare August 4, 2023 15:41
@samugi samugi changed the title feat(nginx-templates): avoid duplication in nginx templates feat(nginx-templates): reduce redundancy of nginx templates Aug 4, 2023
@samugi samugi changed the title feat(nginx-templates): reduce redundancy of nginx templates refactor(nginx-templates): reduce redundancy of nginx templates Aug 4, 2023
@samugi samugi force-pushed the feat/nginx-conf-templates branch 6 times, most recently from f3a7103 to 4bb916c Compare August 7, 2023 17:35
@samugi samugi changed the title refactor(nginx-templates): reduce redundancy of nginx templates refactor(nginx-templates): reduce redundancy Aug 7, 2023
@samugi samugi marked this pull request as ready for review August 7, 2023 19:06
Copy link
Contributor

@StarlightIbuki StarlightIbuki left a comment

Choose a reason for hiding this comment

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

I only find 1 use of spec/fixtures/1.2_custom_nginx.template. Could we eliminate that file too?
Also, could we use a unified template instead of with a separate file called "custom_nginx.template"?

spec/fixtures/custom_nginx.template Outdated Show resolved Hide resolved
spec/fixtures/custom_nginx.template Outdated Show resolved Hide resolved
kong/templates/nginx_kong.lua Outdated Show resolved Hide resolved
kong/cmd/utils/prefix_handler.lua Outdated Show resolved Hide resolved
kong/cmd/utils/prefix_handler.lua Outdated Show resolved Hide resolved
@samugi samugi force-pushed the feat/nginx-conf-templates branch 3 times, most recently from e68eb19 to e72ce3a Compare August 9, 2023 20:41
kong/cmd/reload.lua Outdated Show resolved Hide resolved
kong/cmd/utils/prefix_handler.lua Show resolved Hide resolved
@samugi samugi force-pushed the feat/nginx-conf-templates branch 3 times, most recently from 0b3a3f6 to 505902c Compare August 10, 2023 15:37
@samugi
Copy link
Member Author

samugi commented Aug 11, 2023

As discussed, let's postpone any additional changes to a separate PR if needed. We are also leaving the 1.2_custom_nginx.template template for now, since it won't be updated so it won't cause inconsistencies.

kong/cmd/reload.lua Outdated Show resolved Hide resolved
bungle

This comment was marked as duplicate.

Copy link
Member

@bungle bungle left a comment

Choose a reason for hiding this comment

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

Can we try to move this into own template, render it and then Nginx include it?

kong/templates/nginx_kong.lua Outdated Show resolved Hide resolved
@samugi samugi requested a review from bungle August 14, 2023 19:28
@samugi samugi force-pushed the feat/nginx-conf-templates branch 3 times, most recently from 0a09167 to 640fad5 Compare August 14, 2023 22:36
Copy link
Member

@bungle bungle left a comment

Choose a reason for hiding this comment

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

Just something to think about, not must.

kong/templates/nginx_kong.lua Outdated Show resolved Hide resolved
kong/cmd/reload.lua Outdated Show resolved Hide resolved
kong/cmd/restart.lua Outdated Show resolved Hide resolved
kong/templates/nginx_kong_stream.lua Outdated Show resolved Hide resolved
@samugi samugi force-pushed the feat/nginx-conf-templates branch 3 times, most recently from 2930641 to e0c4e17 Compare August 15, 2023 14:31
This commit tries to unify as much of the configuration as possible in a
single place to reduce duplication and consequently the chances of
forgetting to update one of the files.

* nginx_kong.lua is compiled into nginx-kong.conf: chunks that are only
meant for the test environment are rendered, if needed.

* When the template is rendered, nginx-kong.conf is dynamically loaded
in the http section using the include directive.

refactor(templates): apply PR suggestions

- use nginx include instead of rendering files in the templates using
  inline lua expressions
- rename test-flags to nginx-conf-flags
- cleanup of non needed changes
- adapt tests

Co-authored-by: Aapo Talvensaari <aapo.talvensaari@gmail.com>
@bungle
Copy link
Member

bungle commented Aug 15, 2023

Looks good! Merge on green!

@samugi samugi merged commit c6fa8cb into master Aug 16, 2023
21 checks passed
@samugi samugi deleted the feat/nginx-conf-templates branch August 16, 2023 07:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants