Files
canine/resources/k8/stateless/cron_job.yaml
2025-11-16 09:25:55 -08:00

80 lines
3.1 KiB
YAML

apiVersion: batch/v1
kind: CronJob
metadata:
name: <%= service.name %>
namespace: <%= project.name %>
labels:
caninemanaged: 'true'
app: <%= service.name %>
spec:
schedule: "<%= service.cron_schedule.schedule %>"
concurrencyPolicy: Forbid
successfulJobsHistoryLimit: 5
failedJobsHistoryLimit: 5
jobTemplate:
spec:
template:
spec:
containers:
- name: <%= project.name %>
image: <%= project.container_image_reference %>
imagePullPolicy: Always
command: <% service.command.split(' ').each do |c| %>
- <%= c %>
<% end %>
envFrom:
- configMapRef:
name: <%= project.name %>
- secretRef:
name: <%= project.name %>
<% if @project.volumes.present? %>
volumeMounts:
<% project.volumes.each do |volume| %>
- name: <%= volume.name %>
mountPath: <%= volume.mount_path %>
<% end %>
<% end %>
<% resource_constraint = service.resource_constraint %>
<% if resource_constraint.present? %>
resources:
<% if resource_constraint.cpu_request.present? || resource_constraint.memory_request.present? || resource_constraint.gpu_request.present? %>
requests:
<% if resource_constraint.cpu_request.present? %>
cpu: "<%= resource_constraint.cpu_request_formatted %>"
<% end %>
<% if resource_constraint.memory_request.present? %>
memory: "<%= resource_constraint.memory_request_formatted %>"
<% end %>
<% if resource_constraint.gpu_request.present? && resource_constraint.gpu_request > 0 %>
nvidia.com/gpu: <%= resource_constraint.gpu_request %>
<% end %>
<% end %>
<% if resource_constraint.cpu_limit.present? || resource_constraint.memory_limit.present? %>
limits:
<% if resource_constraint.cpu_limit.present? %>
cpu: "<%= resource_constraint.cpu_limit_formatted %>"
<% end %>
<% if resource_constraint.memory_limit.present? %>
memory: "<%= resource_constraint.memory_limit_formatted %>"
<% end %>
<% if resource_constraint.gpu_request.present? && resource_constraint.gpu_request > 0 %>
nvidia.com/gpu: <%= resource_constraint.gpu_request %>
<% end %>
<% end %>
<% end %>
restartPolicy: OnFailure
imagePullSecrets:
- name: dockerconfigjson-github-com
<% if @project.volumes.present? %>
volumes:
<% project.volumes.each do |volume| %>
- name: <%= volume.name %>
persistentVolumeClaim:
claimName: <%= volume.name %>
# Add your volume specifications here (e.g., persistentVolumeClaim, configMap, etc.)
<% end %>
<% end %>
<% if service.pod_yaml.present? %>
<%= service.pod_yaml %>
<% end %>