# KubeJobSub

Writing YAML files for submitting jobs to Kubernetes (or for anything else, for that matter) is the opposite of fun.

This makes that process much easier, although very specific to my own workflows.

### Installation

### Usage

KubeJobSub can do two things (more may come in the future) - submit jobs to a kubernetes cluster, and get some info about
the cluster you're using.

```
usage: KubeJobSub [-h] {submit,info} ...

KubeJobSub

positional arguments:
  {submit,info}  SubCommand Help
    submit       Submits a job to your kubernetes cluster. Configured to
                 assume you're using azure with a file mount.
    info         Tells you about your kubernetes cluster - number of nodes,and
                 specs/usage for each node.
```

The `submit` subcommand makes the assumption that you're using an Azure file share and want to mount it as a volume.
Support for other things might get added eventually, depending on needs. It will write a YAML file for you
, submit a job to Kubernetes based on that file, and then clean it up. It will do some checks for you to make sure your
job actually gets submitted - it ensures no other jobs have the same name as what you've specified, as well as making sure
that you haven't requested more CPU/Memory than a node in your cluster has.

For example, the following command would do some read trimming for you, and store the results in the mounted file share.
This assumes the FASTQ files you want to trim are in the root of your file share:

```
KubeJobSub submit -j trim -c "bbduk.sh in=/mnt/azure/2014-SEQ-0276_S2_L001_R1_001.fastq.gz in2=/mnt/azure/2014-SEQ-0276_S2_L001_R2_001.fastq.gz out=/mnt/azure/trimmed_R1.fastq.gz out2=/mnt/azure/trimmed_R2.fastq.gz ref=adapters trimq=10 qtrim=w minlength=50" -i cathrine98/bbmap -share my_share_name -n 3 -m 4
```

Full usage options for the `submit` subcommand are below.


```
usage: KubeJobSub submit [-h] -j JOB_NAME -c COMMAND -i IMAGE [-n NUM_CPU]
                            [-m MEMORY] [-v VOLUME] -share SHARE
                            [-secret SECRET] [-k]

optional arguments:
  -h, --help            show this help message and exit
  -j JOB_NAME, --job_name JOB_NAME
                        Name of job.
  -c COMMAND, --command COMMAND
                        The command you want to run. Put it in double quotes.
                        (")
  -i IMAGE, --image IMAGE
                        Docker image to create container from.
  -n NUM_CPU, --num_cpu NUM_CPU
                        Number of CPUs to request for your job. Must be an
                        integer greater than 0. Defaults to 1.
  -m MEMORY, --memory MEMORY
                        Amount of memory to request, in GB. Defaults to 2.
  -v VOLUME, --volume VOLUME
                        The mountpath for your azure file share. Defaults to
                        /mnt/azure
  -share SHARE, --share SHARE
                        Name of Azure file share that you want mounted to the
                        point specified by -v
  -secret SECRET, --secret SECRET
                        The name of the secret created by kubectl for azure
                        file mounting. Defaults to azure-secret. See
                        https://docs.microsoft.com/en-us/azure/aks/azure-
                        files-volume for more information on creating your
                        own.
  -k, --keep            A YAML file will be created to submit your job.
                        Deleted by default once job is submitted, but if this
                        flag is active it will be kept.

```

The info subcommand has no options - just run `KubeJobSub info`. You should see something like:

```
Number of nodes in cluster: 2
NodeName	CPU_Capacity	CPU_Usage	Memory_Capacity	Memory_Usage
aks-nodepool1-25823294-2	4	(28%)	8145492Ki	(26%)
aks-nodepool1-25823294-3	4	(41%)	8145492Ki	(49%)
```