Skip to content

Conversation

@raorudzhov
Copy link
Contributor

@raorudzhov raorudzhov commented Aug 26, 2025

What this PR does / why we need it:

This patch fixes an issue in the NGINX Ingress Controller where invalid Ingress resources caused metric nginx_ingress_controller_config_last_reload_successful to be set value to 0 and never restored after the resource was deleted.

With this change, metrics are now correctly updated even if an Ingress is removed, or its configuration is invalid.

This ensures that monitoring data remains consistent and accurate.

🪲 P.S. this PR also resolved Issue#13818

Previously, when an Ingress contained misconfigurations (e.g. invalid annotations or unsupported snippet directives), the following problems occurred:

  1. Metrics such as nginx_ingress_controller_config_last_reload_successful were set to 0.
  2. After deleting the invalid Ingress, metrics stayed at 0 instead of being restored to 1.
  3. Some parts of the syncIngress logic were skipped due to an early Equal check, preventing proper metric updates.

As a result:

  • Metrics did not reflect the real state of the controller.
  • Monitoring systems could generate false alerts.
  • Operators had no reliable signal that the system had recovered after removing a faulty Ingress.

This patch resolves those issues by ensuring metrics are always properly updated, regardless of Ingress validity.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • CVE Report (Scanner found CVE and adding report)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation only

Which issue/s this PR fixes

This PR fixed Issue#13818

How Has This Been Tested?

  1. Create an invalid Ingress resource;
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: my-app-ingress
  namespace: default
  annotations:
    nginx.ingress.kubernetes.io/configuration-snippet: |
      bla-bla-bla
spec:
  ingressClassName: nginx
  rules:
    - host: myapp.example.com
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: myapp
                port:
                  number: 80
  1. See in logs that NGINX complains about invalid configuration;
Error reloading NGINX:
-------------------------------------------------------------------------------
Error: exit status 1
nginx: [emerg] unknown directive "bla-bla-bla" in /tmp/nginx/nginx-cfg3530923120:6208
nginx: configuration file /tmp/nginx/nginx-cfg3530923120 test failed
-------------------------------------------------------------------------------
  1. Check metrics inside the pod, value is 0;
