Kube Grading#

Kube Grader#

class GraderPod(**kwargs: Any)[source]#

Bases: traitlets.config.configurable.LoggingConfigurable

Wrapper for a kubernetes pod that supports polling of the pod’s status.

property name: str#
property namespace: str#
poll_interval#

An int trait.

property polling: _asyncio.Task#
stop_polling() None[source]#
class KubeAutogradeExecutor(**kwargs: Any)[source]#

Bases: grader_service.autograding.local_grader.LocalAutogradeExecutor

Runs an autograde job in a kubernetes cluster as a pod. The cluster has to have a shared persistent volume claim that is mounted in the input and output directories so that both the service and the executor pods have access to the files. The service account of the grader service has to have permission to get, update, create and delete pods, pod status and pod logs.

default_image_name#

A trait which is callable.

Notes

Classes are callable, as are instances with a __call__() method.

get_image() str[source]#

Returns the image name based on the lecture and assignment. If an image config file exists and has been specified it will first be queried for an image name. If the image name cannot be found in the config file or none has been specified the image name will be determined by the default_image_name function which takes the lecture and assignment as parameters and is specified in the config. The default implementation of this function is to return the lecture code followed by ‘_image’. :return: The image name as determined by this method.

image_config_path#

A trait for unicode strings.

kube_context#

A trait for unicode strings.

start_pod() grader_service.autograding.kube.kube_grader.GraderPod[source]#

Starts a pod in the default namespace with the commit hash as the name of the pod. The image is determined by the get_image method. :return:

volume_mounts#

An instance of a Python list.

volumes#

An instance of a Python list.

Util#

generate_hashed_slug(slug, limit=63, hash_length=6)[source]#

Generate a unique name that’s within a certain length limit

Most k8s objects have a 63 char name limit. We wanna be able to compress larger names down to that if required, while still maintaining some amount of legibility about what the objects really are.

If the length of the slug is shorter than the limit - hash_length, we just return slug directly. If not, we truncate the slug to (limit - hash_length) characters, hash the slug and append hash_length characters from the hash to the end of the truncated slug. This ensures that these names are always unique no matter what.

get_k8s_model(model_type, model_dict)[source]#

Returns an instance of type specified model_type from an model instance or represantative dictionary.

make_pod(name, cmd, image, image_pull_policy, working_dir=None, volumes=None, volume_mounts=None, labels=None, annotations=None, tolerations=None) kubernetes.client.models.v1_pod.V1Pod[source]#
update_k8s_model(target, changes, logger=None, target_name=None, changes_name=None)[source]#

Takes a model instance such as V1PodSpec() and updates it with another model, which is allowed to be a dict or another model instance of the same type. The logger is used to warn if any truthy value in the target is is overridden. The target_name parameter can for example be “pod.spec”, and changes_name parameter could be “extra_pod_config”. These parameters allows the logger to write out something more meaningful to the user whenever something is about to become overridden.