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/08/22 12:15:15 UTC

[camel-k] 06/06: feat(trait): hot reload option

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 fab227dc03b9a6e39fd6fcaf9d7f97db947bc50c
Author: Pasquale Congiusti <pa...@gmail.com>
AuthorDate: Tue Aug 22 09:07:35 2023 +0200

    feat(trait): hot reload option
---
 .../camel.apache.org_integrationplatforms.yaml     |  8 +++++++
 .../crd/bases/camel.apache.org_integrations.yaml   |  4 ++++
 .../bases/camel.apache.org_kameletbindings.yaml    |  4 ++++
 config/crd/bases/camel.apache.org_pipes.yaml       |  4 ++++
 docs/modules/ROOT/partials/apis/camel-k-crds.adoc  |  7 ++++++
 docs/modules/traits/pages/mount.adoc               |  4 ++++
 e2e/common/config/config_reload_test.go            | 25 ++++++++++++++++++++++
 helm/camel-k/crds/crd-integration-platform.yaml    |  8 +++++++
 helm/camel-k/crds/crd-integration.yaml             |  4 ++++
 helm/camel-k/crds/crd-kamelet-binding.yaml         |  4 ++++
 helm/camel-k/crds/crd-pipe.yaml                    |  4 ++++
 pkg/apis/camel/v1/trait/mount.go                   |  2 ++
 pkg/apis/camel/v1/trait/zz_generated.deepcopy.go   |  5 +++++
 .../integration/integration_controller.go          |  5 +++--
 resources/traits.yaml                              |  4 ++++
 15 files changed, 90 insertions(+), 2 deletions(-)

diff --git a/config/crd/bases/camel.apache.org_integrationplatforms.yaml b/config/crd/bases/camel.apache.org_integrationplatforms.yaml
index ba79f08de..5b8fcb43c 100644
--- a/config/crd/bases/camel.apache.org_integrationplatforms.yaml
+++ b/config/crd/bases/camel.apache.org_integrationplatforms.yaml
@@ -1384,6 +1384,10 @@ spec:
                         description: Can be used to enable or disable a trait. All
                           traits share this common property.
                         type: boolean
+                      hotReload:
+                        description: Enable "hot reload" when a secret/configmap mounted
+                          is edited (default true)
+                        type: boolean
                       resources:
                         description: 'A list of resources (text or binary content)
                           pointing to configmap/secret. The resources are expected
@@ -3140,6 +3144,10 @@ spec:
                         description: Can be used to enable or disable a trait. All
                           traits share this common property.
                         type: boolean
+                      hotReload:
+                        description: Enable "hot reload" when a secret/configmap mounted
+                          is edited (default true)
+                        type: boolean
                       resources:
                         description: 'A list of resources (text or binary content)
                           pointing to configmap/secret. The resources are expected
diff --git a/config/crd/bases/camel.apache.org_integrations.yaml b/config/crd/bases/camel.apache.org_integrations.yaml
index 92b5c93eb..0f6b328fb 100644
--- a/config/crd/bases/camel.apache.org_integrations.yaml
+++ b/config/crd/bases/camel.apache.org_integrations.yaml
@@ -7067,6 +7067,10 @@ spec:
                         description: Can be used to enable or disable a trait. All
                           traits share this common property.
                         type: boolean
+                      hotReload:
+                        description: Enable "hot reload" when a secret/configmap mounted
+                          is edited (default true)
+                        type: boolean
                       resources:
                         description: 'A list of resources (text or binary content)
                           pointing to configmap/secret. The resources are expected
diff --git a/config/crd/bases/camel.apache.org_kameletbindings.yaml b/config/crd/bases/camel.apache.org_kameletbindings.yaml
index f05ef63a4..e0a56fcf5 100644
--- a/config/crd/bases/camel.apache.org_kameletbindings.yaml
+++ b/config/crd/bases/camel.apache.org_kameletbindings.yaml
@@ -7355,6 +7355,10 @@ spec:
                             description: Can be used to enable or disable a trait.
                               All traits share this common property.
                             type: boolean
