Skip to content

kbuild: make network readiness checks bounded (#3197) - #3202

Open
Aniket1260 wants to merge 1 commit into
kernelci:mainfrom
Aniket1260:main
Open

kbuild: make network readiness checks bounded (#3197)#3202
Aniket1260 wants to merge 1 commit into
kernelci:mainfrom
Aniket1260:main

Conversation

@Aniket1260

Copy link
Copy Markdown

This PR addresses #3197 by making Kubernetes network readiness checks bounded and independent of unrelated third-party services.

Problem

KernelCI had two generic startup checks that used Google connectivity as an indication that the Kubernetes node network was ready.

KBuild._verify_network() performed an HTTP request to google.com without a request timeout. Additionally, non-200 HTTP responses did not decrement the retry counter, which could cause the readiness check to loop indefinitely.

The generic Python runtime template also attempted to resolve www.google.com before starting a job. Besides introducing an unnecessary dependency on an external service, this does not verify connectivity to the KernelCI services that the job actually needs.

Solution

This PR updates the network readiness handling to use the KernelCI API as the readiness target.

For KBuild._verify_network():

Added a configurable target URL.
Use the configured KernelCI API URL when available, with https://api.kernelci.org as the fallback.
Added configurable retry count, retry delay, and request timeout.
Pass the timeout directly to requests.get().
Decrement the retry counter for every failed attempt, including non-200 HTTP responses.
Avoid sleeping after the final attempt.
Report the target service and elapsed time when readiness checks are exhausted.
Raise a RuntimeError instead of terminating the process directly with sys.exit().

For the generic Python runtime template:

Removed the hard-coded dependency on www.google.com.
Resolve the hostname of the configured KernelCI API instead.
Fall back to api.kernelci.org when the API URL cannot be determined.
Bound the DNS readiness check to a fixed number of attempts.
Report the actual hostname when DNS resolution fails.
Validation

The readiness logic was tested with mocked network conditions, including:

Immediate HTTP 200 success.
Repeated non-200 responses.
Temporary failures followed by a successful response.
Connection failures.
Request timeouts.
Retry exhaustion.

Closes #3197

Signed-off-by: aniket1260 <anket1260@gmail.com>
for _ in range(10):
try:
socket.gethostbyname('www.google.com')
socket.gethostbyname(hostname)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

socket.gethostbyname() has no deadline, so the ten-iteration loop cannot interrupt a stuck DNS lookup

Comment thread kernelci/kbuild.py
while retries > 0:
try:
r = requests.get("https://google.com")
r = requests.get(target_url, timeout=timeout)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

timeout=10 is an inactivity timeout, not a total wall-clock deadline

Comment thread kernelci/kbuild.py
"""Verify network connectivity"""
# TBD: Different URL? pool of urls?
retries = 10
def _verify_network(self, url=None, max_retries=5, retry_delay=5, timeout=10):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

_verify_network() still catches every Exception; malformed URLs and programming/configuration errors become misleading network-readiness failures

Comment thread kernelci/kbuild.py
def is_dtb_artifact(artifact):
return artifact.startswith("dtbs/") and artifact.endswith(".dtb")
posix_art = artifact.replace("\\", "/")
return posix_art.startswith("dtbs/") and posix_art.endswith(".dtb")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The DTB path-normalization changes are unrelated to #3197 and are not explained in the PR description. Please remove them from this PR or submit them separately with their motivation and tests.

Their inclusion also raises concern that the complete patch may not have been carefully reviewed before submission. KernelCI’s contribution policy requires contributors to understand and take responsibility for all submitted changes, and to disclose meaningful AI assistance with an Assisted-by tag. Please review the full diff and disclose any applicable assistance.

@Aniket1260

Copy link
Copy Markdown
Author

@nuclearcat before submitting my next commit, I'll observe the changes more carefully. Thanks for your valuable insights

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make Kubernetes job network readiness checks bounded and deployment-independent

2 participants