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

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

Merged
merged 9 commits into from
Nov 13, 2024

Conversation

jjngx
Copy link
Contributor

@jjngx jjngx commented Nov 11, 2024

Proposed changes

This PR introduces following change:

  • NIC reverts to using default VS and TS templates after custom VS and TS templates (provided by config map obj) are deleted
  • There is no need to restart the NIC pod to revert to custom templates

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.

  • I have read the CONTRIBUTING doc
  • I have added tests that prove my fix is effective or that my feature works
  • I have checked that all unit tests pass after adding my changes
  • I have updated necessary documentation
  • I have rebased my branch onto main
  • I will ensure my PR is targeting the main branch and pulling from my branch from my own fork

@github-actions github-actions bot added bug An issue reporting a potential bug go Pull requests that update Go code labels Nov 11, 2024
@jjngx jjngx linked an issue Nov 11, 2024 that may be closed by this pull request
@jjngx jjngx added this to the v4.0.0 milestone Nov 11, 2024
Copy link

codecov bot commented Nov 11, 2024

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 ⚠️
internal/configs/configmaps.go 50.00% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@            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     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@jjngx jjngx marked this pull request as ready for review November 11, 2024 14:16
@jjngx jjngx requested a review from a team as a code owner November 11, 2024 14:16
@jjngx jjngx merged commit 214d9f1 into main Nov 13, 2024
30 checks passed
@jjngx jjngx deleted the fix/config-map-tmpl branch November 13, 2024 13:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An issue reporting a potential bug go Pull requests that update Go code
Projects
Status: Done 🚀
Development

Successfully merging this pull request may close these issues.

Gracefully handle custom VS and TS template change in ConfigMaps
3 participants