Skip to content

Commit

Permalink
Merge pull request #64 from pit1sIBM/add-job-check
Browse files Browse the repository at this point in the history
Verify: add verify function for k8s Jobs
  • Loading branch information
gabe-l-hart committed Apr 29, 2024
2 parents 7fac9ff + a6953ad commit f38d89a
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
7 changes: 7 additions & 0 deletions oper8/verify_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,12 @@ def verify_pod(object_state: dict) -> bool:
return _verify_condition(object_state, "Ready", True)


def verify_job(object_state: dict) -> bool:
"""Verify that a job has completed successfully"""
# https://kubernetes.io/docs/reference/kubernetes-api/workload-resources/job-v1/#JobStatus
return _verify_condition(object_state, "Completed", True)


def verify_deployment(object_state: dict) -> bool:
"""Verify that all members of a deployment are ready
and all members are rolled out to new version in case of update.
Expand Down Expand Up @@ -186,6 +192,7 @@ def verify_subsystem(object_state: dict, desired_version: str = None) -> bool:

_resource_verifiers = {
"Pod": verify_pod,
"Job": verify_job,
"Deployment": verify_deployment,
"StatefulSet": verify_statefulset,
}
Expand Down
57 changes: 57 additions & 0 deletions tests/test_verify_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,63 @@ def test_verify_pod_null_namespace():
)


##########
## Jobs ##
##########


def test_verify_job_completed():
"""Make sure a completed job verifies cleanly"""
assert run_test_verify(kind="Job", conditions=[make_condition("Completed", True)])


def test_verify_job_failed():
"""Make sure a failed job returns as unverified"""
assert not run_test_verify(kind="Job", conditions=[make_condition("Failed", True)])


def test_verify_job_suspended():
"""Make sure a suspended job returns as unverified"""
assert not run_test_verify(
kind="Job", conditions=[make_condition("Suspended", True)]
)


def test_verify_job_missing():
"""Make sure a missing job returns as unverified"""
assert not run_test_verify(kind="Job", populate_state=None)


def test_verify_job_no_conditions():
"""Make sure a job with no conditions returns as unverified"""
assert not run_test_verify(kind="Job", conditions=[])


def test_verify_job_no_status():
"""Make sure a job with no status returns as unverified"""
assert not run_test_verify(kind="Job", conditions=None)


def test_verify_job_separate_namespace():
"""Make sure a completed job from a different namespace verifies cleanly"""
assert run_test_verify(
kind="Job",
conditions=[make_condition("Completed", True)],
obj_namespace="adifferent",
search_namespace="adifferent",
)


def test_verify_job_null_namespace():
"""Make sure a completed job in the same namespace verifies cleanly"""
assert run_test_verify(
kind="Job",
conditions=[make_condition("Completed", True)],
obj_namespace=TEST_NAMESPACE,
search_namespace=_SESSION_NAMESPACE,
)


#################
## Deployments ##
#################
Expand Down

0 comments on commit f38d89a

Please sign in to comment.