Make job_crud example print the correct job status after job creation#1418
Make job_crud example print the correct job status after job creation#1418k8s-ci-robot merged 7 commits intokubernetes-client:masterfrom
Conversation
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
|
@yliaog Please check this and let me know your comments. Thanks |
| 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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
@yliaog Do i need to write a function to watch the status and print? If yes can you please elaborate it?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
@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?
There was a problem hiding this comment.
It would be great if you can print the watch events until the job succeeded/failed. This can be put into a separate function.
| name=JOB_NAME, | ||
| namespace="default") | ||
| if api_response.status.succeeded is not None or api_response.status.failed is not None: | ||
| job_completed = True |
There was a problem hiding this comment.
this is hot loop, please add sleep(...)
| body=job, | ||
| namespace="default") | ||
| print("Job created. status='%s'" % str(api_response.status)) | ||
| print("Job created. status='%s'" % str(get_job_status(api_instance))) |
There was a problem hiding this comment.
better to keep the previous print line 56 to show the Job is created, then poll for job running status until job is completed
There was a problem hiding this comment.
that depends on the how long it takes to complete the job, 1s is probably ok.
There was a problem hiding this comment.
@yliaog Please check the code changes now. Thanks.
| body=job, | ||
| namespace="default") | ||
| print("Job created. status='%s'" % str(api_response.status)) | ||
| print("Job status='%s'" % str(get_job_status(api_instance))) |
There was a problem hiding this comment.
better to move the print to the polling loop below, so that every 1s, the status is printed out
There was a problem hiding this comment.
@yliaog Please check the updated code. Thanks
|
/lgtm |
|
/home/travis/build/kubernetes-client/python/kubernetes/../examples/job_crud.py:67:80: E501 line too long (95 > 79 characters) from os import path import yaml -from time import sleepfrom kubernetes import client, config JOB_NAME = "pi" def get_job_status(api_instance): |
|
@steveprabha |
@yliaog just ran the command pycodestyle test.py and resolved the below error in new changes. Please check and let me know. Thanks |
|
|
||
| import yaml | ||
|
|
||
| from time import sleep |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
@roycaihw I have made the above mentioned change. Please verify now. Thanks
There was a problem hiding this comment.
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
There was a problem hiding this comment.
https://travis-ci.org/github/kubernetes-client/python/jobs/770874568 has the diff you can check out
|
/lgtm |
|
[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 DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
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