nginxinc / kubernetes-ingress

NGINX and NGINX Plus Ingress Controllers for Kubernetes
https://docs.nginx.com/nginx-ingress-controller
Apache License 2.0
4.68k stars 1.97k forks source link

Use default VS and TS templates when CfgMap obj is deleted #6780

Closed jjngx closed 1 week ago

jjngx commented 2 weeks ago

Proposed changes

This PR introduces following change:

Test in kind:

VS config before applying custom template from configMap:

nginx@nginx-ingress-7fb4ff9677-z4t7b:/etc/nginx/conf.d$ head vs_default_cafe.conf

upstream vs_default_cafe_coffee {
    zone vs_default_cafe_coffee 512k;
    random two least_conn;
    server 10.244.0.6:8080 max_fails=1 fail_timeout=10s max_conns=0;
    server 10.244.0.7:8080 max_fails=1 fail_timeout=10s max_conns=0;

}
...

VS after applying custom template from configMap:

nginx@nginx-ingress-7fb4ff9677-z4t7b:/etc/nginx/conf.d$ head vs_default_cafe.conf
# ===============================================
# ==== VirtualServer TEMPLATE from ConfigMap ====
# ===============================================
#
# TEST!!!!
#
upstream vs_default_cafe_coffee {
    zone vs_default_cafe_coffee 512k;
    random two least_conn;
    server 10.244.0.6:8080 max_fails=1 fail_timeout=10s max_conns=
...

pod logs:

...

I20241111 14:12:39.372865   1 controller.go:262] Event(v1.ObjectReference{Kind:"ConfigMap", Namespace:"nginx-ingress", Name:"nginx-config", UID:"054001d6-4f81-43aa-b5b9-07a9d29fc8a3", APIVersion:"v1", ResourceVersion:"11892", FieldPath:""}): type: 'Normal' reason: 'Updated' Configuration from nginx-ingress/nginx-config was updated
I20241111 14:12:39.373038   1 controller.go:262] Event(v1.ObjectReference{Kind:"VirtualServer", Namespace:"default", Name:"cafe", UID:"edd41c17-e78e-40a4-9f86-c5b485f46963", APIVersion:"k8s.nginx.org/v1", ResourceVersion:"5989", FieldPath:""}): type: 'Normal' reason: 'AddedOrUpdated' Configuration for default/cafe was added or updated
2024/11/11 14:12:39 [notice] 127#127: exit
2024/11/11 14:12:39 [notice] 128#128: exit
2024/11/11 14:12:39 [notice] 22#22: signal 17 (SIGCHLD) received from 120
...

remove the custom VS template - original, default template is applied:

nginx@nginx-ingress-7fb4ff9677-z4t7b:/etc/nginx/conf.d$ head vs_default_cafe.conf

upstream vs_default_cafe_coffee {
    zone vs_default_cafe_coffee 512k;
    random two least_conn;
    server 10.244.0.6:8080 max_fails=1 fail_timeout=10s max_conns=0;
    server 10.244.0.7:8080 max_fails=1 fail_timeout=10s max_conns=0;

}
...

pod logs:

...
I20241111 14:14:21.563389   1 controller.go:262] Event(v1.ObjectReference{Kind:"ConfigMap", Namespace:"nginx-ingress", Name:"nginx-config", UID:"054001d6-4f81-43aa-b5b9-07a9d29fc8a3", APIVersion:"v1", ResourceVersion:"12039", FieldPath:""}): type: 'Normal' reason: 'Updated' Configuration from nginx-ingress/nginx-config was updated
I20241111 14:14:21.563577   1 controller.go:262] Event(v1.ObjectReference{Kind:"VirtualServer", Namespace:"default", Name:"cafe", UID:"edd41c17-e78e-40a4-9f86-c5b485f46963", APIVersion:"k8s.nginx.org/v1", ResourceVersion:"5989", FieldPath:""}): type: 'Normal' reason: 'AddedOrUpdated' Configuration for default/cafe was added or updated
2024/11/11 14:14:21 [notice] 137#137: exit
...

Checklist

Before creating a PR, run through this checklist and mark each as complete.

codecov[bot] commented 2 weeks ago

Codecov Report

Attention: Patch coverage is 68.57143% with 11 lines in your changes missing coverage. Please review.

Project coverage is 53.46%. Comparing base (64de3b8) to head (5ef4d7a). Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
internal/configs/version2/template_executor.go 57.14% 6 Missing and 3 partials :warning:
internal/configs/configmaps.go 50.00% 0 Missing and 2 partials :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #6780 +/- ## ========================================== + Coverage 53.38% 53.46% +0.07% ========================================== Files 89 89 Lines 20195 20218 +23 ========================================== + Hits 10781 10809 +28 + Misses 8977 8965 -12 - Partials 437 444 +7 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.