Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Changes made in wacth.py to print Empty newlines that are skipped when watching pod logs.#2372

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
k8s-ci-robot merged 9 commits intokubernetes-client:masterfromp172913:master
Mar 21, 2025

Conversation

p172913
Copy link
Contributor

What type of PR is this?
/kind bug

What this PR does / why we need it:
This PRs print Empty newlines that are skipped when watching pod logs. Changed yield login in stream to print only single empty line between the logs.

Which issue(s) this PR fixes:
Fixes#2358

Special notes for your reviewer:
This is my first time contributing, so please let me know if I made the change successfully!

Does this PR introduce a user-facing change?
None

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:
None

Changes made in wacth.py to print Empty newlines that are skipped when watching pod logs.
@k8s-ci-robotk8s-ci-robot added kind/bugCategorizes issue or PR as related to a bug. do-not-merge/release-note-label-neededIndicates that a PR should not merge because it's missing one of the release note labels. labelsMar 9, 2025
@linux-foundation-easyclaLinux Foundation: EasyCLA
Copy link

linux-foundation-easyclabot commentedMar 9, 2025
edited
Loading

CLA Signed

The committers listed above are authorized under a signed CLA.

@k8s-ci-robotk8s-ci-robot added the cncf-cla: noIndicates the PR's author has not signed the CNCF CLA. labelMar 9, 2025
@k8s-ci-robot
Copy link
Contributor

Welcome@p172913!

It looks like this is your first PR tokubernetes-client/python 🎉. Please refer to ourpull 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-client/python hasits own contribution guidelines.

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

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

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robotk8s-ci-robot added size/SDenotes a PR that changes 10-29 lines, ignoring generated files. cncf-cla: yesIndicates the PR's author has signed the CNCF CLA. and removed cncf-cla: noIndicates the PR's author has not signed the CNCF CLA. labelsMar 9, 2025
@p172913
Copy link
ContributorAuthor

@yliaog,@fabianvf Please review my PR and approve.

@yliaog
Copy link
Contributor

how did you test it? please add a test to this PR

@p172913
Copy link
ContributorAuthor

p172913 commentedMar 12, 2025
edited
Loading

@yliaog I installed the kubernetes client in editable mode on local, made changes that are mentioned in PR and ran the code given in the issue as an test. It was working fine. And I am seeing output as expected. If needed I can add the test I did in tests...
Here is the screenshot of the output:
image

This file is to test whether empty line are printed when watch function in the kubernetes python client is used.
@k8s-ci-robotk8s-ci-robot added size/MDenotes a PR that changes 30-99 lines, ignoring generated files. and removed size/SDenotes a PR that changes 10-29 lines, ignoring generated files. labelsMar 13, 2025
@p172913
Copy link
ContributorAuthor

@yliaog As per your request I commited a test case. Please review and approve my PR.

@yliaog
Copy link
Contributor

thanks for the PR, could you add a unit test in kubernetes/base/watch/watch_test.py ?

@p172913
Copy link
ContributorAuthor

@yliaog I added it in kubernetes/test/test_pod_logs.py. If i is needed in kubernetes/base/watch/watch_test.py. I can add it there.

@yliaog
Copy link
Contributor

please add a test in kubernetes/base/watch/watch_test.py

Added a unit test name test_pod_log_empty_lines to check if watch is printing empty lines. And made changes in test_watch_with_interspersed_newlines as the watch is also printing empty line. Added a condition to check for empty lines in ogs to avoid the errors.
@k8s-ci-robotk8s-ci-robot added size/LDenotes a PR that changes 100-499 lines, ignoring generated files. and removed size/MDenotes a PR that changes 30-99 lines, ignoring generated files. labelsMar 18, 2025
Deleting file with tests added in test/test_pod_los.py
@p172913
Copy link
ContributorAuthor

@yliaog added unit test in kubernetes/base/watch/watch_test.py with name test_pod_log_empty_lines. And made changes in test_watch_with_interspersed_newlines test case to avoid empty line exception.

yield line # Normal non-empty line
last_was_empty = False
elif not last_was_empty:
yield '/n' # Only yield one empty line
Copy link
Contributor

Choose a reason for hiding this comment

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

should it be '\n' ?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Actually it has to be '' (an empty string) if yield an empty string. We need to change unmarshal_event function also. If needed I can change '/n' to '' and will change unmarshal_event function.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Replace '/n' with '' (empty string) and adjusted unmarshal_event function in watch.py

Changes made in unmarshal_event for not having issues with empty lines.

def test_pod_log_empty_lines(self):
pod_name = "demo-bug"
# Manifest with busybax to keep pod engaged for sometiem
Copy link
Contributor

Choose a reason for hiding this comment

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

typo: sometiem ?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

I will adjust

def test_pod_log_empty_lines(self):
pod_name = "demo-bug"
# Manifest with busybax to keep pod engaged for sometiem
pod_manifest = {
Copy link
Contributor

Choose a reason for hiding this comment

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

where is pod_manifest used?

Copy link
ContributorAuthor

@p172913p172913Mar 19, 2025
edited
Loading

Choose a reason for hiding this comment

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

I used minikube before replacing it with mock function. After checking locally forgot to delete it

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Just deleted pod_manifest from watch_test.py.

Removed pod_manifest from watch_test.py.
# Print outputs
print(f"Captured logs: {log_output}")
# self.assertTrue(any("Hello from Docker" in line for line in log_output))
self.assertTrue(any(line.strip() == "" for line in log_output), "No empty lines found in logs")
Copy link
Contributor

Choose a reason for hiding this comment

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

could you add an assertion that ensures the log_output has exactly what is expected, the whole log?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Changed assertive statement to make sure entire output logs are verified.

Changes made to check whether entire log is printed or not.
#Mock logs used for this test
w.stream = Mock(return_value=[
"Hello from Docker",
"", # Empty line
Copy link
Contributor

Choose a reason for hiding this comment

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

add another empty line here?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Added few empty lines to the test case.

Changes made in watch.py to print multiple empty line if necessary.
As per request added few empty lines to test case in watch_test.py
@yliaog
Copy link
Contributor

/lgtm
/approve

@k8s-ci-robotk8s-ci-robot added the lgtm"Looks good to me", indicates that a PR is ready to be merged. labelMar 21, 2025
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR isAPPROVED

This pull-request has been approved by:p172913,yliaog

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

The pull request process is describedhere

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-robotk8s-ci-robot added the approvedIndicates a PR has been approved by an approver from all required OWNERS files. labelMar 21, 2025
@yliaog
Copy link
Contributor

/release-note-none

@k8s-ci-robotk8s-ci-robot added release-note-noneDenotes a PR that doesn't merit a release note. and removed do-not-merge/release-note-label-neededIndicates that a PR should not merge because it's missing one of the release note labels. labelsMar 21, 2025
@k8s-ci-robotk8s-ci-robot merged commitbd32360 intokubernetes-client:masterMar 21, 2025
10 checks passed
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@yliaogyliaogyliaog left review comments

@fabianvffabianvfAwaiting requested review from fabianvf

Assignees

@yliaogyliaog

Labels
approvedIndicates a PR has been approved by an approver from all required OWNERS files.cncf-cla: yesIndicates the PR's author has signed the CNCF CLA.kind/bugCategorizes issue or PR as related to a bug.lgtm"Looks good to me", indicates that a PR is ready to be merged.release-note-noneDenotes a PR that doesn't merit a release note.size/LDenotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

Empty newlines skipped when watching pod logs
3 participants
@p172913@k8s-ci-robot@yliaog

[8]ページ先頭

©2009-2025 Movatter.jp