Skip to content

Kubernetes CronJob

Bases: Job

🚀 The CronJob class is responsible for managing Kubernetes CronJobs. It extends the Job class and provides additional functionalities specific to Kubernetes CronJobs.

CLI Usage

genius cronjob sub-command Examples:

genius cronjob create_cronjob --name example-cronjob --image example-image --command "echo hello" --schedule "*/5 * * * *" --namespace geniusrise \
    --context_name arn:aws:eks:us-east-1:genius-dev:cluster/geniusrise-dev

```bash
genius cronjob delete_cronjob --name example-cronjob --namespace geniusrise \
    --context_name arn:aws:eks:us-east-1:genius-dev:cluster/geniusrise-dev
```

```bash
genius cronjob get_cronjob_status --name example-cronjob --namespace geniusrise \
    --context_name arn:aws:eks:us-east-1:genius-dev:cluster/geniusrise-dev
```

YAML Configuration:

    version: "1.0"
    cronjobs:
      - name: "example-cronjob"
        image: "example-image"
        command: "example-command"
        schedule: "*/5 * * * *"
        env_vars:
          KEY: "value"
        cpu: "100m"
        memory: "256Mi"
        storage: "1Gi"
        gpu: "1"

Extended CLI Examples
genius cronjob create_cronjob \
  --k8s_kind cronjob \
  --k8s_namespace geniusrise \
  --k8s_context_name arn:aws:eks:us-east-1:genius-dev:cluster/geniusrise-dev \
  --k8s_name example-cronjob \
  --k8s_image "genius-dev.dkr.ecr.ap-south-1.amazonaws.com/geniusrise" \
  --k8s_schedule "*/5 * * * *" \
  --k8s_env_vars '{"AWS_DEFAULT_REGION": "ap-south-1", "AWS_SECRET_ACCESS_KEY": "", "AWS_ACCESS_KEY_ID": ""}' \
  --k8s_cpu "100m" \
  --k8s_memory "256Mi"
genius cronjob delete_cronjob \
  example-cronjob \
  --namespace geniusrise \
  --context_name arn:aws:eks:us-east-1:genius-dev:cluster/geniusrise-dev
genius cronjob get_cronjob_status \
  example-cronjob \
  --namespace geniusrise \
  --context_name arn:aws:eks:us-east-1:genius-dev:cluster/geniusrise-dev

__create_cronjob_spec(image, command, schedule, env_vars={}, cpu=None, memory=None, storage=None, gpu=None, image_pull_secret_name=None)

📦 Create a Kubernetes CronJob specification.

Parameters:

Name Type Description Default
image str

Docker image for the CronJob.

required
command str

Command to run in the container.

required
env_vars dict

Environment variables for the CronJob.

{}
cpu Optional[str]

CPU requirements.

None
memory Optional[str]

Memory requirements.

None
storage Optional[str]

Storage requirements.

None
gpu Optional[str]

GPU requirements.

None
image_pull_secret_name Optional[str]

Name of the image pull secret.

None

Returns:

Type Description
client.V1CronJobSpec

client.V1CronJobSpec: The CronJob specification.

__init__()

🚀 Initialize the CronJob class for managing Kubernetes Cron Jobs.

create(name, image, schedule, command, env_vars={}, cpu=None, memory=None, storage=None, gpu=None, image_pull_secret_name=None, **kwargs)

🛠 Create a Kubernetes CronJob.

Parameters:

Name Type Description Default
name str

Name of the CronJob.

required
image str

Docker image for the CronJob.

required
command str

Command to run in the container.

required
schedule str

Cron schedule.

required
env_vars dict

Environment variables for the CronJob.

{}

create_parser(parser)

🎛 Create a parser for CLI commands related to Cron Job functionalities.

Parameters:

Name Type Description Default
parser ArgumentParser

The main parser.

required

Returns:

Name Type Description
ArgumentParser ArgumentParser

The parser with subparsers for each command.

delete(name)

🗑 Delete a Kubernetes CronJob.

Parameters:

Name Type Description Default
name str

Name of the CronJob to delete.

required

run(args)

🚀 Run the Cron Job manager.

Parameters:

Name Type Description Default
args Namespace

The parsed command line arguments.

required

status(name)

📊 Get the status of a Kubernetes CronJob.

Parameters:

Name Type Description Default
name str

Name of the CronJob.

required

Returns:

Name Type Description
dict V1CronJob

Status of the CronJob.