Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cron): make uri explicit #5875

Merged
merged 1 commit into from
Oct 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion addons/keda/keda.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ func (t *kedaTrait) getTopControllerReference(e *trait.Environment) *v1.ObjectRe

func (t *kedaTrait) populateTriggersFromKamelets(e *trait.Environment) error {
kameletURIs := make(map[string][]string)
_, err := e.ConsumeMeta(func(meta metadata.IntegrationMetadata) bool {
_, err := e.ConsumeMeta(false, func(meta metadata.IntegrationMetadata) bool {
for _, kameletURI := range meta.FromURIs {
if kameletStr := source.ExtractKamelet(kameletURI); kameletStr != "" && camelv1.ValidKameletName(kameletStr) {
kamelet := kameletStr
Expand Down
2 changes: 1 addition & 1 deletion addons/master/master.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (t *masterTrait) Configure(e *trait.Environment) (bool, *trait.TraitConditi
return ptr.Deref(t.Enabled, false), nil, nil
}

enabled, err := e.ConsumeMeta(func(meta metadata.IntegrationMetadata) bool {
enabled, err := e.ConsumeMeta(false, func(meta metadata.IntegrationMetadata) bool {
found := false
loop:
for _, endpoint := range meta.FromURIs {
Expand Down
96 changes: 0 additions & 96 deletions e2e/common/misc/cron_test.go

This file was deleted.

37 changes: 0 additions & 37 deletions e2e/common/misc/files/cron-trait-yaml.yaml

This file was deleted.

110 changes: 110 additions & 0 deletions e2e/common/traits/cron_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
//go:build integration
// +build integration

// To enable compilation of this file in Goland, go to "Settings -> Go -> Vendoring & Build Tags -> Custom Tags" and add "integration"

/*
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package common

import (
"context"
"testing"

. "github.com/onsi/gomega"
corev1 "k8s.io/api/core/v1"
"k8s.io/utils/ptr"

. "github.com/apache/camel-k/v2/e2e/support"
v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1"
)

func TestRunCronExample(t *testing.T) {
t.Parallel()
WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) {

t.Run("cron-timer", func(t *testing.T) {
g.Expect(KamelRun(t, ctx, ns, "files/cron-timer.yaml").Execute()).To(Succeed())
g.Eventually(IntegrationCronJob(t, ctx, ns, "cron-timer"), TestTimeoutLong).ShouldNot(BeNil())
g.Eventually(IntegrationConditionStatus(t, ctx, ns, "cron-timer", v1.IntegrationConditionReady), TestTimeoutMedium).Should(
Equal(corev1.ConditionTrue))
g.Eventually(IntegrationConditionStatus(t, ctx, ns, "cron-timer", v1.IntegrationConditionCronJobAvailable), TestTimeoutMedium).Should(
Equal(corev1.ConditionTrue))
// As it's a cron, we expect it's triggered, executed and turned off
g.Eventually(IntegrationStatusReplicas(t, ctx, ns, "cron-timer"), TestTimeoutMedium).Should(Equal(ptr.To(int32(1))))
g.Eventually(IntegrationLogs(t, ctx, ns, "cron-timer")).Should(ContainSubstring("Magicstring!"))
g.Eventually(IntegrationStatusReplicas(t, ctx, ns, "cron-timer")).Should(Equal(ptr.To(int32(0))))
g.Eventually(DeleteIntegrations(t, ctx, ns)).Should(Equal(0))
})

t.Run("cron-java", func(t *testing.T) {
g.Expect(KamelRun(t, ctx, ns, "files/CronJava.java").Execute()).To(Succeed())
g.Eventually(IntegrationCronJob(t, ctx, ns, "cron-java"), TestTimeoutLong).ShouldNot(BeNil())
g.Eventually(IntegrationConditionStatus(t, ctx, ns, "cron-java", v1.IntegrationConditionReady), TestTimeoutMedium).Should(
Equal(corev1.ConditionTrue))
g.Eventually(IntegrationConditionStatus(t, ctx, ns, "cron-java", v1.IntegrationConditionCronJobAvailable), TestTimeoutMedium).Should(
Equal(corev1.ConditionTrue))
// As it's a cron, we expect it's triggered, executed and turned off
g.Eventually(IntegrationStatusReplicas(t, ctx, ns, "cron-java"), TestTimeoutMedium).Should(Equal(ptr.To(int32(1))))
g.Eventually(IntegrationLogs(t, ctx, ns, "cron-java")).Should(ContainSubstring("Magicstring!"))
g.Eventually(IntegrationStatusReplicas(t, ctx, ns, "cron-java")).Should(Equal(ptr.To(int32(0))))
g.Eventually(DeleteIntegrations(t, ctx, ns)).Should(Equal(0))
})

t.Run("cron-tab", func(t *testing.T) {
g.Expect(KamelRun(t, ctx, ns, "files/cron-tab.yaml").Execute()).To(Succeed())
g.Eventually(IntegrationCronJob(t, ctx, ns, "cron-tab"), TestTimeoutLong).ShouldNot(BeNil())
g.Eventually(IntegrationConditionStatus(t, ctx, ns, "cron-tab", v1.IntegrationConditionReady), TestTimeoutMedium).Should(
Equal(corev1.ConditionTrue))
g.Eventually(IntegrationConditionStatus(t, ctx, ns, "cron-tab", v1.IntegrationConditionCronJobAvailable), TestTimeoutMedium).Should(
Equal(corev1.ConditionTrue))
// As it's a cron, we expect it's triggered, executed and turned off
g.Eventually(IntegrationStatusReplicas(t, ctx, ns, "cron-tab"), TestTimeoutMedium).Should(Equal(ptr.To(int32(1))))
g.Eventually(IntegrationLogs(t, ctx, ns, "cron-tab")).Should(ContainSubstring("Magicstring!"))
g.Eventually(IntegrationStatusReplicas(t, ctx, ns, "cron-tab")).Should(Equal(ptr.To(int32(0))))
g.Eventually(DeleteIntegrations(t, ctx, ns)).Should(Equal(0))
})

t.Run("cron-quartz", func(t *testing.T) {
g.Expect(KamelRun(t, ctx, ns, "files/cron-quartz.yaml").Execute()).To(Succeed())
g.Eventually(IntegrationCronJob(t, ctx, ns, "cron-quartz"), TestTimeoutLong).ShouldNot(BeNil())
g.Eventually(IntegrationConditionStatus(t, ctx, ns, "cron-quartz", v1.IntegrationConditionReady), TestTimeoutShort).Should(
Equal(corev1.ConditionTrue))
g.Eventually(IntegrationConditionStatus(t, ctx, ns, "cron-quartz", v1.IntegrationConditionCronJobAvailable), TestTimeoutMedium).Should(
Equal(corev1.ConditionTrue))
// As it's a cron, we expect it's triggered, executed and turned off
g.Eventually(IntegrationStatusReplicas(t, ctx, ns, "cron-quartz"), TestTimeoutMedium).Should(Equal(ptr.To(int32(1))))
g.Eventually(IntegrationLogs(t, ctx, ns, "cron-quartz")).Should(ContainSubstring("Magicstring!"))
g.Eventually(IntegrationStatusReplicas(t, ctx, ns, "cron-quartz")).Should(Equal(ptr.To(int32(0))))
g.Eventually(DeleteIntegrations(t, ctx, ns)).Should(Equal(0))
})

t.Run("cron-fallback", func(t *testing.T) {
g.Expect(KamelRun(t, ctx, ns, "files/cron-fallback.yaml").Execute()).To(Succeed())
g.Eventually(IntegrationCronJob(t, ctx, ns, "cron-fallback"), TestTimeoutLong).Should(BeNil())
g.Eventually(IntegrationConditionStatus(t, ctx, ns, "cron-fallback", v1.IntegrationConditionReady), TestTimeoutShort).Should(
Equal(corev1.ConditionTrue))
g.Eventually(IntegrationConditionStatus(t, ctx, ns, "cron-fallback", v1.IntegrationConditionCronJobAvailable), TestTimeoutMedium).Should(
Equal(corev1.ConditionFalse))
g.Eventually(IntegrationPodPhase(t, ctx, ns, "cron-fallback")).Should(Equal(corev1.PodRunning))
g.Eventually(IntegrationLogs(t, ctx, ns, "cron-fallback"), TestTimeoutShort).Should(ContainSubstring("Magicstring!"))
g.Eventually(DeleteIntegrations(t, ctx, ns)).Should(Equal(0))
})

})
}
29 changes: 29 additions & 0 deletions e2e/common/traits/files/CronJava.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import org.apache.camel.builder.RouteBuilder;

public class CronJava extends RouteBuilder {
@Override
public void configure() throws Exception {
from("timer:java?period=60000")
.setHeader("m").constant("string!")
.setBody().simple("Magic${header.m}")
.log("${body}");
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from:
uri: "quartz:trigger"
parameters:
cron: "0/1 * * * * ?"
cron: "0 */1 * * * ?"
steps:
- setHeader:
name: "m"
Expand Down
1 change: 1 addition & 0 deletions pkg/apis/camel/v1/common_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,7 @@ type SourceSpec struct {
Loader string `json:"loader,omitempty"`
// Interceptors are optional identifiers the org.apache.camel.k.RoutesLoader
// uses to pre/post process sources
// Deprecated: no longer in use.
Interceptors []string `json:"interceptors,omitempty"`
// Type defines the kind of source described by this object
Type SourceType `json:"type,omitempty"`
Expand Down
Loading
Loading