+                          hotReload:
+                            description: Enable "hot reload" when a secret/configmap
+                              mounted is edited (default true)
+                            type: boolean
                           resources:
                             description: 'A list of resources (text or binary content)
                               pointing to configmap/secret. The resources are expected
diff --git a/config/crd/bases/camel.apache.org_pipes.yaml b/config/crd/bases/camel.apache.org_pipes.yaml
index 076dad280..76a0ade90 100644
--- a/config/crd/bases/camel.apache.org_pipes.yaml
+++ b/config/crd/bases/camel.apache.org_pipes.yaml
@@ -7352,6 +7352,10 @@ spec:
                             description: Can be used to enable or disable a trait.
                               All traits share this common property.
                             type: boolean
+                          hotReload:
+                            description: Enable "hot reload" when a secret/configmap
+                              mounted is edited (default true)
+                            type: boolean
                           resources:
                             description: 'A list of resources (text or binary content)
                               pointing to configmap/secret. The resources are expected
diff --git a/docs/modules/ROOT/partials/apis/camel-k-crds.adoc b/docs/modules/ROOT/partials/apis/camel-k-crds.adoc
index a7d86ea4e..d0480ef70 100644
--- a/docs/modules/ROOT/partials/apis/camel-k-crds.adoc
+++ b/docs/modules/ROOT/partials/apis/camel-k-crds.adoc
@@ -6856,6 +6856,13 @@ Syntax: [configmap{vbar}secret]:name[/key][@path], where name represents the res
 
 A list of Persistent Volume Claims to be mounted. Syntax: [pvcname:/container/path]
 
+|`hotReload` +
+bool
+|
+
+
+Enable "hot reload" when a secret/configmap mounted is edited (default true)
+
 
 |===
 
diff --git a/docs/modules/traits/pages/mount.adoc b/docs/modules/traits/pages/mount.adoc
index 45f5503d4..2847d362a 100644
--- a/docs/modules/traits/pages/mount.adoc
+++ b/docs/modules/traits/pages/mount.adoc
@@ -45,6 +45,10 @@ Syntax: [configmap\|secret]:name[/key][@path], where name represents the resourc
 | []string
 | A list of Persistent Volume Claims to be mounted. Syntax: [pvcname:/container/path]
 
+| mount.hot-reload
+| bool
+| Enable "hot reload" when a secret/configmap mounted is edited (default true)
+
 |===
 
 // End of autogenerated code - DO NOT EDIT! (configuration)
diff --git a/e2e/common/config/config_reload_test.go b/e2e/common/config/config_reload_test.go
index 71106d1ce..c419838f8 100644
--- a/e2e/common/config/config_reload_test.go
+++ b/e2e/common/config/config_reload_test.go
@@ -52,6 +52,31 @@ func TestConfigmapHotReload(t *testing.T) {
 	Expect(Kamel("delete", "--all", "-n", ns).Execute()).To(Succeed())
 }
 
+func TestConfigmapHotReloadFalse(t *testing.T) {
+	RegisterTestingT(t)
+
+	var cmData = make(map[string]string)
+	cmData["my-configmap-key"] = "my configmap content"
+	CreatePlainTextConfigmap(ns, "my-hot-cm-2", cmData)
+
+	Expect(KamelRunWithID(operatorID, ns, "./files/config-configmap-route.groovy",
+		"--config",
+		"configmap:my-hot-cm-2",
+		// DO NOT hot reload
+		"-t",
+		"mount.hot-reload=false",
+	).Execute()).To(Succeed())
+	Eventually(IntegrationPodPhase(ns, "config-configmap-route"), TestTimeoutLong).Should(Equal(corev1.PodRunning))
+	Eventually(IntegrationConditionStatus(ns, "config-configmap-route", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue))
+	Eventually(IntegrationLogs(ns, "config-configmap-route"), TestTimeoutShort).Should(ContainSubstring("my configmap content"))
+
+	cmData["my-configmap-key"] = "my configmap content updated"
+	UpdatePlainTextConfigmap(ns, "my-hot-cm-2", cmData)
+	Eventually(IntegrationLogs(ns, "config-configmap-route"), TestTimeoutShort).Should(Not(ContainSubstring("my configmap content updated")))
+
+	Expect(Kamel("delete", "--all", "-n", ns).Execute()).To(Succeed())
+}
+
 func TestSecretHotReload(t *testing.T) {
 	RegisterTestingT(t)
 
diff --git a/helm/camel-k/crds/crd-integration-platform.yaml b/helm/camel-k/crds/crd-integration-platform.yaml
index ba79f08de..5b8fcb43c 100644
--- a/helm/camel-k/crds/crd-integration-platform.yaml
+++ b/helm/camel-k/crds/crd-integration-platform.yaml
@@ -1384,6 +1384,10 @@ spec:
                         description: Can be used to enable or disable a trait. All
                           traits share this common property.
                         type: boolean
+                      hotReload:
+                        description: Enable "hot reload" when a secret/configmap mounted
+                          is edited (default true)
+                        type: boolean
                       resources:
                         description: 'A list of resources (text or binary content)
                           pointing to configmap/secret. The resources are expected
@@ -3140,6 +3144,10 @@ spec:
                         description: Can be used to enable or disable a trait. All
                           traits share this common property.
                         type: boolean
+                      hotReload:
+                        description: Enable "hot reload" when a secret/configmap mounted
+                          is edited (default true)
+                        type: boolean
                       resources:
                         description: 'A list of resources (text or binary content)
                           pointing to configmap/secret. The resources are expected
diff --git a/helm/camel-k/crds/crd-integration.yaml b/helm/camel-k/crds/crd-integration.yaml
index 92b5c93eb..0f6b328fb 100644
--- a/helm/camel-k/crds/crd-integration.yaml
+++ b/helm/camel-k/crds/crd-integration.yaml
@@ -7067,6 +7067,10 @@ spec:
                         description: Can be used to enable or disable a trait. All
                           traits share this common property.
                         type: boolean
+                      hotReload:
+                        description: Enable "hot reload" when a secret/configmap mounted
+                          is edited (default true)
+                        type: boolean
                       resources:
                         description: 'A list of resources (text or binary content)
                           pointing to configmap/secret. The resources are expected
diff --git a/helm/camel-k/crds/crd-kamelet-binding.yaml b/helm/camel-k/crds/crd-kamelet-binding.yaml
index f05ef63a4..e0a56fcf5 100644
--- a/helm/camel-k/crds/crd-kamelet-binding.yaml
+++ b/helm/camel-k/crds/crd-kamelet-binding.yaml
@@ -7355,6 +7355,10 @@ spec:
                             description: Can be used to enable or disable a trait.
                               All traits share this common property.
                             type: boolean
+                          hotReload:
+                            description: Enable "hot reload" when a secret/configmap
+                              mounted is edited (default true)
+                            type: boolean
                           resources:
                             description: 'A list of resources (text or binary content)
                               pointing to configmap/secret. The resources are expected
diff --git a/helm/camel-k/crds/crd-pipe.yaml b/helm/camel-k/crds/crd-pipe.yaml
index 076dad280..76a0ade90 100644
--- a/helm/camel-k/crds/crd-pipe.yaml
+++ b/helm/camel-k/crds/crd-pipe.yaml
@@ -7352,6 +7352,10 @@ spec:
                             description: Can be used to enable or disable a trait.
                               All traits share this common property.
                             type: boolean
+                          hotReload:
+                            description: Enable "hot reload" when a secret/configmap
+                              mounted is edited (default true)
+                            type: boolean
                           resources:
                             description: 'A list of resources (text or binary content)
                               pointing to configmap/secret. The resources are expected
diff --git a/pkg/apis/camel/v1/trait/mount.go b/pkg/apis/camel/v1/trait/mount.go
index 284debb8a..2782a0eb3 100644
--- a/pkg/apis/camel/v1/trait/mount.go
+++ b/pkg/apis/camel/v1/trait/mount.go
@@ -35,4 +35,6 @@ type MountTrait struct {
 	Resources []string `property:"resources" json:"resources,omitempty"`
 	// A list of Persistent Volume Claims to be mounted. Syntax: [pvcname:/container/path]
 	Volumes []string `property:"volumes" json:"volumes,omitempty"`
+	// Enable "hot reload" when a secret/configmap mounted is edited (default true)
+	HotReload *bool `property:"hot-reload" json:"hotReload,omitempty"`
 }
diff --git a/pkg/apis/camel/v1/trait/zz_generated.deepcopy.go b/pkg/apis/camel/v1/trait/zz_generated.deepcopy.go
index c1d0423f9..bad665a54 100644
--- a/pkg/apis/camel/v1/trait/zz_generated.deepcopy.go
+++ b/pkg/apis/camel/v1/trait/zz_generated.deepcopy.go
@@ -685,6 +685,11 @@ func (in *MountTrait) DeepCopyInto(out *MountTrait) {
 		*out = make([]string, len(*in))
 		copy(*out, *in)
 	}
+	if in.HotReload != nil {
+		in, out := &in.HotReload, &out.HotReload
+		*out = new(bool)
+		**out = **in
+	}
 }
 
 // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MountTrait.
