Skip to content
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

Add container option in waitjob read namespace pod log #134

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 19 additions & 18 deletions contents/job-wait.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,19 @@ def wait():
retries = int(environ.get("RD_CONFIG_RETRIES"))
sleep = float(environ.get("RD_CONFIG_SLEEP"))
show_log = environ.get("RD_CONFIG_SHOW_LOG") == "true"
container = environ.get("RD_CONFIG_CONTAINER")

# Poll for completion if retries
retries_count = 0
completed = False


while True:
common.connect()

#validate retries
# validate retries
if retries_count != 0:
log.warning("An error occurred - retries: {0}".format(retries_count))
log.warning(
"An error occurred - retries: {0}".format(retries_count))
retries_count = retries_count + 1

if retries_count > retries:
Expand All @@ -46,23 +47,23 @@ def wait():

if show_log and not completed:
log.debug("Searching for pod associated with job")

start_time = time.time()
timeout = 300 #Revisar si este tiempo es suficiente para pods que no logran ser creados
timeout = 300 # Revisar si este tiempo es suficiente para pods que no logran ser creados
while True:
core_v1 = client.CoreV1Api()
try:
#get available pod
# get available pod
pod_list = core_v1.list_namespaced_pod(
namespace,
label_selector="job-name==" + name
)
first_item = pod_list.items[0]
pod_name = first_item.metadata.name

#try get available log
# try get available log
core_v1.read_namespaced_pod_log(name=pod_name,
namespace=namespace)
namespace=namespace, container=container)
break
except ApiException as ex:
log.warning("Pod is not ready, status: %d", ex.status)
Expand All @@ -73,19 +74,20 @@ def wait():
time.sleep(15)
if timeout and time.time() - start_time > timeout: # pragma: no cover
raise TimeoutError

log.info("Fetching logs from pod: {0}".format(pod_name))

if retries_count == 1:
log.info("========================== job log start ==========================")
log.info(
"========================== job log start ==========================")

w = watch.Watch()
for line in w.stream(core_v1.read_namespaced_pod_log,
name=pod_name,
namespace=namespace):
name=pod_name,
namespace=namespace, container=container):
print(line.encode('ascii', 'ignore'))

#check status job
# check status job
batch_v1 = client.BatchV1Api()

api_response = batch_v1.read_namespaced_job_status(
Expand All @@ -105,13 +107,13 @@ def wait():

if completed:
if show_log:
log.info("=========================== job log end ===========================")
log.info(
"=========================== job log end ===========================")
break

log.info("Waiting for job completion")
time.sleep(sleep)


if api_response.status.succeeded:
log.info("Job succeeded")
sys.exit(0)
Expand All @@ -124,13 +126,12 @@ def wait():
sys.exit(1)



def main():
if environ.get("RD_CONFIG_DEBUG") == "true":
log.setLevel(logging.DEBUG)
log.debug("Log level configured for DEBUG")

#common.connect()
# common.connect()
wait()


Expand Down
6 changes: 6 additions & 0 deletions plugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1819,6 +1819,12 @@ providers:
required: false
renderingOptions:
groupName: Authentication
- name: container
type: String
title: "Container"
default: ""
description: "Get logs from this container"
required: false
- name: url
type: String
title: "Cluster URL"
Expand Down