Skip to content

Make job_crud example print the correct job status after job creation#1418

Merged
k8s-ci-robot merged 7 commits intokubernetes-client:masterfrom
prabha1331:patch-5
May 13, 2021
Merged

Make job_crud example print the correct job status after job creation#1418
k8s-ci-robot merged 7 commits intokubernetes-client:masterfrom
prabha1331:patch-5

Conversation

@prabha1331
Copy link
Copy Markdown
Contributor

create_job function was not printing the current status of the job. Modified the create_job function to call read_namespaced_job_status in order to get the current job status

create_job function was not printing the current status of the job. Modified the create_job function to call read_namespaced_job_status in order to get the current job status
@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Apr 18, 2021
@k8s-ci-robot k8s-ci-robot requested review from roycaihw and yliaog April 18, 2021 10:48
@k8s-ci-robot k8s-ci-robot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Apr 18, 2021
@prabha1331
Copy link
Copy Markdown
Contributor Author

@yliaog Please check this and let me know your comments. Thanks

Comment thread examples/job_crud.py Outdated
namespace="default")
print("Job created. status='%s'" % str(api_response.status))
# Need to wait for a second for the job status to update
sleep(1)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

api_response.status is the status immediately after creating 'job'. then controller will run to update the job status as the job is making progress. the time to take for job to run to completion is not determined, it could be short, could be long. the way to get status update is to Watch it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@yliaog Do i need to write a function to watch the status and print? If yes can you please elaborate it?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

https://github.com/kubernetes-client/python/blob/master/examples/pod_namespace_watch.py has an example for 'watch', or, you may periodically poll for status update.

Copy link
Copy Markdown
Contributor Author

@prabha1331 prabha1331 Apr 20, 2021

Choose a reason for hiding this comment

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

@yliaog Should we just print the status as soon as JOB_NAME get into Initialized Phase in the watch? Or should we wait for the Job to get into Running/Completed phase and then print the status?

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.

It would be great if you can print the watch events until the job succeeded/failed. This can be put into a separate function.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@roycaihw @yliaog I have updated the code to Poll for status update until success/failure. Please check.

@roycaihw roycaihw changed the title Fix issue #1395 Make job_crud example print the correct job status after job creation Apr 20, 2021
@prabha1331 prabha1331 requested a review from yliaog May 2, 2021 16:10
Comment thread examples/job_crud.py
name=JOB_NAME,
namespace="default")
if api_response.status.succeeded is not None or api_response.status.failed is not None:
job_completed = True
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this is hot loop, please add sleep(...)

Comment thread examples/job_crud.py Outdated
body=job,
namespace="default")
print("Job created. status='%s'" % str(api_response.status))
print("Job created. status='%s'" % str(get_job_status(api_instance)))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

better to keep the previous print line 56 to show the Job is created, then poll for job running status until job is completed

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@yliaog sleep for 1 sec is good?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

that depends on the how long it takes to complete the job, 1s is probably ok.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@yliaog Please check the code changes now. Thanks.

Comment thread examples/job_crud.py Outdated
body=job,
namespace="default")
print("Job created. status='%s'" % str(api_response.status))
print("Job status='%s'" % str(get_job_status(api_instance)))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

better to move the print to the polling loop below, so that every 1s, the status is printed out

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@yliaog Please check the updated code. Thanks

Copy link
Copy Markdown
Contributor Author

@prabha1331 prabha1331 May 8, 2021

Choose a reason for hiding this comment

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

@yliaog @roycaihw Do you have any idea why the travis-ci build is failing?

@yliaog
Copy link
Copy Markdown
Contributor

yliaog commented May 7, 2021

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added lgtm "Looks good to me", indicates that a PR is ready to be merged. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels May 7, 2021
@yliaog
Copy link
Copy Markdown
Contributor

yliaog commented May 10, 2021

/home/travis/build/kubernetes-client/python/kubernetes/../examples/job_crud.py:67:80: E501 line too long (95 > 79 characters)
diff --git a/examples/job_crud.py b/examples/job_crud.py
index 23282bd..eb66789 100644
--- a/examples/job_crud.py
+++ b/examples/job_crud.py
@@ -17,11 +17,10 @@ Creates, updates, and deletes a job object.
"""

from os import path
+from time import sleep

import yaml

-from time import sleep

from kubernetes import client, config

JOB_NAME = "pi"
@@ -59,7 +58,6 @@ def create_job(api_instance, job):
get_job_status(api_instance)

def get_job_status(api_instance):
job_completed = False
while not job_completed:
ERROR: InvocationError for command /home/travis/build/kubernetes-client/python/scripts/update-pycodestyle.sh (exited with code 1)

@yliaog
Copy link
Copy Markdown
Contributor

yliaog commented May 10, 2021

@steveprabha
the output is from here: https://travis-ci.org/github/kubernetes-client/python/jobs/769884870

@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 11, 2021
@prabha1331
Copy link
Copy Markdown
Contributor Author

@steveprabha
the output is from here: https://travis-ci.org/github/kubernetes-client/python/jobs/769884870

@yliaog just ran the command pycodestyle test.py and resolved the below error in new changes. Please check and let me know. Thanks
test.py:68:80: E501 line too long (95 > 79 characters)

Comment thread examples/job_crud.py Outdated

import yaml

from time import sleep
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 pycodestyle test is picky about the import. Could you make it

from os import path
from time import sleep
 
import yaml

from kubernetes import client, config

?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@roycaihw I have made the above mentioned change. Please verify now. Thanks

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

are there any special character on the line after " from time import sleep"?

==============================================
diff --git a/examples/job_crud.py b/examples/job_crud.py
index 2174ef7..ab02761 100644
--- a/examples/job_crud.py
+++ b/examples/job_crud.py
@@ -18,7 +18,7 @@ Creates, updates, and deletes a job object.

from os import path
from time import sleep

import yaml

from kubernetes import client, config

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@yliaog
Copy link
Copy Markdown
Contributor

yliaog commented May 13, 2021

/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 May 13, 2021
@k8s-ci-robot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

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

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

The pull request process is described here

Details 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 a126ab0 into kubernetes-client:master May 13, 2021
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/S Denotes a PR that changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants