You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by as...@apache.org on 2022/03/09 13:33:44 UTC
[camel-k] 02/02: chore(e2e): Add KameletBinding readiness condition e2e tests
This is an automated email from the ASF dual-hosted git repository.
astefanutti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit 0ce1c472f34b373990628700b331b1e31150ad4f
Author: Antonin Stefanutti <an...@stefanutti.fr>
AuthorDate: Wed Mar 9 11:41:47 2022 +0100
chore(e2e): Add KameletBinding readiness condition e2e tests
---
e2e/common/kamelet_binding_test.go | 4 ++--
e2e/common/scale_binding_test.go | 8 +++----
e2e/knative/kamelet_test.go | 47 ++++++++++++++++++++++++++++++++++----
e2e/support/test_support.go | 37 ++++++++++++++++++++++++++----
4 files changed, 82 insertions(+), 14 deletions(-)
diff --git a/e2e/common/kamelet_binding_test.go b/e2e/common/kamelet_binding_test.go
index 7d68cb7..bc24f68 100644
--- a/e2e/common/kamelet_binding_test.go
+++ b/e2e/common/kamelet_binding_test.go
@@ -67,7 +67,7 @@ func TestErrorHandler(t *testing.T) {
t.Run("throw error test", func(t *testing.T) {
RegisterTestingT(t)
- Expect(BindKameletToWithErrorHandler(ns, "throw-error-binding", from, to, map[string]string{"message": "throw Error"}, map[string]string{"loggerName": "integrationLogger"}, errorHandler)()).To(Succeed())
+ Expect(BindKameletToWithErrorHandler(ns, "throw-error-binding", map[string]string{}, from, to, map[string]string{"message": "throw Error"}, map[string]string{"loggerName": "integrationLogger"}, errorHandler)()).To(Succeed())
Eventually(IntegrationPodPhase(ns, "throw-error-binding"), TestTimeoutMedium).Should(Equal(corev1.PodRunning))
Eventually(IntegrationLogs(ns, "throw-error-binding"), TestTimeoutShort).Should(ContainSubstring("kameletErrorHandler"))
@@ -78,7 +78,7 @@ func TestErrorHandler(t *testing.T) {
t.Run("don't throw error test", func(t *testing.T) {
RegisterTestingT(t)
- Expect(BindKameletToWithErrorHandler(ns, "no-error-binding", from, to, map[string]string{"message": "true"}, map[string]string{"loggerName": "integrationLogger"}, errorHandler)()).To(Succeed())
+ Expect(BindKameletToWithErrorHandler(ns, "no-error-binding", map[string]string{}, from, to, map[string]string{"message": "true"}, map[string]string{"loggerName": "integrationLogger"}, errorHandler)()).To(Succeed())
Eventually(IntegrationPodPhase(ns, "no-error-binding"), TestTimeoutMedium).Should(Equal(corev1.PodRunning))
Eventually(IntegrationLogs(ns, "no-error-binding"), TestTimeoutShort).ShouldNot(ContainSubstring("kameletErrorHandler"))
diff --git a/e2e/common/scale_binding_test.go b/e2e/common/scale_binding_test.go
index 3bbc2ee..649220d 100644
--- a/e2e/common/scale_binding_test.go
+++ b/e2e/common/scale_binding_test.go
@@ -54,7 +54,7 @@ func TestKameletBindingScale(t *testing.T) {
Expect(Kamel("bind", "timer-source?message=HelloBinding", "log-sink", "-n", ns, "--name", name).Execute()).To(Succeed())
Eventually(IntegrationPodPhase(ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning))
Eventually(IntegrationConditionStatus(ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue))
- Eventually(KameletBindingCondition(ns, name, v1alpha1.KameletBindingConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue))
+ Eventually(KameletBindingConditionStatus(ns, name, v1alpha1.KameletBindingConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue))
Eventually(IntegrationLogs(ns, name), TestTimeoutShort).Should(ContainSubstring("HelloBinding"))
t.Run("Update binding scale spec", func(t *testing.T) {
@@ -71,7 +71,7 @@ func TestKameletBindingScale(t *testing.T) {
// Check the readiness condition becomes truthy back
Eventually(IntegrationConditionStatus(ns, name, v1.IntegrationConditionReady), TestTimeoutMedium).Should(Equal(corev1.ConditionTrue))
// Finally check the readiness condition becomes truthy back on kamelet binding
- Eventually(KameletBindingCondition(ns, name, v1alpha1.KameletBindingConditionReady), TestTimeoutMedium).Should(Equal(corev1.ConditionTrue))
+ Eventually(KameletBindingConditionStatus(ns, name, v1alpha1.KameletBindingConditionReady), TestTimeoutMedium).Should(Equal(corev1.ConditionTrue))
})
t.Run("Scale kamelet binding with polymorphic client", func(t *testing.T) {
@@ -85,7 +85,7 @@ func TestKameletBindingScale(t *testing.T) {
Expect(err).To(BeNil())
// Check the readiness condition is still truthy as down-scaling
- Expect(KameletBindingCondition(ns, name, v1alpha1.KameletBindingConditionReady)()).To(Equal(corev1.ConditionTrue))
+ Expect(KameletBindingConditionStatus(ns, name, v1alpha1.KameletBindingConditionReady)()).To(Equal(corev1.ConditionTrue))
// Check the Integration scale subresource Spec field
Eventually(IntegrationSpecReplicas(ns, name), TestTimeoutShort).
Should(gstruct.PointTo(BeNumerically("==", 2)))
@@ -116,7 +116,7 @@ func TestKameletBindingScale(t *testing.T) {
Expect(err).To(BeNil())
// Check the readiness condition is still truthy as down-scaling in kamelet binding
- Expect(KameletBindingCondition(ns, name, v1alpha1.KameletBindingConditionReady)()).To(Equal(corev1.ConditionTrue))
+ Expect(KameletBindingConditionStatus(ns, name, v1alpha1.KameletBindingConditionReady)()).To(Equal(corev1.ConditionTrue))
// Check the KameletBinding scale subresource Spec field
Eventually(KameletBindingSpecReplicas(ns, name), TestTimeoutShort).
Should(gstruct.PointTo(BeNumerically("==", 1)))
diff --git a/e2e/knative/kamelet_test.go b/e2e/knative/kamelet_test.go
index 7a68f6d..a0d8e33 100644
--- a/e2e/knative/kamelet_test.go
+++ b/e2e/knative/kamelet_test.go
@@ -23,6 +23,7 @@ limitations under the License.
package knative
import (
+ "fmt"
"testing"
. "github.com/onsi/gomega"
@@ -36,13 +37,15 @@ import (
"github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
)
-// Test that kamelet binding can be changed and changes propagated to integrations
+// Test that a KameletBinding can be changed and the changes are propagated to the Integration
func TestKameletChange(t *testing.T) {
WithNewTestNamespace(t, func(ns string) {
Expect(Kamel("install", "-n", ns).Execute()).To(Succeed())
Expect(CreateTimerKamelet(ns, "timer-source")()).To(Succeed())
Expect(CreateKnativeChannel(ns, "messages")()).To(Succeed())
+
Expect(Kamel("run", "-n", ns, "files/display.groovy", "-w").Execute()).To(Succeed())
+
from := corev1.ObjectReference{
Kind: "Kamelet",
APIVersion: v1alpha1.SchemeGroupVersion.String(),
@@ -54,15 +57,51 @@ func TestKameletChange(t *testing.T) {
Name: "messages",
APIVersion: messaging.SchemeGroupVersion.String(),
}
- Expect(BindKameletTo(ns, "timer-binding", from, to, map[string]string{"message": "message is Hello"}, map[string]string{})()).To(Succeed())
- Eventually(IntegrationPodPhase(ns, "timer-binding"), TestTimeoutMedium).Should(Equal(corev1.PodRunning))
+
+ name := "timer-binding"
+ annotations := map[string]string{
+ "trait.camel.apache.org/health.enabled": "true",
+ "trait.camel.apache.org/health.readiness-initial-delay": "10",
+ }
+
+ Expect(BindKameletTo(ns, name, annotations, from, to, map[string]string{"message": "message is Hello"}, map[string]string{})()).To(Succeed())
+
+ Eventually(KameletBindingConditionStatus(ns, name, v1alpha1.KameletBindingConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionFalse))
+ Eventually(KameletBindingCondition(ns, name, v1alpha1.KameletBindingConditionReady), TestTimeoutMedium).Should(And(
+ WithTransform(KameletBindingConditionReason, Equal(v1.IntegrationConditionDeploymentProgressingReason)),
+ WithTransform(KameletBindingConditionMessage, Equal(fmt.Sprintf("Integration %q readiness condition is %q", name, corev1.ConditionFalse))),
+ ))
+
+ Eventually(IntegrationPodPhase(ns, name), TestTimeoutMedium).Should(Equal(corev1.PodRunning))
Eventually(IntegrationConditionStatus(ns, "timer-binding", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue))
Eventually(IntegrationLogs(ns, "display"), TestTimeoutShort).Should(ContainSubstring("message is Hello"))
- Expect(BindKameletTo(ns, "timer-binding", from, to, map[string]string{"message": "message is Hi"}, map[string]string{})()).To(Succeed())
+ Eventually(KameletBindingConditionStatus(ns, name, v1alpha1.KameletBindingConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue))
+ Eventually(KameletBindingCondition(ns, name, v1alpha1.KameletBindingConditionReady), TestTimeoutMedium).Should(And(
+ WithTransform(KameletBindingConditionReason, Equal(v1.IntegrationConditionDeploymentReadyReason)),
+ WithTransform(KameletBindingConditionMessage, Equal(fmt.Sprintf("Integration %q readiness condition is %q", name, corev1.ConditionTrue))),
+ ))
+
+ // Update the KameletBinding
+ Expect(BindKameletTo(ns, "timer-binding", annotations, from, to, map[string]string{"message": "message is Hi"}, map[string]string{})()).To(Succeed())
+
+ Eventually(KameletBindingConditionStatus(ns, name, v1alpha1.KameletBindingConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionFalse))
+ Eventually(KameletBindingCondition(ns, name, v1alpha1.KameletBindingConditionReady), TestTimeoutMedium).Should(And(
+ WithTransform(KameletBindingConditionReason, Equal(v1.IntegrationConditionDeploymentProgressingReason)),
+ WithTransform(KameletBindingConditionMessage, Equal(fmt.Sprintf("Integration %q readiness condition is %q", name, corev1.ConditionFalse))),
+ ))
+
Eventually(IntegrationPodPhase(ns, "timer-binding"), TestTimeoutMedium).Should(Equal(corev1.PodRunning))
Eventually(IntegrationConditionStatus(ns, "timer-binding", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue))
Eventually(IntegrationLogs(ns, "display"), TestTimeoutShort).Should(ContainSubstring("message is Hi"))
+
+ Eventually(KameletBindingConditionStatus(ns, name, v1alpha1.KameletBindingConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue))
+ Eventually(KameletBindingCondition(ns, name, v1alpha1.KameletBindingConditionReady), TestTimeoutMedium).
+ Should(And(
+ WithTransform(KameletBindingConditionReason, Equal(v1.IntegrationConditionDeploymentReadyReason)),
+ WithTransform(KameletBindingConditionMessage, Equal(fmt.Sprintf("Integration %q readiness condition is %q", name, corev1.ConditionTrue))),
+ ))
+
Expect(Kamel("delete", "--all", "-n", ns).Execute()).To(Succeed())
})
}
diff --git a/e2e/support/test_support.go b/e2e/support/test_support.go
index 81d3d8b..c57c081 100644
--- a/e2e/support/test_support.go
+++ b/e2e/support/test_support.go
@@ -758,7 +758,35 @@ func KameletBindingStatusReplicas(ns string, name string) func() *int32 {
}
}
-func KameletBindingCondition(ns string, name string, conditionType v1alpha1.KameletBindingConditionType) func() corev1.ConditionStatus {
+func KameletBindingCondition(ns string, name string, conditionType v1alpha1.KameletBindingConditionType) func() *v1alpha1.KameletBindingCondition {
+ return func() *v1alpha1.KameletBindingCondition {
+ kb := KameletBinding(ns, name)()
+ if kb == nil {
+ return nil
+ }
+ c := kb.Status.GetCondition(conditionType)
+ if c == nil {
+ return nil
+ }
+ return c
+ }
+}
+
+func KameletBindingConditionReason(c *v1alpha1.KameletBindingCondition) string {
+ if c == nil {
+ return ""
+ }
+ return c.Reason
+}
+
+func KameletBindingConditionMessage(c *v1alpha1.KameletBindingCondition) string {
+ if c == nil {
+ return ""
+ }
+ return c.Message
+}
+
+func KameletBindingConditionStatus(ns string, name string, conditionType v1alpha1.KameletBindingConditionType) func() corev1.ConditionStatus {
return func() corev1.ConditionStatus {
klb := KameletBinding(ns, name)()
if klb == nil {
@@ -1566,13 +1594,14 @@ func CreateTimerKamelet(ns string, name string) func() error {
return CreateKamelet(ns, name, flow, props, nil)
}
-func BindKameletTo(ns string, name string, from corev1.ObjectReference, to corev1.ObjectReference, sourceProperties map[string]string, sinkProperties map[string]string) func() error {
- return BindKameletToWithErrorHandler(ns, name, from, to, sourceProperties, sinkProperties, nil)
+func BindKameletTo(ns string, name string, annotations map[string]string, from corev1.ObjectReference, to corev1.ObjectReference, sourceProperties map[string]string, sinkProperties map[string]string) func() error {
+ return BindKameletToWithErrorHandler(ns, name, annotations, from, to, sourceProperties, sinkProperties, nil)
}
-func BindKameletToWithErrorHandler(ns string, name string, from corev1.ObjectReference, to corev1.ObjectReference, sourceProperties map[string]string, sinkProperties map[string]string, errorHandler map[string]interface{}) func() error {
+func BindKameletToWithErrorHandler(ns string, name string, annotations map[string]string, from corev1.ObjectReference, to corev1.ObjectReference, sourceProperties map[string]string, sinkProperties map[string]string, errorHandler map[string]interface{}) func() error {
return func() error {
kb := v1alpha1.NewKameletBinding(ns, name)
+ kb.Annotations = annotations
kb.Spec = v1alpha1.KameletBindingSpec{
Source: v1alpha1.Endpoint{
Ref: &from,