Fix add concurrency in cronjobs and default to Forbid
@@ -65,6 +65,12 @@ type cronTrait struct {
// Use the default Camel implementation of the `cron` endpoint (`quartz`) instead of trying to materialize the integration
// as Kubernetes CronJob.
Fallback *bool `property:"fallback"`
+ // Specifies how to treat concurrent executions of a Job.
+ // Valid values are:
+ // - "Allow": allows CronJobs to run concurrently;
+ // - "Forbid" (default): forbids concurrent runs, skipping next run if previous run hasn't finished yet;
+ // - "Replace": cancels currently running job and replaces it with a new one
+ ConcurrencyPolicy string `property:"concurrency-policy"`
// Automatically deploy the integration as CronJob when all routes are
// either starting from a periodic consumer (only `cron`, `timer` and `quartz` are supported) or a passive consumer (e.g. `direct` is a passive consumer).
//
@@ -134,6 +140,10 @@ func (t *cronTrait) Configure(e *Environment) (bool, error) {
t.Components = strings.Join(configuredComponents, ",")
}
+ if t.ConcurrencyPolicy == "" {
+ t.ConcurrencyPolicy = string(v1beta1.ForbidConcurrent)
+ }
+
if t.Schedule == "" && t.Components == "" && t.Fallback == nil {
// If there's at least a `cron` endpoint, add a fallback implementation
fromURIs, err := t.getSourcesFromURIs(e)
@@ -221,6 +231,7 @@ func (t *cronTrait) getCronJobFor(e *Environment) *v1beta1.CronJob {
},
Spec: v1beta1.CronJobSpec{
Schedule: t.Schedule,
+ ConcurrencyPolicy: v1beta1.ConcurrencyPolicy(t.ConcurrencyPolicy),
JobTemplate: v1beta1.JobTemplateSpec{
Spec: batchv1.JobSpec{
Template: corev1.PodTemplateSpec{