diff --git a/pkg/controller/integration/integration_controller.go b/pkg/controller/integration/integration_controller.go
index 51970810d..c4013d382 100644
--- a/pkg/controller/integration/integration_controller.go
+++ b/pkg/controller/integration/integration_controller.go
@@ -31,6 +31,7 @@ import (
 	"k8s.io/apimachinery/pkg/runtime/schema"
 	"k8s.io/apimachinery/pkg/types"
 	"k8s.io/client-go/tools/record"
+	"k8s.io/utils/pointer"
 
 	"sigs.k8s.io/controller-runtime/pkg/builder"
 	ctrl "sigs.k8s.io/controller-runtime/pkg/client"
@@ -186,7 +187,7 @@ func configmapEnqueueRequestsFromMapFunc(ctx context.Context, c client.Client, c
 
 	for _, integration := range list.Items {
 		found := false
-		if integration.Spec.Traits.Mount == nil {
+		if integration.Spec.Traits.Mount == nil || !pointer.BoolDeref(integration.Spec.Traits.Mount.HotReload, true) {
 			continue
 		}
 		for _, c := range integration.Spec.Traits.Mount.Configs {
@@ -236,7 +237,7 @@ func secretEnqueueRequestsFromMapFunc(ctx context.Context, c client.Client, sec
 
 	for _, integration := range list.Items {
 		found := false
-		if integration.Spec.Traits.Mount == nil {
+		if integration.Spec.Traits.Mount == nil || !pointer.BoolDeref(integration.Spec.Traits.Mount.HotReload, true) {
 			continue
 		}
 		for _, c := range integration.Spec.Traits.Mount.Configs {
diff --git a/resources/traits.yaml b/resources/traits.yaml
index 94a178c8c..863267f3b 100755
--- a/resources/traits.yaml
+++ b/resources/traits.yaml
@@ -1132,6 +1132,10 @@ traits:
   - name: volumes
     type: '[]string'
     description: 'A list of Persistent Volume Claims to be mounted. Syntax: [pvcname:/container/path]'
+  - name: hot-reload
+    type: bool
+    description: Enable "hot reload" when a secret/configmap mounted is edited (default
+      true)
 - name: openapi
   platform: true
   profiles: