You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by pc...@apache.org on 2023/03/24 08:13:12 UTC

[camel-k] branch main updated (694b9ac64 -> 630dd58c9)

This is an automated email from the ASF dual-hosted git repository.

pcongiusti pushed a change to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git


    from 694b9ac64 chore: changelog automatic update
     new 118c35836 chore(doc): how to test Camel K 2.0 locally
     new b9d2fe3c9 fix(builder): native from source should rebuild
     new a98002e97 chore(test): improve testing
     new 630dd58c9 fix(e2e): proper condition for checking kits

The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../ROOT/pages/contributing/local-development.adoc | 75 ++++-------------
 e2e/common/config/config_test.go                   |  2 +-
 e2e/native/files/{Java.java => Java2.java}         |  2 +-
 .../files/yaml.yaml => native/files/yaml2.yaml}    |  2 +-
 e2e/native/native_test.go                          | 37 +++++----
 e2e/native/native_with_sources_test.go             | 32 ++++++-
 pkg/controller/integration/kits.go                 | 25 ++++++
 pkg/controller/integration/kits_test.go            | 97 ++++++++++++++++++++++
 pkg/resources/resources.go                         | 17 ++++
 pkg/util/defaults/defaults.go                      |  2 +-
 10 files changed, 209 insertions(+), 82 deletions(-)
 copy e2e/native/files/{Java.java => Java2.java} (95%)
 copy e2e/{common/misc/files/yaml.yaml => native/files/yaml2.yaml} (96%)


[camel-k] 01/04: chore(doc): how to test Camel K 2.0 locally

Posted by pc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

pcongiusti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git

commit 118c35836840566647160044458328a9837d69bb
Author: Pasquale Congiusti <pa...@gmail.com>
AuthorDate: Thu Mar 23 12:02:48 2023 +0100

    chore(doc): how to test Camel K 2.0 locally
---
 .../ROOT/pages/contributing/local-development.adoc | 75 +++++-----------------
 1 file changed, 15 insertions(+), 60 deletions(-)

diff --git a/docs/modules/ROOT/pages/contributing/local-development.adoc b/docs/modules/ROOT/pages/contributing/local-development.adoc
index 82d61e8a7..ff6197b55 100644
--- a/docs/modules/ROOT/pages/contributing/local-development.adoc
+++ b/docs/modules/ROOT/pages/contributing/local-development.adoc
@@ -4,85 +4,40 @@
 If you plan on contributing to Camel K, you will end up needing to run and troubleshoot your operator code locally. Here is a guideline that will help you configure your local operator running.
 
 [[local-operator]]
-== Running operator locally
+== Running a development operator
 
-As soon as you build your operator locally you will ask yourself how to test it. The idea is that you execute it locally and instruct it to **watch** a namespace on a Kubernetes cluster (it may be remote or any local environment). Let's use a namespace called ``operator-test``.
+As soon as you build your operator locally you will ask yourself how to test it. In the past, we used to have the possibility to run the operator on the same development machine and connect to Kubernetes cluster. However, that approach was quite cumbersome, so now we propose a way to locally install and run your development Camel K operator as it was a "normal" installation.
 
-* You can start with setting the environment variable ``WATCH_NAMESPACE`` with the namespace you'd like your operator to watch. You also need to specify the name of the operator, as you may have different operators running on the cluster.
-----
-export WATCH_NAMESPACE=operator-test
-export OPERATOR_ID="camel-k-dev"
-----
+Once you have done your development, you will need to build and push Camel K Operator container image to the container registry your Kubernetes is later going to use. If you're on a local machine, you are probably using Minikube or Kind. In such case you can make your Docker daemon to use the cluster container registry. In Minikube it would be like the following:
 
-* The next step is to install an ``IntegrationPlatform`` on the cluster namespace. You probably need to tweak the registry parameters in order to be able to authenticate against an image repository (see below paragraph for local repository instructions). It's important to specify the target operator that will take care of this IntegrationPlatform (`-x` or `--operator-id` option).
+[source]
 ----
-./kamel install --skip-operator-setup -n operator-test --registry my-registry:5000 -x camel-k-dev
+eval $(minikube -p minikube docker-env)
 ----
 
-* Finally, assuming you've built your application correctly we can run the operator:
------
-./kamel operator
------
-
-* Test the local operator by creating a test `Integration`.
------
-./kamel run xyz.abc -n operator-test -x camel-k-dev
------
-
-IMPORTANT: make sure no other Camel K Operators are watching this namespace, neither you have a global Camel K Operator  installed on your cluster. As you may have more than one Camel K operator installed on the cluster, it's important you specify the `-x` (or `--operator-id`) option.
+For other cluster types you may check the specific documentation. As soon as you're connected to the Docker daemon you can build images via:
 
-[[local-minikube]]
-== Local operator and local cluster
-
-If you want to run a local operator togheter with ``Minikube`` you will need an additional step in order to let the local operator push images in the local registry. We need to expose the local registry as described in https://minikube.sigs.k8s.io/docs/handbook/registry/#docker-on-windows[this procedure]:
-
-* Enable the addon registry (this should be already in place):
+[source]
 ----
-minikube addons enable registry
+make images
 ----
 
