Skip to content

Commit

Permalink
Fix knative service url e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
claudio4j authored and realMartinez committed Sep 6, 2024
1 parent 0e8e20f commit 2412110
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 24 deletions.
23 changes: 23 additions & 0 deletions e2e/knative/files/knativeurl1.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# camel-k: language=yaml
# ---------------------------------------------------------------------------
# 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.
# ---------------------------------------------------------------------------

- from:
uri: "knative:endpoint/knative"
steps:
- setBody:
constant: "Hello from knative"
31 changes: 31 additions & 0 deletions e2e/knative/files/knativeurl2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# camel-k: language=yaml
# ---------------------------------------------------------------------------
# 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.
# ---------------------------------------------------------------------------

- from:
uri: "timer:tick"
steps:
- setBody:
constant: "message"
- to: "knative:channel/messages"

- from:
uri: "timer:tick"
steps:
- setBody:
constant: "word"
- to: "knative:channel/words"
48 changes: 24 additions & 24 deletions e2e/knative/knative_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,38 +27,38 @@ import (
"testing"

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

. "github.com/apache/camel-k/v2/e2e/support"
v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1"
"github.com/apache/camel-k/v2/pkg/util/knative"
camelv1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1"
v1 "k8s.io/api/core/v1"
)

func TestKnativeServiceURL(t *testing.T) {
g := NewWithT(t)

installed, err := knative.IsServingInstalled(TestClient(t))
g.Expect(err).NotTo(HaveOccurred())
if !installed {
t.Error("Knative not installed in the cluster")
t.FailNow()
}
WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) {
operatorID := "camel-k-knative-service"
// Install without profile (should automatically detect the presence of Knative)
g.Expect(KamelInstallWithID(t, ctx, operatorID, ns)).To(Succeed())
g.Eventually(PlatformPhase(t, ctx, ns), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady))
g.Eventually(PlatformProfile(t, ctx, ns), TestTimeoutShort).Should(Equal(v1.TraitProfile("")))
cluster := Platform(t, ctx, ns)().Status.Cluster

t.Run("run yaml on cluster profile", func(t *testing.T) {
g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/knative2.yaml", "--profile", string(cluster)).Execute()).To(Succeed())
g.Eventually(IntegrationPodPhase(t, ctx, ns, "knative2"), TestTimeoutLong).Should(Equal(corev1.PodRunning))
g.Eventually(IntegrationTraitProfile(t, ctx, ns, "knative2"), TestTimeoutShort).Should(Equal(v1.TraitProfile(string(cluster))))
knChannelWords := "words"
knChannelMessages := "messages"
g.Expect(CreateKnativeChannel(t, ctx, ns, knChannelMessages)()).To(Succeed())
g.Expect(CreateKnativeChannel(t, ctx, ns, knChannelWords)()).To(Succeed())

g.Eventually(KnativeService(t, ctx, ns, "knative2")().Status.RouteStatusFields.URL.String(), TestTimeoutLong).Should(Equal("http://knative2.ns.domain"))
t.Run("Service endpoint url check", func(t *testing.T) {
g.Expect(KamelRun(t, ctx, ns, "files/knativeurl1.yaml").Execute()).To(Succeed())
g.Eventually(IntegrationPodPhase(t, ctx, ns, "knativeurl1"), TestTimeoutLong).Should(Equal(v1.PodRunning))
g.Eventually(IntegrationConditionStatus(t, ctx, ns, "knativeurl1", camelv1.IntegrationConditionReady), TestTimeoutMedium).Should(Equal(v1.ConditionTrue))
ks := KnativeService(t, ctx, ns, "knativeurl1")
g.Eventually(ks, TestTimeoutShort).ShouldNot(BeNil())
url := "http://knativeurl1." + ns + ".svc.cluster.local"
g.Eventually(ks().Status.RouteStatusFields.URL.String(), TestTimeoutShort).Should(Equal(url))
})

g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed())
t.Run("Service multiple endpoint url check", func(t *testing.T) {
g.Expect(KamelRun(t, ctx, ns, "files/knativeurl2.yaml").Execute()).To(Succeed())
g.Eventually(IntegrationPodPhase(t, ctx, ns, "knativeurl2"), TestTimeoutLong).Should(Equal(v1.PodRunning))
g.Eventually(IntegrationConditionStatus(t, ctx, ns, "knativeurl2", camelv1.IntegrationConditionReady), TestTimeoutMedium).Should(Equal(v1.ConditionTrue))
ks := KnativeService(t, ctx, ns, "knativeurl2")
g.Eventually(ks, TestTimeoutShort).ShouldNot(BeNil())
url := "http://knativeurl2." + ns + ".svc.cluster.local"
g.Eventually(ks().Status.RouteStatusFields.URL.String(), TestTimeoutShort).Should(Equal(url))
})
g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed())
})
}

0 comments on commit 2412110

Please sign in to comment.