curl 127.0.0.1:10254/metrics -s | grep reload_successful{
nginx_ingress_controller_config_last_reload_successful{controller_class="ingress-nginx.deckhouse.io/nginx",controller_namespace="d8-ingress-nginx",controller_pod="controller-nginx-rwmf5"} 0
  1. Delete the invalid Ingress resource;
  2. Check metrics again, value is should be 1.
curl 127.0.0.1:10254/metrics -s | grep reload_successful{
nginx_ingress_controller_config_last_reload_successful{controller_class="ingress-nginx.deckhouse.io/nginx",controller_namespace="d8-ingress-nginx",controller_pod="controller-nginx-rwmf5"} 1

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I've read the CONTRIBUTION guide
  • I have added unit and/or e2e tests to cover my changes.
  • All new and existing tests passed.

…_successful metric was reporting an incorrect value

Signed-off-by: Roman Orudzhov <[email protected]>
@netlify
Copy link

netlify bot commented Aug 26, 2025

Deploy Preview for kubernetes-ingress-nginx canceled.

Name Link
🔨 Latest commit 2d2f0a6
🔍 Latest deploy log https://app.netlify.com/projects/kubernetes-ingress-nginx/deploys/68adcb807ebbef0008e21eb5

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Aug 26, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: raorudzhov / name: Roman Orudzhov (2d2f0a6)

@k8s-ci-robot k8s-ci-robot added the needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. label Aug 26, 2025
@k8s-ci-robot
Copy link
Contributor

Welcome @raorudzhov!

It looks like this is your first PR to kubernetes/ingress-nginx 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes/ingress-nginx has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added needs-kind Indicates a PR lacks a `kind/foo` label and requires one. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Aug 26, 2025
@k8s-ci-robot
Copy link
Contributor

Hi @raorudzhov. Thanks for your PR.

I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added needs-priority size/S Denotes a PR that changes 10-29 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Aug 26, 2025
@Gacko Gacko changed the title Controller: Correct nginx_ingress_controller_config_last_reload_successful metric Metrics: Fix nginx_ingress_controller_config_last_reload_successful. Aug 26, 2025
Copy link
Member

@Gacko Gacko left a comment

Choose a reason for hiding this comment

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

/triage accepted
/kind cleanup
/priority backlog
/hold

Do you think it's possible to test this in either unit tests or E2E tests (or both)?

@k8s-ci-robot k8s-ci-robot added do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. triage/accepted Indicates an issue or PR is ready to be actively worked on. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. priority/backlog Higher priority than priority/awaiting-more-evidence. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-kind Indicates a PR lacks a `kind/foo` label and requires one. needs-priority labels Aug 26, 2025
@Gacko
Copy link
Member

Gacko commented Aug 26, 2025

/cherry-pick release-1.13

@Gacko
Copy link
Member

Gacko commented Aug 26, 2025

/cherry-pick release-1.12

@k8s-infra-cherrypick-robot
Copy link
Contributor

@Gacko: once the present PR merges, I will cherry-pick it on top of release-1.13 in a new PR and assign it to you.

In response to this:

/cherry-pick release-1.13

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@k8s-infra-cherrypick-robot
Copy link
Contributor

@Gacko: once the present PR merges, I will cherry-pick it on top of release-1.12 in a new PR and assign it to you.

In response to this:

/cherry-pick release-1.12

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@raorudzhov
Copy link
Contributor Author

Most likely, the current e2e tests don’t cover this, but if we add handling for this scenario, the functionality will most likely be covered.

@Gacko
Copy link
Member

Gacko commented Aug 26, 2025

I'm not that deep in our E2E tests, Go code wise, but I can imagine them to be able to do something like "use invalid config, check the metric is 0, fix config, check the metric is 1". That would be enough!

Also I'd like to have the expected behavior written down somewhere, so in tests, also to be able to prevent any regression.

@raorudzhov
Copy link
Contributor Author

Got it! Just to clarify — do you want me to expand this with actual E2E test cases? So that you can accept PR

@Gacko
Copy link
Member

Gacko commented Aug 26, 2025

Exactly, that would be wonderful! I'm currently about to start a new release cycle, so if you hurry this would still make it into a v1.13.2 / v1.12.6. 🙂

@Gacko Gacko self-assigned this Aug 26, 2025
@Gacko
Copy link
Member

Gacko commented Aug 28, 2025

So, I took a deeper look and I think it's hard to impossible to test this, because this needs an invalid Ingress to recover from and currently configuring Ingress resources in E2E tests always waits for the controller and NGINX to have been reloaded. I'm gonna test this manually for now.

Copy link
Member

@Gacko Gacko left a comment

Choose a reason for hiding this comment

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

/triage accepted
/kind bug
/priority backlog
/hold
/ok-to-test

Ok, I tested the current main with and without your change and a) you're right, it's not working without and b) your change fixes it. As stated before I currently have hard times believing this can be covered by tests as these wait for the reload to succeed after a configuration change and I do not have the resources to extend our testing framework for this use-case at the moment.

Let me just bump some images I promoted today, then I will merge your PR and kick of the controller build for the next patch release.

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. kind/bug Categorizes issue or PR as related to a bug. approved Indicates a PR has been approved by an approver from all required OWNERS files. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Aug 28, 2025
@raorudzhov
Copy link
Contributor Author

Thank you for your help
I’ll be waiting for the merge

@Gacko
Copy link
Member

Gacko commented Aug 28, 2025

/lgtm
/unhold

@k8s-ci-robot k8s-ci-robot added lgtm "Looks good to me", indicates that a PR is ready to be merged. and removed do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. labels Aug 28, 2025
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Gacko, raorudzhov

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot merged commit 59dbc01 into kubernetes:main Aug 28, 2025
27 checks passed
@k8s-infra-cherrypick-robot
Copy link
Contributor

@Gacko: new pull request created: #13859

In response to this:

/cherry-pick release-1.12

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@k8s-infra-cherrypick-robot
Copy link
Contributor

@Gacko: new pull request created: #13860

In response to this:

/cherry-pick release-1.13

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. priority/backlog Higher priority than priority/awaiting-more-evidence. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Metric nginx_ingress_controller_config_last_reload_successful does not work correctly

4 participants