Skip to content

Add Health class to call health check endpoints on current context #2035

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

Merged
merged 7 commits into from
Nov 24, 2024

Conversation

feloy
Copy link
Contributor

@feloy feloy commented Nov 19, 2024

Add an Health class with 2 public methods livez and readyz to check the health check endpoints of the current context.

If these endpoints are not served (status 404), the deprecated healthz is checked. If this endpoint healthz is also not served (status 404), the cluster is considered healthy, else its result is used.

@k8s-ci-robot k8s-ci-robot added the do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. label Nov 19, 2024
@k8s-ci-robot k8s-ci-robot added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Nov 19, 2024
@feloy feloy changed the base branch from master to release-1.x November 19, 2024 11:00
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Nov 19, 2024
@feloy
Copy link
Contributor Author

feloy commented Nov 19, 2024

Thanks @cjihrig for your review. I've made the changes, and added a unit test on an uncovered case

@feloy feloy requested a review from cjihrig November 19, 2024 15:10
Copy link
Contributor

@cjihrig cjihrig left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@feloy feloy requested a review from cjihrig November 19, 2024 15:26
src/health.ts Outdated
const status = response.status;
if (status === 200) {
return true;
} else if (status === 404) {
Copy link
Contributor

Choose a reason for hiding this comment

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

remove else since there is return in the preceding case.

src/health.ts Outdated
return true;
}
return this.healthz(opts);
} else {
Copy link
Contributor

Choose a reason for hiding this comment

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

remove else since all paths above end in return

@brendandburns
Copy link
Contributor

Thanks for the PR. Minor comments, then LGTM

(and special thanks for adding tests!)

@feloy feloy requested a review from brendandburns November 19, 2024 20:25
src/health.ts Outdated
Comment on lines 51 to 52
} catch {
throw new Error('Error occurred in health request');

This comment was marked as outdated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I get an error when I try to build with this parameter:

npm run build

> @kubernetes/[email protected] build
> tsc

src/health.ts:52:65 - error TS2554: Expected 0-1 arguments, but got 2.

52             throw new Error('Error occurred in health request', { cause: err });
                                                                   ~~~~~~~~~~~~~~


Found 1 error in src/health.ts:52

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changing the tsconfig with the following would fix the problem, but I'm not sure of the potential side-effects:

  "compilerOptions": {
    "lib": ["es2022"],

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, ok. There must be a TypeScript setting that needs to be tweaked in the project since cause is a newer addition to the spec. I will resolve my comment.

@feloy feloy requested a review from cjihrig November 19, 2024 20:45
@feloy
Copy link
Contributor Author

feloy commented Nov 20, 2024

I added a commit, to export the Health class

@feloy
Copy link
Contributor Author

feloy commented Nov 20, 2024

I also made a change to how the abortcontroller signal was managed. Previously, the abort controller passed to fetch was not accessible. I changed to use the one (if any) passed as parameter, so the caller can abort the request

@feloy feloy marked this pull request as draft November 20, 2024 12:39
@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Nov 20, 2024
@feloy
Copy link
Contributor Author

feloy commented Nov 20, 2024

setting as draft, the time to make some test, to find the best way for the user to handle abort

@feloy feloy marked this pull request as ready for review November 20, 2024 15:46
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Nov 20, 2024
@feloy
Copy link
Contributor Author

feloy commented Nov 20, 2024

I made one more change to throw the original error when it is an AbortError, so the caller can detect that the call has been aborted

It is ready for review again

Sorry for all these afterward changes

@brendandburns
Copy link
Contributor

Looks good to me. I'd like to get an LGTM from @cjihrig also since he reviewed earlier and then we can merge.

@feloy
Copy link
Contributor Author

feloy commented Nov 22, 2024

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: cjihrig, feloy Once this PR has been reviewed and has the lgtm label, please assign mstruebing for approval. For more information see the Kubernetes Code Review Process.

/assign mstruebing

@brendandburns
Copy link
Contributor

/lgtm
/approve

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

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: brendandburns, cjihrig, feloy

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 Nov 24, 2024
@k8s-ci-robot k8s-ci-robot merged commit 467300e into kubernetes-client:release-1.x Nov 24, 2024
7 checks passed
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. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants