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
The following commit(s) were added to refs/heads/main by this push: new ee92705 Fix #2236: Add Service Binding E2E test ee92705 is described below commit ee92705539a1851525ca50d223a8b9585851099c Author: John Poth <poth.j...@gmail.com> AuthorDate: Fri Apr 23 16:49:23 2021 +0200 Fix #2236: Add Service Binding E2E test --- .github/workflows/kubernetes.yml | 9 ++++ e2e/service-binding/ServiceBinding.java | 27 ++++++++++ e2e/service-binding/service_binding_test.go | 80 +++++++++++++++++++++++++++++ script/Makefile | 4 ++ 4 files changed, 120 insertions(+) diff --git a/.github/workflows/kubernetes.yml b/.github/workflows/kubernetes.yml index e074b61..95c07c7 100644 --- a/.github/workflows/kubernetes.yml +++ b/.github/workflows/kubernetes.yml @@ -94,6 +94,14 @@ jobs: make IMAGE_NAME=${LOCAL_IMAGE} PACKAGE_ARTIFACTS_STRATEGY=download build package-artifacts images images-push sudo mv ./kamel /usr/local/bin + - name: Install Service Binding + run: | + echo "Installing Service Binding Operator" + + export SERVICE_BINDING_VERSION=v0.7.1 + kubectl create -f https://github.com/redhat-developer/service-binding-operator/releases/download/$SERVICE_BINDING_VERSION/release.yaml + echo "Waiting for all pods to be ready in service-binding-operator" + kubectl wait --for=condition=Ready pod --all -n service-binding-operator --timeout=60s - name: Run IT # Disable registry tests as not compatible with KinD #env: @@ -119,3 +127,4 @@ jobs: # Then run integration tests make test-integration + make test-service-binding \ No newline at end of file diff --git a/e2e/service-binding/ServiceBinding.java b/e2e/service-binding/ServiceBinding.java new file mode 100644 index 0000000..2f7c729 --- /dev/null +++ b/e2e/service-binding/ServiceBinding.java @@ -0,0 +1,27 @@ +/* + * 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 ServiceBinding extends RouteBuilder { + @Override + public void configure() throws Exception { + from("timer:tick") + .setBody(simple("${properties:host}:${properties:port}")) + .log("${body}"); + } +} \ No newline at end of file diff --git a/e2e/service-binding/service_binding_test.go b/e2e/service-binding/service_binding_test.go new file mode 100644 index 0000000..9b88717 --- /dev/null +++ b/e2e/service-binding/service_binding_test.go @@ -0,0 +1,80 @@ +// +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 service_binding + +import ( + "fmt" + "testing" + + . "github.com/onsi/gomega" + + corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + + . "github.com/apache/camel-k/e2e/support" + camelv1 "github.com/apache/camel-k/pkg/apis/camel/v1" +) + +func TestServiceBindingTrait(t *testing.T) { + WithNewTestNamespace(t, func(ns string) { + Expect(Kamel("install", "-n", ns).Execute()).To(Succeed()) + + // Create our mock service config + host := "hostname" + port := "12324" + service := &corev1.ConfigMap{ + TypeMeta: metav1.TypeMeta{ + Kind: "ConfigMap", + APIVersion: "v1", + }, + ObjectMeta: metav1.ObjectMeta{ + Name: "mock-service-config", + Namespace: ns, + Annotations: map[string]string{ + "service.binding/host": "path={.data.service-host}", + "service.binding/port": "path={.data.service-port}", + }, + }, + Data: map[string]string{ + "service-host": host, + "service-port": port, + }, + } + serviceRef := fmt.Sprintf("%s:%s/%s", service.TypeMeta.Kind, ns, service.ObjectMeta.Name) + Expect(TestClient().Create(TestContext, service)).To(Succeed()) + + // Create integration and bind it to our service + name := "service-binding" + Expect(Kamel("run", "ServiceBinding.java", + "--name", name, + "--connect", serviceRef, + "-n", ns, + ).Execute()).To(Succeed()) + + Eventually(IntegrationPodPhase(ns, name), TestTimeoutMedium).Should(Equal(corev1.PodRunning)) + Eventually(IntegrationCondition(ns, name, camelv1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + Eventually(IntegrationLogs(ns, name), TestTimeoutShort).Should(ContainSubstring(fmt.Sprintf("%s:%s", host, port))) + + // Clean up + Expect(Kamel("delete", "--all", "-n", ns).Execute()).To(Succeed()) + }) +} diff --git a/script/Makefile b/script/Makefile index 01a400b..fb2ff57 100644 --- a/script/Makefile +++ b/script/Makefile @@ -180,6 +180,10 @@ test-upgrade: build STAGING_RUNTIME_REPO="$(STAGING_RUNTIME_REPO)" \ go test -timeout 60m -v ./e2e/upgrade -tags=integration +test-service-binding: build + STAGING_RUNTIME_REPO="$(STAGING_RUNTIME_REPO)" go test -timeout 60m -v ./e2e/service-binding -tags=integration + #go test -timeout 60m -v ./e2e/service-binding -tags=integration + build-kamel: # Ensure the binary is statically linked when building on Linux due to ABI changes in newer glibc 2.32, otherwise # it would not run on older versions. See https://github.com/apache/camel-k/pull/2141#issuecomment-800990117