-* Get the ``Pod`` name that is in charge to run the registry and proxy the registry 5000 port to be used locally.
-----
-kubectl get pods -n kube-system
-NAME                               READY   STATUS    RESTARTS   AGE
-...
-registry-fttbv                     1/1     Running   40         89d
-...
+This command will build and publish your actual Camel K development version to the container registry. At this stage installing the Camel K development version will be as easy as a typical installation:
 
-kubectl port-forward --namespace kube-system registry-fttbv 5000:5000
+[source]
 ----
-
-* Update the ``IntegrationPlatform`` to instruct it to use the ``localhost`` registry:
-----
-./kamel install --skip-operator-setup -n operator-test --registry localhost:5000 --force -x camel-k-dev
+./kamel install
 ----
 
-A similar procedure may work if you use other local environments. The idea is to expose the docker registry and be able to use it from your local operator.
-
-IMPORTANT: using build strategy as `Pod` won't probably work as it will expect the registry to be available at a URL not possible to reach from a local machine.
+You can provide any customization required such as `--log-level`, `--operator-id`, etcetera. Mind that you need to use `./kamel` in order to use the development binary you've just built, as tipically, `kamel` is the production CLI you have installed in your binary path.
 
 === Local Camel K runtime
 
-Camel K integrations are based on https://github.com/apache/camel-k-runtime[Camel K runtime], generally paired with the operator release. If you need to specify a different runtime, or you have a local Camel K runtime that you want to test, then you will need to specify it in the `Integration Platform`:
-----
-./kamel install --skip-operator-setup -n operator-test --registry localhost:5000 --force --runtime-version $version -x camel-k-dev
-----
+Camel K integrations are based on https://github.com/apache/camel-k-runtime[Camel K runtime], generally paired with the operator release. If you need to specify a different runtime, or you have a local Camel K Runtime that you want to test you need to build a Camel K version bundled with the local Camel K Runtime bits
 
-The `$version` variable must be replaced with the version you are building. For example, `1.3.1-SNAPSHOT`. With these instructions, the operator will pick up and use the snapshot version you have released locally. In order to use the local maven repository, you will also need to edit your IntegrationPlatform as follow:
 ----
-$ k edit ip -n operator-test
-
-...
-  spec:
-    build:
-      maven:
-        cliOptions:
-        - -V
-        localRepository: /home/user/.m2/repository
-        settings: {}
-...
+make images CAMEL_K_RUNTIME_DIR=<path/to/local/ck-runtime/project>
 ----
-pointing the `localRepository` where your local maven is storing the artifacts (it will look for the camel-k-runtime dependencies there).
 
+Once this is done you need to re-install via `./kamel install`.
 
-Alternatively, if no local registry is available, you can use another type of registry as explained in xref:installation/registry/registry.adoc[the Registry section].


[camel-k] 02/04: fix(builder): native from source should rebuild

Posted by pc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

pcongiusti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git

commit b9d2fe3c93f78b3349d32731e21233045448648c
Author: Pasquale Congiusti <pa...@gmail.com>
AuthorDate: Thu Mar 23 12:03:54 2023 +0100

    fix(builder): native from source should rebuild
    
    Closes #4126
---
 e2e/native/files/Java2.java             | 28 ++++++++++++++++++++++
 e2e/native/files/yaml2.yaml             | 28 ++++++++++++++++++++++
 e2e/native/native_test.go               | 34 +++++++++++++-------------
 e2e/native/native_with_sources_test.go  | 29 +++++++++++++++++++++++
 pkg/controller/integration/kits.go      | 20 ++++++++++++++++
 pkg/controller/integration/kits_test.go | 42 +++++++++++++++++++++++++++++++++
 pkg/resources/resources.go              | 17 +++++++++++++
 pkg/util/defaults/defaults.go           |  2 +-
 8 files changed, 182 insertions(+), 18 deletions(-)

