Skip to content

Commit

Permalink
feat(apache#5121): adding timeZone property to the Cron trait spec
Browse files Browse the repository at this point in the history
  • Loading branch information
lsergio committed Jun 20, 2024
1 parent 3d10994 commit 20856fa
Show file tree
Hide file tree
Showing 16 changed files with 151 additions and 1 deletion.
7 changes: 7 additions & 0 deletions docs/modules/ROOT/partials/apis/camel-k-crds.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -6646,6 +6646,13 @@ string
The CronJob schedule for the whole integration. If multiple routes are declared, they must have the same schedule for this
mechanism to work correctly.
|`timeZone` +
string
|
The timezone that the CronJob will run on
|`components` +
string
|
Expand Down
4 changes: 4 additions & 0 deletions docs/modules/traits/pages/cron.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ The following configuration options are available:
| The CronJob schedule for the whole integration. If multiple routes are declared, they must have the same schedule for this
mechanism to work correctly.

| cron.timeZone
| string
| The timezone that the CronJob will run on

| cron.components
| string
| A comma separated list of the Camel components that need to be customized in order for them to work when the schedule is triggered externally by Kubernetes.
Expand Down
6 changes: 6 additions & 0 deletions helm/camel-k/crds/crd-integration-platform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -854,6 +854,9 @@ spec:
jobs executions will be counted as failed ones.
format: int64
type: integer
timeZone:
description: The timezone that the CronJob will run on
type: string
type: object
dependencies:
description: The configuration of Dependencies trait
Expand Down Expand Up @@ -2883,6 +2886,9 @@ spec:
jobs executions will be counted as failed ones.
format: int64
type: integer
timeZone:
description: The timezone that the CronJob will run on
type: string
type: object
dependencies:
description: The configuration of Dependencies trait
Expand Down
6 changes: 6 additions & 0 deletions helm/camel-k/crds/crd-integration-profile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,9 @@ spec:
jobs executions will be counted as failed ones.
format: int64
type: integer
timeZone:
description: The timezone that the CronJob will run on
type: string
type: object
dependencies:
description: The configuration of Dependencies trait
Expand Down Expand Up @@ -2643,6 +2646,9 @@ spec:
jobs executions will be counted as failed ones.
format: int64
type: integer
timeZone:
description: The timezone that the CronJob will run on
type: string
type: object
dependencies:
description: The configuration of Dependencies trait
Expand Down
3 changes: 3 additions & 0 deletions helm/camel-k/crds/crd-integration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6795,6 +6795,9 @@ spec:
jobs executions will be counted as failed ones.
format: int64
type: integer
timeZone:
description: The timezone that the CronJob will run on
type: string
type: object
dependencies:
description: The configuration of Dependencies trait
Expand Down
3 changes: 3 additions & 0 deletions helm/camel-k/crds/crd-kamelet-binding.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7079,6 +7079,9 @@ spec:
jobs executions will be counted as failed ones.
format: int64
type: integer
timeZone:
description: The timezone that the CronJob will run on
type: string
type: object
dependencies:
description: The configuration of Dependencies trait
Expand Down
3 changes: 3 additions & 0 deletions helm/camel-k/crds/crd-pipe.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7077,6 +7077,9 @@ spec:
jobs executions will be counted as failed ones.
format: int64
type: integer
timeZone:
description: The timezone that the CronJob will run on
type: string
type: object
dependencies:
description: The configuration of Dependencies trait
Expand Down
2 changes: 2 additions & 0 deletions pkg/apis/camel/v1/trait/cron.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ type CronTrait struct {
// The CronJob schedule for the whole integration. If multiple routes are declared, they must have the same schedule for this
// mechanism to work correctly.
Schedule string `property:"schedule" json:"schedule,omitempty"`
// The timezone that the CronJob will run on
TimeZone *string `property:"timeZone" json:"timeZone,omitempty"`
// A comma separated list of the Camel components that need to be customized in order for them to work when the schedule is triggered externally by Kubernetes.
// A specific customizer is activated for each specified component. E.g. for the `timer` component, the `cron-timer` customizer is
// activated (it's present in the `org.apache.camel.k:camel-k-cron` library).
Expand Down
5 changes: 5 additions & 0 deletions pkg/apis/camel/v1/trait/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -854,6 +854,9 @@ spec:
jobs executions will be counted as failed ones.
format: int64
type: integer
timeZone:
description: The timezone that the CronJob will run on
type: string
type: object
dependencies:
description: The configuration of Dependencies trait
Expand Down Expand Up @@ -2883,6 +2886,9 @@ spec:
jobs executions will be counted as failed ones.
format: int64
type: integer
timeZone:
description: The timezone that the CronJob will run on
type: string
type: object
dependencies:
description: The configuration of Dependencies trait
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,9 @@ spec:
jobs executions will be counted as failed ones.
format: int64
type: integer
timeZone:
description: The timezone that the CronJob will run on
type: string
type: object
dependencies:
description: The configuration of Dependencies trait
Expand Down Expand Up @@ -2643,6 +2646,9 @@ spec:
jobs executions will be counted as failed ones.
format: int64
type: integer
timeZone:
description: The timezone that the CronJob will run on
type: string
type: object
dependencies:
description: The configuration of Dependencies trait
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6795,6 +6795,9 @@ spec:
jobs executions will be counted as failed ones.
format: int64
type: integer
timeZone:
description: The timezone that the CronJob will run on
type: string
type: object
dependencies:
description: The configuration of Dependencies trait
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7079,6 +7079,9 @@ spec:
jobs executions will be counted as failed ones.
format: int64
type: integer
timeZone:
description: The timezone that the CronJob will run on
type: string
type: object
dependencies:
description: The configuration of Dependencies trait
Expand Down
3 changes: 3 additions & 0 deletions pkg/resources/config/crd/bases/camel.apache.org_pipes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7077,6 +7077,9 @@ spec:
jobs executions will be counted as failed ones.
format: int64
type: integer
timeZone:
description: The timezone that the CronJob will run on
type: string
type: object
dependencies:
description: The configuration of Dependencies trait
Expand Down
2 changes: 1 addition & 1 deletion pkg/trait/cron.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,6 @@ func (t *cronTrait) getCronJobFor(e *Environment) *batchv1.CronJob {
if t.BackoffLimit != nil {
backoffLimit = *t.BackoffLimit
}

cronjob := batchv1.CronJob{
TypeMeta: metav1.TypeMeta{
Kind: "CronJob",
Expand All @@ -258,6 +257,7 @@ func (t *cronTrait) getCronJobFor(e *Environment) *batchv1.CronJob {
},
Spec: batchv1.CronJobSpec{
Schedule: t.Schedule,
TimeZone: t.TimeZone,
ConcurrencyPolicy: batchv1.ConcurrencyPolicy(t.ConcurrencyPolicy),
StartingDeadlineSeconds: t.StartingDeadlineSeconds,
JobTemplate: batchv1.JobTemplateSpec{
Expand Down
90 changes: 90 additions & 0 deletions pkg/trait/cron_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -635,4 +635,94 @@ func TestCronWithBackoffLimit(t *testing.T) {

assert.NotNil(t, cronJob.Spec.JobTemplate.Spec.BackoffLimit)
assert.EqualValues(t, *cronJob.Spec.JobTemplate.Spec.BackoffLimit, 5)

assert.Nil(t, cronJob.Spec.TimeZone)
}

func TestCronWithTimeZone(t *testing.T) {
catalog, err := camel.DefaultCatalog()
require.NoError(t, err)

client, _ := test.NewFakeClient()
traitCatalog := NewCatalog(nil)

timeZone := "America/Sao_Paulo"

environment := Environment{
CamelCatalog: catalog,
Catalog: traitCatalog,
Client: client,
Integration: &v1.Integration{
ObjectMeta: metav1.ObjectMeta{
Name: "test",
Namespace: "ns",
},
Status: v1.IntegrationStatus{
Phase: v1.IntegrationPhaseDeploying,
},
Spec: v1.IntegrationSpec{
Sources: []v1.SourceSpec{
{
DataSpec: v1.DataSpec{
Name: "routes.java",
Content: `from("cron:tab?schedule=0 0/2 * * ?").to("log:test")`,
},
Language: v1.LanguageJavaSource,
},
},
Traits: v1.Traits{
Cron: &traitv1.CronTrait{
TimeZone: &timeZone,
},
},
},
},
IntegrationKit: &v1.IntegrationKit{
Status: v1.IntegrationKitStatus{
Phase: v1.IntegrationKitPhaseReady,
},
},
Platform: &v1.IntegrationPlatform{
Spec: v1.IntegrationPlatformSpec{
Build: v1.IntegrationPlatformBuildSpec{
RuntimeVersion: catalog.Runtime.Version,
},
},
Status: v1.IntegrationPlatformStatus{
Phase: v1.IntegrationPlatformPhaseReady,
},
},
EnvVars: make([]corev1.EnvVar, 0),
ExecutedTraits: make([]Trait, 0),
Resources: kubernetes.NewCollection(),
}
environment.Platform.ResyncStatusFullConfig()

c, err := NewFakeClient("ns")
require.NoError(t, err)

tc := NewCatalog(c)

expectedCondition := NewIntegrationCondition(
"Deployment",
v1.IntegrationConditionDeploymentAvailable,
corev1.ConditionFalse,
"DeploymentAvailable",
"controller strategy: cron-job",
)
conditions, err := tc.apply(&environment)
require.NoError(t, err)
assert.Contains(t, conditions, expectedCondition)
assert.NotEmpty(t, environment.ExecutedTraits)

ct, _ := environment.GetTrait("cron").(*cronTrait)
assert.NotNil(t, ct)
assert.Nil(t, ct.Fallback)
assert.Contains(t, environment.Interceptors, "cron")

cronJob := environment.Resources.GetCronJob(func(job *batchv1.CronJob) bool { return true })
assert.NotNil(t, cronJob)

assert.NotNil(t, cronJob.Spec.TimeZone)
assert.EqualValues(t, *cronJob.Spec.TimeZone, "America/Sao_Paulo")
}

0 comments on commit 20856fa

Please sign in to comment.