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

Allow overriding of the default response format for custom errors #7245

Merged

Conversation

ianroberts
Copy link
Contributor

What this PR does / why we need it:

Currently the example custom-errors back-end always defaults to responding with HTML error messages if the caller's Accept header does not specify otherwise. This is sub-optimal in cases where, for example, we are generating custom errors for an ingress that refers to a REST API endpoint whose default response format is e.g. JSON - in the absence of an Accept header, the default format of the error messages should be the same as the default format of the endpoint's own successful responses.

This PR modifies the example custom error generator so it can take the default response MIME type from an environment variable, instead of always using text/html. HTML is still the default if the variable is not set, to preserve backwards compatibility, but this makes it possible to set DEFAULT_RESPONSE_FORMAT=application/json in the deployment spec for the case described above to make a particular instance respond in JSON by default.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

How Has This Been Tested?

I am running a copy of this code in my own cluster successfully.

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I've read the CONTRIBUTION guide
  • I have added tests to cover my changes. N/A
  • All new and existing tests passed. N/A - this is a change to example code that no tests depend on

@k8s-ci-robot
Copy link
Contributor

Thanks for your pull request. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please follow instructions at https://git.k8s.io/community/CLA.md#the-contributor-license-agreement to sign the CLA.

It may take a couple minutes for the CLA signature to be fully registered; after that, please reply here with a new comment and we'll verify. Thanks.


  • If you've already signed a CLA, it's possible we don't have your GitHub username or you're using a different email address. Check your existing CLA data and verify that your email is set on your git commits.
  • If you signed the CLA as a corporation, please sign in with your organization's credentials at https://identity.linuxfoundation.org/projects/cncf to be authorized.
  • If you have done the above and are still having issues with the CLA being reported as unsigned, please log a ticket with the Linux Foundation Helpdesk: https://support.linuxfoundation.org/
  • Should you encounter any issues with the Linux Foundation Helpdesk, send a message to the backup e-mail support address at: [email protected]

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/test-infra repository. I understand the commands that are listed here.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. label Jun 16, 2021
@k8s-ci-robot
Copy link
Contributor

Welcome @ianroberts!

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
Copy link
Contributor

Hi @ianroberts. 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/test-infra repository.

@k8s-ci-robot k8s-ci-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Jun 16, 2021
@ianroberts
Copy link
Contributor Author

CLA signed.

@k8s-ci-robot k8s-ci-robot added 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 Jun 16, 2021
@ianroberts ianroberts force-pushed the custom-errors-default-format branch from 6d83b85 to 227ca18 Compare June 16, 2021 12:03
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Jun 16, 2021
@rikatz rikatz changed the base branch from master to main July 16, 2021 13:15
@rikatz
Copy link
Contributor

rikatz commented Aug 6, 2021

/ok-to-test

@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. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Aug 6, 2021
@rikatz
Copy link
Contributor

rikatz commented Aug 6, 2021

@ianroberts thanks for your PR!
As this gets merged, the image will need to be promoted and a new PR opened to point to the new image.

I'll post the sha of the new image here

@rikatz
Copy link
Contributor

rikatz commented Aug 6, 2021

/retest

@rikatz
Copy link
Contributor

rikatz commented Aug 6, 2021

@ianroberts can you please rebase over main? This problem is a bit well known, and was solved on past :)

Thanks!

Rather than hard-coding the default response format as HTML, allow the default to be overridden by an environment variable.  For example, given a REST API endpoint that defaults to responding in JSON, you may wish to configure the error messages to be JSON by default as well.
@ianroberts ianroberts force-pushed the custom-errors-default-format branch from 227ca18 to dcd8bca Compare August 6, 2021 19:10
@ianroberts
Copy link
Contributor Author

Doesn't seem to have helped, sorry. Though I can't see how anything I've changed in my PR could cause it to fail this way, as I haven't touched any code in the ingress controller itself, only the custom errors image.

@rikatz
Copy link
Contributor

rikatz commented Aug 6, 2021

hum, this may be my fault, as I just did some changes in image runner. Let me check here

@rikatz
Copy link
Contributor

rikatz commented Aug 6, 2021

https://prow.k8s.io/view/gs/kubernetes-jenkins/pr-logs/pull/ingress-nginx/7457/pull-ingress-nginx-test/1423734457763893248

yeap, tried to reproduce and got the same error.

Let me fix this here

@rikatz
Copy link
Contributor

rikatz commented Aug 6, 2021

@ianroberts please rebase again, now this should work :)

This was due to the migration to go v1.16 and some changes

@rikatz
Copy link
Contributor

rikatz commented Aug 6, 2021

/retest

@rikatz
Copy link
Contributor

rikatz commented Aug 6, 2021

no need to rebase
/lgtm
/approve
Thanks!

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Aug 6, 2021
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ianroberts, rikatz

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 added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 6, 2021
@k8s-ci-robot k8s-ci-robot merged commit e5e3305 into kubernetes:main Aug 6, 2021
@rikatz
Copy link
Contributor

rikatz commented Aug 6, 2021

So I though this image was published on gcr.k8s.io but it isn't so no further action seems to be required.

Thanks

rchshld pushed a commit to joomcode/ingress-nginx that referenced this pull request May 19, 2023
Rather than hard-coding the default response format as HTML, allow the default to be overridden by an environment variable.  For example, given a REST API endpoint that defaults to responding in JSON, you may wish to configure the error messages to be JSON by default as well.
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. 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. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants