Sha256: 43d18e15e8284d91a35b22a08c79746a21f0c6ea1204b828c10b1149044a0129

Contents?: true

Size: 1.66 KB

Versions: 2

Compression:

Stored size: 1.66 KB

Contents

# frozen_string_literal: true

module Metatron
  module Templates
    # Template for basic CronJob k8s resource
    class CronJob < Template
      include Concerns::Annotated
      include Concerns::PodProducer
      include Concerns::Namespaced

      attr_accessor :schedule, :suspend, :concurrency_policy, :starting_deadline_seconds,
                    :successful_jobs_history_limit, :failed_jobs_history_limit,
                    :backoff_limit

      alias backoffLimit backoff_limit
      alias concurrencyPolicy concurrency_policy
      alias startingDeadlineSeconds starting_deadline_seconds
      alias successfulJobsHistoryLimit successful_jobs_history_limit
      alias failedJobsHistoryLimit failed_jobs_history_limit

      def initialize(name, schedule = "* * * * *")
        super(name)
        @schedule = schedule
        @api_version = "batch/v1"
      end

      # rubocop:disable Metrics/AbcSize
      def render
        {
          apiVersion:,
          kind:,
          metadata: {
            labels: { "#{label_namespace}/name": name }.merge(additional_labels),
            name:
          }.merge(formatted_annotations).merge(formatted_namespace),
          spec: {
            schedule:,
            suspend:,
            concurrencyPolicy:,
            startingDeadlineSeconds:,
            successfulJobsHistoryLimit:,
            failedJobsHistoryLimit:,
            jobTemplate: {
              spec: {
                activeDeadlineSeconds:,
                backoffLimit:
              }.merge(pod_template).compact
            }.merge(formatted_tolerations).compact
          }.compact
        }
      end
      # rubocop:enable Metrics/AbcSize
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
metatron-0.2.4 lib/metatron/templates/cron_job.rb
metatron-0.2.3 lib/metatron/templates/cron_job.rb