diff --git a/e2e/native/files/Java2.java b/e2e/native/files/Java2.java
new file mode 100644
index 000000000..73b29ab99
--- /dev/null
+++ b/e2e/native/files/Java2.java
@@ -0,0 +1,28 @@
+/*
+ * 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 Java extends RouteBuilder {
+   @Override
+   public void configure() throws Exception {
+     from("timer:tick")
+       .setHeader("m").constant("string!")
+       .setBody().simple("Magic2${header.m}")
+       .log("Java ${body}");
+   }
+ }
diff --git a/e2e/native/files/yaml2.yaml b/e2e/native/files/yaml2.yaml
new file mode 100644
index 000000000..d717e5da6
--- /dev/null
+++ b/e2e/native/files/yaml2.yaml
@@ -0,0 +1,28 @@
+# ---------------------------------------------------------------------------
+# 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:yaml"
+    parameters:
+      period: "5000"
+    steps:
+      - set-header:
+          name: "m"
+          constant: "string!"
+      - set-body:
+          simple: "Magic${header.m}2"
+      - to: "log:info"
diff --git a/e2e/native/native_test.go b/e2e/native/native_test.go
index 0060b0d93..703956955 100644
--- a/e2e/native/native_test.go
+++ b/e2e/native/native_test.go
@@ -75,24 +75,8 @@ func TestNativeIntegrations(t *testing.T) {
 			Expect(Kamel("delete", name, "-n", ns).Execute()).To(Succeed())
 		})
 
-		t.Run("warm up before native build testing", func(t *testing.T) {
-			// The following native build test is under tight time constraints, so here it runs
-			// a warm up testing to make sure necessary jars are already downloaded.
-			name := "warm-up-yaml"
-			Expect(KamelRunWithID(operatorID, ns, "files/yaml.yaml", "--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(IntegrationLogs(ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!"))
-
-			// Clean up
-			Expect(Kamel("delete", name, "-n", ns).Execute()).To(Succeed())
-			Expect(DeleteKits(ns)).To(Succeed())
-		})
-
 		t.Run("automatic rollout deployment from fast-jar to native kit", func(t *testing.T) {
-			name := "jvm-to-native"
+			name := "yaml-native"
 			Expect(KamelRunWithID(operatorID, ns, "files/yaml.yaml", "--name", name,
 				"-t", "quarkus.package-type=fast-jar",
 				"-t", "quarkus.package-type=native",
@@ -146,5 +130,21 @@ func TestNativeIntegrations(t *testing.T) {
 			// Clean up
 			Expect(Kamel("delete", name, "-n", ns).Execute()).To(Succeed())
 		})
+
+		t.Run("yaml native should not rebuild", func(t *testing.T) {
+			name := "yaml-native-2"
+			Expect(KamelRunWithID(operatorID, ns, "files/yaml2.yaml", "--name", name,
+				"-t", "quarkus.package-type=native",
+			).Execute()).To(Succeed())
+
+			// This one should run quickly as it suppose to reuse an IntegrationKit
+			Eventually(IntegrationPodPhase(ns, name), TestTimeoutShort).Should(Equal(corev1.PodRunning))
+			Eventually(IntegrationPod(ns, name), TestTimeoutShort).
+				Should(WithTransform(getContainerCommand(), MatchRegexp(".*camel-k-integration-\\d+\\.\\d+\\.\\d+[-A-Za-z]*-runner.*")))
+			Eventually(IntegrationConditionStatus(ns, name, v1.IntegrationConditionReady), TestTimeoutShort).
+				Should(Equal(corev1.ConditionTrue))
+			Eventually(IntegrationLogs(ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!2"))
+			Expect(IntegrationKit(ns, "yaml-native")).Should(Equal(IntegrationKit(ns, "yaml-native-2")))
+		})
 	})
 }
diff --git a/e2e/native/native_with_sources_test.go b/e2e/native/native_with_sources_test.go
index ab3348fca..f59f6cdbc 100644
--- a/e2e/native/native_with_sources_test.go
+++ b/e2e/native/native_with_sources_test.go
@@ -54,9 +54,38 @@ func TestNativeHighMemoryIntegrations(t *testing.T) {
 				Should(WithTransform(getContainerCommand(), MatchRegexp(".*camel-k-integration-\\d+\\.\\d+\\.\\d+[-A-Za-z]*-runner.*")))
 			Eventually(IntegrationConditionStatus(ns, name, v1.IntegrationConditionReady), TestTimeoutShort).
 				Should(Equal(corev1.ConditionTrue))
+			Eventually(IntegrationLogs(ns, name), TestTimeoutShort).Should(ContainSubstring("Java Magicstring!"))
+		})
+
+		t.Run("java native same should not rebuild", func(t *testing.T) {
+			name := "java-native-clone"
+			Expect(KamelRunWithID(operatorID, ns, "files/Java.java", "--name", name,
+				"-t", "quarkus.package-type=native",
+			).Execute()).To(Succeed())
 
+			// This one should run quickly as it suppose to reuse an IntegrationKit
+			Eventually(IntegrationPodPhase(ns, name), TestTimeoutShort).Should(Equal(corev1.PodRunning))
+			Eventually(IntegrationPod(ns, name), TestTimeoutShort).
+				Should(WithTransform(getContainerCommand(), MatchRegexp(".*camel-k-integration-\\d+\\.\\d+\\.\\d+[-A-Za-z]*-runner.*")))
+			Eventually(IntegrationConditionStatus(ns, name, v1.IntegrationConditionReady), TestTimeoutShort).
+				Should(Equal(corev1.ConditionTrue))
 			Eventually(IntegrationLogs(ns, name), TestTimeoutShort).Should(ContainSubstring("Java Magicstring!"))
+			Expect(IntegrationKit(ns, "java-native")).Should(Equal(IntegrationKit(ns, "java-native-clone")))
+		})
 
+		t.Run("java native should rebuild", func(t *testing.T) {
+			name := "java-native-2"
+			Expect(KamelRunWithID(operatorID, ns, "files/Java2.java", "--name", name,
+				"-t", "quarkus.package-type=native",
+			).Execute()).To(Succeed())
+
+			Eventually(IntegrationPodPhase(ns, name), TestTimeoutVeryLong).Should(Equal(corev1.PodRunning))
+			Eventually(IntegrationPod(ns, name), TestTimeoutShort).
+				Should(WithTransform(getContainerCommand(), MatchRegexp(".*camel-k-integration-\\d+\\.\\d+\\.\\d+[-A-Za-z]*-runner.*")))
+			Eventually(IntegrationConditionStatus(ns, name, v1.IntegrationConditionReady), TestTimeoutShort).
+				Should(Equal(corev1.ConditionTrue))
+			Eventually(IntegrationLogs(ns, name), TestTimeoutShort).Should(ContainSubstring("Java Magic2string!"))
+			Expect(IntegrationKit(ns, "java-native-2")).ShouldNot(Equal(IntegrationKit(ns, "java-native")))
 			// Clean up
 			Expect(Kamel("delete", name, "-n", ns).Execute()).To(Succeed())
 		})
diff --git a/pkg/controller/integration/kits.go b/pkg/controller/integration/kits.go
index 2cf22089b..ee3b8550e 100644
--- a/pkg/controller/integration/kits.go
+++ b/pkg/controller/integration/kits.go
@@ -131,6 +131,12 @@ func integrationMatches(integration *v1.Integration, kit *v1.IntegrationKit) (bo
 		ilog.Debug("Integration and integration-kit dependencies do not match", "integration", integration.Name, "integration-kit", kit.Name, "namespace", integration.Namespace)
 		return false, nil
 	}
+	// If IntegrationKit has any source, we must verify that it corresponds with the one in the Integration.
+	// This is important in case of Native builds as we need to rebuild when language requires a source during build.
+	if (kit.Spec.Sources != nil && len(kit.Spec.Sources) > 0) && !hasMatchingSources(integration, kit) {
+		ilog.Debug("Integration and integration-kit sources do not match", "integration", integration.Name, "integration-kit", kit.Name, "namespace", integration.Namespace)
+		return false, nil
+	}
 
 	ilog.Debug("Matched Integration and integration-kit", "integration", integration.Name, "integration-kit", kit.Name, "namespace", integration.Namespace)
 	return true, nil
@@ -250,3 +256,17 @@ func matchesTrait(it map[string]interface{}, kt map[string]interface{}) bool {
 	// perform exact match on the two trait maps
 	return reflect.DeepEqual(it, kt)
 }
+
+func hasMatchingSources(it *v1.Integration, kit *v1.IntegrationKit) bool {
+	for _, itSource := range it.Sources() {
+		for _, ikSource := range kit.Spec.Sources {
+			if itSource.Content == ikSource.Content {
+				// found, let's move to the next one
+				break
+			}
+			return false
+		}
+
+	}
+	return true
+}
diff --git a/pkg/controller/integration/kits_test.go b/pkg/controller/integration/kits_test.go
index 94709f977..08113e27e 100644
--- a/pkg/controller/integration/kits_test.go
+++ b/pkg/controller/integration/kits_test.go
@@ -338,3 +338,45 @@ func TestHasMatchingTraits_KitSameTraitShouldBePicked(t *testing.T) {
 	assert.Nil(t, err)
 	assert.True(t, ok)
 }
+
+func TestHasMatchingSources(t *testing.T) {
+	integration := &v1.Integration{
+		Spec: v1.IntegrationSpec{
+			Sources: []v1.SourceSpec{
+				v1.NewSourceSpec("test", "some content", v1.LanguageJavaShell),
+			},
+		},
+	}
+
+	kit := &v1.IntegrationKit{
+		Spec: v1.IntegrationKitSpec{
+			Sources: []v1.SourceSpec{
+				v1.NewSourceSpec("test", "some content", v1.LanguageJavaShell),
+			},
+		},
+	}
+
+	hasMatchingSources := hasMatchingSources(integration, kit)
+	assert.True(t, hasMatchingSources)
+}
+
+func TestHasNotMatchingSources(t *testing.T) {
+	integration := &v1.Integration{
+		Spec: v1.IntegrationSpec{
+			Sources: []v1.SourceSpec{
+				v1.NewSourceSpec("test", "some content", v1.LanguageJavaShell),
+			},
+		},
+	}
+
+	kit := &v1.IntegrationKit{
+		Spec: v1.IntegrationKitSpec{
+			Sources: []v1.SourceSpec{
+				v1.NewSourceSpec("test", "some content 2", v1.LanguageJavaShell),
+			},
+		},
+	}
+
+	hasMatchingSources := hasMatchingSources(integration, kit)
+	assert.False(t, hasMatchingSources)
+}
diff --git a/pkg/resources/resources.go b/pkg/resources/resources.go
index ae517e797..c23b0583f 100644
--- a/pkg/resources/resources.go
+++ b/pkg/resources/resources.go
@@ -167,6 +167,18 @@ var assets = func() http.FileSystem {
 			name:    "manager",
 			modTime: time.Time{},
 		},
+		"/manager/bundle": &vfsgen۰DirInfo{
+			name:    "bundle",
+			modTime: time.Time{},
+		},
+		"/manager/bundle/manifests": &vfsgen۰DirInfo{
+			name:    "manifests",
+			modTime: time.Time{},
+		},
+		"/manager/bundle/metadata": &vfsgen۰DirInfo{
+			name:    "metadata",
+			modTime: time.Time{},
+		},
 		"/manager/operator-deployment.yaml": &vfsgen۰CompressedFileInfo{
 			name:             "operator-deployment.yaml",
 			modTime:          time.Time{},
@@ -671,6 +683,7 @@ var assets = func() http.FileSystem {
 		fs["/crd/bases/camel.apache.org_kamelets.yaml"].(os.FileInfo),
 	}
 	fs["/manager"].(*vfsgen۰DirInfo).entries = []os.FileInfo{
+		fs["/manager/bundle"].(os.FileInfo),
 		fs["/manager/operator-deployment.yaml"].(os.FileInfo),
 		fs["/manager/operator-pvc.yaml"].(os.FileInfo),
 		fs["/manager/operator-service-account.yaml"].(os.FileInfo),
@@ -684,6 +697,10 @@ var assets = func() http.FileSystem {
 		fs["/manager/patch-toleration.yaml"].(os.FileInfo),
 		fs["/manager/patch-watch-namespace-global.yaml"].(os.FileInfo),
 	}
+	fs["/manager/bundle"].(*vfsgen۰DirInfo).entries = []os.FileInfo{
+		fs["/manager/bundle/manifests"].(os.FileInfo),
+		fs["/manager/bundle/metadata"].(os.FileInfo),
+	}
 	fs["/prometheus"].(*vfsgen۰DirInfo).entries = []os.FileInfo{
 		fs["/prometheus/operator-pod-monitor.yaml"].(os.FileInfo),
 		fs["/prometheus/operator-prometheus-rule.yaml"].(os.FileInfo),
diff --git a/pkg/util/defaults/defaults.go b/pkg/util/defaults/defaults.go
index fad3aed54..c20ed0e4f 100644
--- a/pkg/util/defaults/defaults.go
+++ b/pkg/util/defaults/defaults.go
@@ -26,7 +26,7 @@ const (
 	Version = "2.0.0-SNAPSHOT"
 
 	// DefaultRuntimeVersion --
-	DefaultRuntimeVersion = "1.18.0-SNAPSHOT"
+	DefaultRuntimeVersion = "3.20.1-SNAPSHOT"
 
 	// BuildahVersion --
 	BuildahVersion = "1.23.3"


[camel-k] 03/04: chore(test): improve testing

Posted by pc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

pcongiusti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git

commit a98002e97de2648c4252a1147faa20e2c6454f34
Author: Pasquale Congiusti <pa...@gmail.com>
AuthorDate: Thu Mar 23 13:05:59 2023 +0100

    chore(test): improve testing
---
 e2e/native/native_test.go               | 31 ++++++++---------
 e2e/native/native_with_sources_test.go  | 59 +++++++++++++++++----------------
 pkg/controller/integration/kits.go      |  6 ++--
 pkg/controller/integration/kits_test.go | 50 ++++++++++++++++++++++++++--
 4 files changed, 98 insertions(+), 48 deletions(-)

diff --git a/e2e/native/native_test.go b/e2e/native/native_test.go
index 703956955..e523067fe 100644
--- a/e2e/native/native_test.go
+++ b/e2e/native/native_test.go
@@ -127,24 +127,25 @@ func TestNativeIntegrations(t *testing.T) {
 
 			Eventually(IntegrationLogs(ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!"))
 
+			t.Run("yaml native should not rebuild", func(t *testing.T) {
+				name := "yaml-native-2"
+				Expect(KamelRunWithID(operatorID, ns, "files/yaml2.yaml", "--name", name,
+					"-t", "quarkus.package-type=native",
+				).Execute()).To(Succeed())
+
+				// This one should run quickly as it suppose to reuse an IntegrationKit
+				Eventually(IntegrationPodPhase(ns, name), TestTimeoutShort).Should(Equal(corev1.PodRunning))
+				Eventually(IntegrationPod(ns, name), TestTimeoutShort).
+					Should(WithTransform(getContainerCommand(), MatchRegexp(".*camel-k-integration-\\d+\\.\\d+\\.\\d+[-A-Za-z]*-runner.*")))
+				Eventually(IntegrationConditionStatus(ns, name, v1.IntegrationConditionReady), TestTimeoutShort).
+					Should(Equal(corev1.ConditionTrue))
+				Eventually(IntegrationLogs(ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!2"))
+				Expect(IntegrationKit(ns, "yaml-native")).Should(Equal(IntegrationKit(ns, "yaml-native-2")))
+			})
+
 			// Clean up
 			Expect(Kamel("delete", name, "-n", ns).Execute()).To(Succeed())
 		})
 
-		t.Run("yaml native should not rebuild", func(t *testing.T) {
-			name := "yaml-native-2"
-			Expect(KamelRunWithID(operatorID, ns, "files/yaml2.yaml", "--name", name,
-				"-t", "quarkus.package-type=native",
-			).Execute()).To(Succeed())
-
-			// This one should run quickly as it suppose to reuse an IntegrationKit
-			Eventually(IntegrationPodPhase(ns, name), TestTimeoutShort).Should(Equal(corev1.PodRunning))
-			Eventually(IntegrationPod(ns, name), TestTimeoutShort).
-				Should(WithTransform(getContainerCommand(), MatchRegexp(".*camel-k-integration-\\d+\\.\\d+\\.\\d+[-A-Za-z]*-runner.*")))
-			Eventually(IntegrationConditionStatus(ns, name, v1.IntegrationConditionReady), TestTimeoutShort).
-				Should(Equal(corev1.ConditionTrue))
-			Eventually(IntegrationLogs(ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!2"))
-			Expect(IntegrationKit(ns, "yaml-native")).Should(Equal(IntegrationKit(ns, "yaml-native-2")))
-		})
 	})
 }
diff --git a/e2e/native/native_with_sources_test.go b/e2e/native/native_with_sources_test.go
index f59f6cdbc..fd7c58276 100644
--- a/e2e/native/native_with_sources_test.go
+++ b/e2e/native/native_with_sources_test.go
@@ -55,37 +55,38 @@ func TestNativeHighMemoryIntegrations(t *testing.T) {
 			Eventually(IntegrationConditionStatus(ns, name, v1.IntegrationConditionReady), TestTimeoutShort).
 				Should(Equal(corev1.ConditionTrue))
 			Eventually(IntegrationLogs(ns, name), TestTimeoutShort).Should(ContainSubstring("Java Magicstring!"))
-		})
 
-		t.Run("java native same should not rebuild", func(t *testing.T) {
-			name := "java-native-clone"
-			Expect(KamelRunWithID(operatorID, ns, "files/Java.java", "--name", name,
-				"-t", "quarkus.package-type=native",
-			).Execute()).To(Succeed())
+			t.Run("java native same should not rebuild", func(t *testing.T) {
+				name := "java-native-clone"
+				Expect(KamelRunWithID(operatorID, ns, "files/Java.java", "--name", name,
+					"-t", "quarkus.package-type=native",
+				).Execute()).To(Succeed())
+
+				// This one should run quickly as it suppose to reuse an IntegrationKit
+				Eventually(IntegrationPodPhase(ns, name), TestTimeoutShort).Should(Equal(corev1.PodRunning))
+				Eventually(IntegrationPod(ns, name), TestTimeoutShort).
+					Should(WithTransform(getContainerCommand(), MatchRegexp(".*camel-k-integration-\\d+\\.\\d+\\.\\d+[-A-Za-z]*-runner.*")))
+				Eventually(IntegrationConditionStatus(ns, name, v1.IntegrationConditionReady), TestTimeoutShort).
+					Should(Equal(corev1.ConditionTrue))
+				Eventually(IntegrationLogs(ns, name), TestTimeoutShort).Should(ContainSubstring("Java Magicstring!"))
+				Expect(IntegrationKit(ns, "java-native")).Should(Equal(IntegrationKit(ns, "java-native-clone")))
+			})
+
+			t.Run("java native should rebuild", func(t *testing.T) {
+				name := "java-native-2"
+				Expect(KamelRunWithID(operatorID, ns, "files/Java2.java", "--name", name,
+					"-t", "quarkus.package-type=native",
+				).Execute()).To(Succeed())
+
+				Eventually(IntegrationPodPhase(ns, name), TestTimeoutVeryLong).Should(Equal(corev1.PodRunning))
+				Eventually(IntegrationPod(ns, name), TestTimeoutShort).
+					Should(WithTransform(getContainerCommand(), MatchRegexp(".*camel-k-integration-\\d+\\.\\d+\\.\\d+[-A-Za-z]*-runner.*")))
+				Eventually(IntegrationConditionStatus(ns, name, v1.IntegrationConditionReady), TestTimeoutShort).
+					Should(Equal(corev1.ConditionTrue))
+				Eventually(IntegrationLogs(ns, name), TestTimeoutShort).Should(ContainSubstring("Java Magic2string!"))
+				Expect(IntegrationKit(ns, "java-native-2")).ShouldNot(Equal(IntegrationKit(ns, "java-native")))
+			})
 
-			// This one should run quickly as it suppose to reuse an IntegrationKit
-			Eventually(IntegrationPodPhase(ns, name), TestTimeoutShort).Should(Equal(corev1.PodRunning))
-			Eventually(IntegrationPod(ns, name), TestTimeoutShort).
-				Should(WithTransform(getContainerCommand(), MatchRegexp(".*camel-k-integration-\\d+\\.\\d+\\.\\d+[-A-Za-z]*-runner.*")))
-			Eventually(IntegrationConditionStatus(ns, name, v1.IntegrationConditionReady), TestTimeoutShort).
-				Should(Equal(corev1.ConditionTrue))
-			Eventually(IntegrationLogs(ns, name), TestTimeoutShort).Should(ContainSubstring("Java Magicstring!"))
-			Expect(IntegrationKit(ns, "java-native")).Should(Equal(IntegrationKit(ns, "java-native-clone")))
-		})
-
-		t.Run("java native should rebuild", func(t *testing.T) {
-			name := "java-native-2"
-			Expect(KamelRunWithID(operatorID, ns, "files/Java2.java", "--name", name,
-				"-t", "quarkus.package-type=native",
-			).Execute()).To(Succeed())
-
-			Eventually(IntegrationPodPhase(ns, name), TestTimeoutVeryLong).Should(Equal(corev1.PodRunning))
-			Eventually(IntegrationPod(ns, name), TestTimeoutShort).
-				Should(WithTransform(getContainerCommand(), MatchRegexp(".*camel-k-integration-\\d+\\.\\d+\\.\\d+[-A-Za-z]*-runner.*")))
-			Eventually(IntegrationConditionStatus(ns, name, v1.IntegrationConditionReady), TestTimeoutShort).
-				Should(Equal(corev1.ConditionTrue))
-			Eventually(IntegrationLogs(ns, name), TestTimeoutShort).Should(ContainSubstring("Java Magic2string!"))
-			Expect(IntegrationKit(ns, "java-native-2")).ShouldNot(Equal(IntegrationKit(ns, "java-native")))
 			// Clean up
 			Expect(Kamel("delete", name, "-n", ns).Execute()).To(Succeed())
 		})
diff --git a/pkg/controller/integration/kits.go b/pkg/controller/integration/kits.go
index ee3b8550e..f96ea10e0 100644
--- a/pkg/controller/integration/kits.go
+++ b/pkg/controller/integration/kits.go
@@ -259,14 +259,16 @@ func matchesTrait(it map[string]interface{}, kt map[string]interface{}) bool {
 
 func hasMatchingSources(it *v1.Integration, kit *v1.IntegrationKit) bool {
 	for _, itSource := range it.Sources() {
+		found := false
 		for _, ikSource := range kit.Spec.Sources {
 			if itSource.Content == ikSource.Content {
-				// found, let's move to the next one
+				found = true
 				break
 			}
+		}
+		if !found {
 			return false
 		}
-
 	}
 	return true
 }
diff --git a/pkg/controller/integration/kits_test.go b/pkg/controller/integration/kits_test.go
index 08113e27e..c4b017c5c 100644
--- a/pkg/controller/integration/kits_test.go
+++ b/pkg/controller/integration/kits_test.go
@@ -356,8 +356,54 @@ func TestHasMatchingSources(t *testing.T) {
 		},
 	}
 
-	hasMatchingSources := hasMatchingSources(integration, kit)
-	assert.True(t, hasMatchingSources)
+	hms := hasMatchingSources(integration, kit)
+	assert.True(t, hms)
+
+	kit2 := &v1.IntegrationKit{
+		Spec: v1.IntegrationKitSpec{
+			Sources: []v1.SourceSpec{
+				v1.NewSourceSpec("test", "some content 2", v1.LanguageJavaShell),
+				v1.NewSourceSpec("test", "some content", v1.LanguageJavaShell),
+			},
+		},
+	}
+
+	hms2 := hasMatchingSources(integration, kit2)
+	assert.True(t, hms2)
+}
+
+func TestHasMatchingMultipleSources(t *testing.T) {
+	integration := &v1.Integration{
+		Spec: v1.IntegrationSpec{
+			Sources: []v1.SourceSpec{
+				v1.NewSourceSpec("test", "some content", v1.LanguageJavaShell),
+				v1.NewSourceSpec("test", "some content 2", v1.LanguageJavaShell),
+			},
+		},
+	}
+
+	kit := &v1.IntegrationKit{
+		Spec: v1.IntegrationKitSpec{
+			Sources: []v1.SourceSpec{
+				v1.NewSourceSpec("test", "some content 2", v1.LanguageJavaShell),
+				v1.NewSourceSpec("test", "some content", v1.LanguageJavaShell),
+			},
+		},
+	}
+
+	hms := hasMatchingSources(integration, kit)
+	assert.True(t, hms)
+
+	integration2 := &v1.Integration{
+		Spec: v1.IntegrationSpec{
+			Sources: []v1.SourceSpec{
+				v1.NewSourceSpec("test", "some content", v1.LanguageJavaShell),
+			},
+		},
+	}
+
+	hms2 := hasMatchingSources(integration2, kit)
+	assert.True(t, hms2)
 }
 
 func TestHasNotMatchingSources(t *testing.T) {


[camel-k] 04/04: fix(e2e): proper condition for checking kits

Posted by pc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

pcongiusti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git

commit 630dd58c9a1cc07e0688c43bf9b9d7fc8f9947e8
Author: Pasquale Congiusti <pa...@gmail.com>
AuthorDate: Thu Mar 23 17:19:49 2023 +0100

    fix(e2e): proper condition for checking kits
---
 e2e/common/config/config_test.go        |  2 +-
 e2e/native/native_test.go               |  4 +++-
 e2e/native/native_with_sources_test.go  |  4 ++--
 pkg/controller/integration/kits.go      |  3 +++
 pkg/controller/integration/kits_test.go | 17 +++++++++++++----
 5 files changed, 22 insertions(+), 8 deletions(-)

diff --git a/e2e/common/config/config_test.go b/e2e/common/config/config_test.go
index 07b239632..f3362b343 100644
--- a/e2e/common/config/config_test.go
+++ b/e2e/common/config/config_test.go
@@ -283,7 +283,7 @@ func TestRunConfigExamples(t *testing.T) {
 		Eventually(IntegrationConditionStatus(ns, "build-property-route-updated", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue))
 		Eventually(IntegrationLogs(ns, "build-property-route-updated"), TestTimeoutShort).Should(ContainSubstring("my-super-application-updated"))
 		// Verify the integration kits are different
-		Expect(IntegrationKit(ns, "build-property-route")).ShouldNot(Equal(IntegrationKit(ns, "build-property-route-updated")))
+		Eventually(IntegrationKit(ns, "build-property-route-updated")).ShouldNot(Equal(IntegrationKit(ns, "build-property-route")()))
 		Expect(Kamel("delete", "--all", "-n", ns).Execute()).To(Succeed())
 	})
 
diff --git a/e2e/native/native_test.go b/e2e/native/native_test.go
index e523067fe..d7c7c2ba5 100644
--- a/e2e/native/native_test.go
+++ b/e2e/native/native_test.go
@@ -76,6 +76,8 @@ func TestNativeIntegrations(t *testing.T) {
 		})
 
 		t.Run("automatic rollout deployment from fast-jar to native kit", func(t *testing.T) {
+			// Let's make sure we start from a clean state
+			Expect(DeleteKits(ns)).To(Succeed())
 			name := "yaml-native"
 			Expect(KamelRunWithID(operatorID, ns, "files/yaml.yaml", "--name", name,
 				"-t", "quarkus.package-type=fast-jar",
@@ -140,7 +142,7 @@ func TestNativeIntegrations(t *testing.T) {
 				Eventually(IntegrationConditionStatus(ns, name, v1.IntegrationConditionReady), TestTimeoutShort).
 					Should(Equal(corev1.ConditionTrue))
 				Eventually(IntegrationLogs(ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!2"))
-				Expect(IntegrationKit(ns, "yaml-native")).Should(Equal(IntegrationKit(ns, "yaml-native-2")))
+				Eventually(IntegrationKit(ns, "yaml-native-2")).Should(Equal(IntegrationKit(ns, "yaml-native")()))
 			})
 
 			// Clean up
diff --git a/e2e/native/native_with_sources_test.go b/e2e/native/native_with_sources_test.go
index fd7c58276..b5128ab95 100644
--- a/e2e/native/native_with_sources_test.go
+++ b/e2e/native/native_with_sources_test.go
@@ -69,7 +69,7 @@ func TestNativeHighMemoryIntegrations(t *testing.T) {
 				Eventually(IntegrationConditionStatus(ns, name, v1.IntegrationConditionReady), TestTimeoutShort).
 					Should(Equal(corev1.ConditionTrue))
 				Eventually(IntegrationLogs(ns, name), TestTimeoutShort).Should(ContainSubstring("Java Magicstring!"))
-				Expect(IntegrationKit(ns, "java-native")).Should(Equal(IntegrationKit(ns, "java-native-clone")))
+				Eventually(IntegrationKit(ns, "java-native-clone")).Should(Equal(IntegrationKit(ns, "java-native")()))
 			})
 
 			t.Run("java native should rebuild", func(t *testing.T) {
@@ -84,7 +84,7 @@ func TestNativeHighMemoryIntegrations(t *testing.T) {
 				Eventually(IntegrationConditionStatus(ns, name, v1.IntegrationConditionReady), TestTimeoutShort).
 					Should(Equal(corev1.ConditionTrue))
 				Eventually(IntegrationLogs(ns, name), TestTimeoutShort).Should(ContainSubstring("Java Magic2string!"))
-				Expect(IntegrationKit(ns, "java-native-2")).ShouldNot(Equal(IntegrationKit(ns, "java-native")))
+				Eventually(IntegrationKit(ns, "java-native-2")).ShouldNot(Equal(IntegrationKit(ns, "java-native")()))
 			})
 
 			// Clean up
diff --git a/pkg/controller/integration/kits.go b/pkg/controller/integration/kits.go
index f96ea10e0..8c8cebd1e 100644
--- a/pkg/controller/integration/kits.go
+++ b/pkg/controller/integration/kits.go
@@ -258,6 +258,9 @@ func matchesTrait(it map[string]interface{}, kt map[string]interface{}) bool {
 }
 
 func hasMatchingSources(it *v1.Integration, kit *v1.IntegrationKit) bool {
+	if len(it.Sources()) != len(kit.Spec.Sources) {
+		return false
+	}
 	for _, itSource := range it.Sources() {
 		found := false
 		for _, ikSource := range kit.Spec.Sources {
diff --git a/pkg/controller/integration/kits_test.go b/pkg/controller/integration/kits_test.go
index c4b017c5c..4e316bace 100644
--- a/pkg/controller/integration/kits_test.go
+++ b/pkg/controller/integration/kits_test.go
@@ -369,7 +369,7 @@ func TestHasMatchingSources(t *testing.T) {
 	}
 
 	hms2 := hasMatchingSources(integration, kit2)
-	assert.True(t, hms2)
+	assert.False(t, hms2)
 }
 
 func TestHasMatchingMultipleSources(t *testing.T) {
@@ -403,7 +403,7 @@ func TestHasMatchingMultipleSources(t *testing.T) {
 	}
 
 	hms2 := hasMatchingSources(integration2, kit)
-	assert.True(t, hms2)
+	assert.False(t, hms2)
 }
 
 func TestHasNotMatchingSources(t *testing.T) {
@@ -423,6 +423,15 @@ func TestHasNotMatchingSources(t *testing.T) {
 		},
 	}
 
-	hasMatchingSources := hasMatchingSources(integration, kit)
-	assert.False(t, hasMatchingSources)
+	hsm := hasMatchingSources(integration, kit)
+	assert.False(t, hsm)
+
+	kit2 := &v1.IntegrationKit{
+		Spec: v1.IntegrationKitSpec{
+			Sources: []v1.SourceSpec{},
+		},
+	}
+
+	hsm2 := hasMatchingSources(integration, kit2)
+	assert.False(t, hsm2)
 }