nginxinc / kubernetes-ingress

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

After removing the custom template, NIC does not restore to default template without restarting NIC pod #5906

Open haywoodsh opened 3 months ago

haywoodsh commented 3 months ago

Describe the bug The NIC monitors the config map and alters its behavior when deployed with the -nginx-configmaps flag. Users have the ability to add and edit custom templates using the config map keys main-template, ingress-template, and virtualserver-template after deployment. However, if a user deletes the config map key or the entire config map, the custom template will persist with the last set value and will not revert to the default until the NIC is restarted. To Reproduce Steps to reproduce the behavior:

  1. Deploy NIC with the flag --nginx-configmaps=$(POD_NAMESPACE)/nginx-config and empty configmap, i.e.
    kind: ConfigMap
    apiVersion: v1
    metadata:
    name: nginx-config
    namespace: nginx-ingress
    data:
  2. Add a custom template with the config map entry that is slightly different from the default tempalte, e.g. comment at the top # custom main template and re-apply the config map
    kind: ConfigMap
    apiVersion: v1
    metadata:
    name: nginx-config
    namespace: nginx-ingress
    data:
    main-template: |
    # custom main template
    worker_processes  {{.WorkerProcesses}};
    ...
        include /etc/nginx/conf.d/*.conf;
    }
    ...
  3. Run cat etc/nginx/nginx.conf inside the NIC pod to confirm # custom main template is at the top of nginx.conf
  4. Remove the main-template key in config map so that it reverts the one at step 1 again, and then re-apply the config map
  5. Run cat etc/nginx/nginx.conf inside the NIC pod, # custom main template is still at the top of nginx.conf, showing that NIC does not revert to using the default template.

Expected behavior As the NIC monitors the config map in real-time, its behavior should mirror the config map's contents. Thus, when a user inserts a custom template into the config map, the NIC should switch from the default to the custom template. Consequently, if the custom template key is deleted from the config map, the user would anticipate that the NIC reverts to the default template.

Your environment

Additional context Add any other context about the problem here. Any log files you want to share.

github-actions[bot] commented 3 months ago

Hi @haywoodsh thanks for reporting!

Be sure to check out the docs and the Contributing Guidelines while you wait for a human to take a look at this :slightly_smiling_face:

Cheers!