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


The following commit(s) were added to refs/heads/main by this push:
     new 5d28e2681 fix(controller): filter confimap/secret watches
5d28e2681 is described below

commit 5d28e2681090f547c0188a7fc8fc3981dd752af3
Author: Pasquale Congiusti <pasquale.congiu...@gmail.com>
AuthorDate: Wed Feb 7 12:24:22 2024 +0100

    fix(controller): filter confimap/secret watches
---
 config/crd/bases/camel.apache.org_integrationplatforms.yaml |  8 ++++++--
 config/crd/bases/camel.apache.org_integrations.yaml         |  4 +++-
 config/crd/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           |  3 ++-
 docs/modules/traits/pages/mount.adoc                        |  3 ++-
 e2e/common/config/config_reload_test.go                     | 12 ++++++------
 e2e/support/test_support.go                                 | 10 ++++++++++
 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                            |  3 ++-
 pkg/controller/integration/integration_controller.go        | 13 +++++++++++--
 resources/traits.yaml                                       |  3 ++-
 15 files changed, 65 insertions(+), 22 deletions(-)

diff --git a/config/crd/bases/camel.apache.org_integrationplatforms.yaml 
b/config/crd/bases/camel.apache.org_integrationplatforms.yaml
index 4d1fdf46a..703421ce0 100644
--- a/config/crd/bases/camel.apache.org_integrationplatforms.yaml
+++ b/config/crd/bases/camel.apache.org_integrationplatforms.yaml
@@ -1474,7 +1474,9 @@ spec:
                         type: boolean
                       hotReload:
                         description: Enable "hot reload" when a 
secret/configmap mounted
-                          is edited (default `false`)
+                          is edited (default `false`). The configmap/secret 
must be
+                          marked with `camel.apache.org/integration` label to 
be taken
+                          in account.
                         type: boolean
                       resources:
                         description: 'A list of resources (text or binary 
content)
@@ -3340,7 +3342,9 @@ spec:
                         type: boolean
                       hotReload:
                         description: Enable "hot reload" when a 
secret/configmap mounted
-                          is edited (default `false`)
+                          is edited (default `false`). The configmap/secret 
must be
+                          marked with `camel.apache.org/integration` label to 
be taken
+                          in account.
                         type: boolean
                       resources:
                         description: 'A list of resources (text or binary 
content)
diff --git a/config/crd/bases/camel.apache.org_integrations.yaml 
b/config/crd/bases/camel.apache.org_integrations.yaml
index 558ba2dc9..cb7af2c06 100644
--- a/config/crd/bases/camel.apache.org_integrations.yaml
+++ b/config/crd/bases/camel.apache.org_integrations.yaml
@@ -7375,7 +7375,9 @@ spec:
                         type: boolean
                       hotReload:
                         description: Enable "hot reload" when a 
secret/configmap mounted
-                          is edited (default `false`)
+                          is edited (default `false`). The configmap/secret 
must be
+                          marked with `camel.apache.org/integration` label to 
be taken
+                          in account.
                         type: boolean
                       resources:
                         description: 'A list of resources (text or binary 
content)
diff --git a/config/crd/bases/camel.apache.org_kameletbindings.yaml 
b/config/crd/bases/camel.apache.org_kameletbindings.yaml
index 574914b8c..549baab20 100644
--- a/config/crd/bases/camel.apache.org_kameletbindings.yaml
+++ b/config/crd/bases/camel.apache.org_kameletbindings.yaml
@@ -7672,7 +7672,9 @@ spec:
                             type: boolean
                           hotReload:
                             description: Enable "hot reload" when a 
secret/configmap
-                              mounted is edited (default `false`)
+                              mounted is edited (default `false`). The 
configmap/secret
+                              must be marked with 
`camel.apache.org/integration` label
+                              to be taken in account.
                             type: boolean
                           resources:
                             description: 'A list of resources (text or binary 
content)
diff --git a/config/crd/bases/camel.apache.org_pipes.yaml 
b/config/crd/bases/camel.apache.org_pipes.yaml
index 7984794fc..c83ee3d6a 100644
--- a/config/crd/bases/camel.apache.org_pipes.yaml
+++ b/config/crd/bases/camel.apache.org_pipes.yaml
@@ -7670,7 +7670,9 @@ spec:
                             type: boolean
                           hotReload:
                             description: Enable "hot reload" when a 
secret/configmap
-                              mounted is edited (default `false`)
+                              mounted is edited (default `false`). The 
configmap/secret
+                              must be marked with 
`camel.apache.org/integration` label
+                              to be taken in account.
                             type: boolean
                           resources:
                             description: 'A list of resources (text or binary 
content)
diff --git a/docs/modules/ROOT/partials/apis/camel-k-crds.adoc 
b/docs/modules/ROOT/partials/apis/camel-k-crds.adoc
index 83b136256..685bcb11d 100644
--- a/docs/modules/ROOT/partials/apis/camel-k-crds.adoc
+++ b/docs/modules/ROOT/partials/apis/camel-k-crds.adoc
@@ -7392,7 +7392,8 @@ bool
 |
 
 
-Enable "hot reload" when a secret/configmap mounted is edited (default `false`)
+Enable "hot reload" when a secret/configmap mounted is edited (default 
`false`). The configmap/secret must be
+marked with `camel.apache.org/integration` label to be taken in account.
 
 
 |===
diff --git a/docs/modules/traits/pages/mount.adoc 
b/docs/modules/traits/pages/mount.adoc
index 2e082f419..1077b8e48 100644
--- a/docs/modules/traits/pages/mount.adoc
+++ b/docs/modules/traits/pages/mount.adoc
@@ -47,7 +47,8 @@ Syntax: [configmap\|secret]:name[/key][@path], where name 
represents the resourc
 
 | mount.hot-reload
 | bool
-| Enable "hot reload" when a secret/configmap mounted is edited (default 
`false`)
+| Enable "hot reload" when a secret/configmap mounted is edited (default 
`false`). The configmap/secret must be
+marked with `camel.apache.org/integration` label to be taken in account.
 
 |===
 
diff --git a/e2e/common/config/config_reload_test.go 
b/e2e/common/config/config_reload_test.go
index 338dd7f6e..cb43fac0f 100644
--- a/e2e/common/config/config_reload_test.go
+++ b/e2e/common/config/config_reload_test.go
@@ -40,7 +40,7 @@ func TestConfigmapHotReload(t *testing.T) {
 
        var cmData = make(map[string]string)
        cmData["my-configmap-key"] = "my configmap content"
-       CreatePlainTextConfigmap(ns, "my-hot-cm", cmData)
+       CreatePlainTextConfigmapWithLabels(ns, "my-hot-cm", cmData, 
map[string]string{"camel.apache.org/integration": "test"})
 
        Expect(KamelRunWithID(operatorID, ns,
                "./files/config-configmap-route.groovy",
@@ -56,7 +56,7 @@ func TestConfigmapHotReload(t *testing.T) {
        Eventually(IntegrationLogs(ns, name), 
TestTimeoutShort).Should(ContainSubstring("my configmap content"))
 
        cmData["my-configmap-key"] = "my configmap content updated"
-       UpdatePlainTextConfigmap(ns, "my-hot-cm", cmData)
+       UpdatePlainTextConfigmapWithLabels(ns, "my-hot-cm", cmData, 
map[string]string{"camel.apache.org/integration": "test"})
        Eventually(IntegrationLogs(ns, name), 
TestTimeoutShort).Should(ContainSubstring("my configmap content updated"))
 
        Expect(Kamel("delete", "--all", "-n", ns).Execute()).To(Succeed())
@@ -69,7 +69,7 @@ func TestConfigmapHotReloadDefault(t *testing.T) {
 
        var cmData = make(map[string]string)
        cmData["my-configmap-key"] = "my configmap content"
-       CreatePlainTextConfigmap(ns, "my-hot-cm-2", cmData)
+       CreatePlainTextConfigmapWithLabels(ns, "my-hot-cm-2", cmData, 
map[string]string{"camel.apache.org/integration": "test"})
 
        Expect(KamelRunWithID(operatorID, ns, 
"./files/config-configmap-route.groovy",
                "--config",
@@ -82,7 +82,7 @@ func TestConfigmapHotReloadDefault(t *testing.T) {
        Eventually(IntegrationLogs(ns, name), 
TestTimeoutShort).Should(ContainSubstring("my configmap content"))
 
        cmData["my-configmap-key"] = "my configmap content updated"
-       UpdatePlainTextConfigmap(ns, "my-hot-cm-2", cmData)
+       UpdatePlainTextConfigmapWithLabels(ns, "my-hot-cm-2", cmData, 
map[string]string{"camel.apache.org/integration": "test"})
        Eventually(IntegrationLogs(ns, name), 
TestTimeoutShort).Should(Not(ContainSubstring("my configmap content updated")))
 
        Expect(Kamel("delete", "--all", "-n", ns).Execute()).To(Succeed())
@@ -95,7 +95,7 @@ func TestSecretHotReload(t *testing.T) {
 
        var secData = make(map[string]string)
        secData["my-secret-key"] = "very top secret"
-       CreatePlainTextSecret(ns, "my-hot-sec", secData)
+       CreatePlainTextSecretWithLabels(ns, "my-hot-sec", secData, 
map[string]string{"camel.apache.org/integration": "test"})
 
        Expect(KamelRunWithID(operatorID, ns, 
"./files/config-secret-route.groovy",
                "--config",
@@ -110,7 +110,7 @@ func TestSecretHotReload(t *testing.T) {
        Eventually(IntegrationLogs(ns, name), 
TestTimeoutShort).Should(ContainSubstring("very top secret"))
 
        secData["my-secret-key"] = "very top secret updated"
-       UpdatePlainTextSecret(ns, "my-hot-sec", secData)
+       UpdatePlainTextSecretWithLabels(ns, "my-hot-sec", secData, 
map[string]string{"camel.apache.org/integration": "test"})
        Eventually(IntegrationLogs(ns, name), 
TestTimeoutShort).Should(ContainSubstring("very top secret updated"))
 
        Expect(Kamel("delete", "--all", "-n", ns).Execute()).To(Succeed())
diff --git a/e2e/support/test_support.go b/e2e/support/test_support.go
index 3e2faf2c7..457c3b0a9 100644
--- a/e2e/support/test_support.go
+++ b/e2e/support/test_support.go
@@ -1607,6 +1607,10 @@ func CreatePlainTextConfigmapWithLabels(ns string, name 
string, data map[string]
 }
 
 func UpdatePlainTextConfigmap(ns string, name string, data map[string]string) 
error {
+       return UpdatePlainTextConfigmapWithLabels(ns, name, data, nil)
+}
+
+func UpdatePlainTextConfigmapWithLabels(ns string, name string, data 
map[string]string, labels map[string]string) error {
        cm := corev1.ConfigMap{
                TypeMeta: metav1.TypeMeta{
                        Kind:       "ConfigMap",
@@ -1615,6 +1619,7 @@ func UpdatePlainTextConfigmap(ns string, name string, 
data map[string]string) er
                ObjectMeta: metav1.ObjectMeta{
                        Namespace: ns,
                        Name:      name,
+                       Labels:    labels,
                },
                Data: data,
        }
@@ -1655,6 +1660,10 @@ func CreatePlainTextSecret(ns string, name string, data 
map[string]string) error
 }
 
 func UpdatePlainTextSecret(ns string, name string, data map[string]string) 
error {
+       return UpdatePlainTextSecretWithLabels(ns, name, data, nil)
+}
+
+func UpdatePlainTextSecretWithLabels(ns string, name string, data 
map[string]string, labels map[string]string) error {
        sec := corev1.Secret{
                TypeMeta: metav1.TypeMeta{
                        Kind:       "Secret",
@@ -1663,6 +1672,7 @@ func UpdatePlainTextSecret(ns string, name string, data 
map[string]string) error
                ObjectMeta: metav1.ObjectMeta{
                        Namespace: ns,
                        Name:      name,
+                       Labels:    labels,
                },
                StringData: data,
        }
diff --git a/helm/camel-k/crds/crd-integration-platform.yaml 
b/helm/camel-k/crds/crd-integration-platform.yaml
index 4d1fdf46a..703421ce0 100644
--- a/helm/camel-k/crds/crd-integration-platform.yaml
+++ b/helm/camel-k/crds/crd-integration-platform.yaml
@@ -1474,7 +1474,9 @@ spec:
                         type: boolean
                       hotReload:
                         description: Enable "hot reload" when a 
secret/configmap mounted
-                          is edited (default `false`)
+                          is edited (default `false`). The configmap/secret 
must be
+                          marked with `camel.apache.org/integration` label to 
be taken
+                          in account.
                         type: boolean
                       resources:
                         description: 'A list of resources (text or binary 
content)
@@ -3340,7 +3342,9 @@ spec:
                         type: boolean
                       hotReload:
                         description: Enable "hot reload" when a 
secret/configmap mounted
-                          is edited (default `false`)
+                          is edited (default `false`). The configmap/secret 
must be
+                          marked with `camel.apache.org/integration` label to 
be taken
+                          in account.
                         type: boolean
                       resources:
                         description: 'A list of resources (text or binary 
content)
diff --git a/helm/camel-k/crds/crd-integration.yaml 
b/helm/camel-k/crds/crd-integration.yaml
index 558ba2dc9..cb7af2c06 100644
--- a/helm/camel-k/crds/crd-integration.yaml
+++ b/helm/camel-k/crds/crd-integration.yaml
@@ -7375,7 +7375,9 @@ spec:
                         type: boolean
                       hotReload:
                         description: Enable "hot reload" when a 
secret/configmap mounted
-                          is edited (default `false`)
+                          is edited (default `false`). The configmap/secret 
must be
+                          marked with `camel.apache.org/integration` label to 
be taken
+                          in account.
                         type: boolean
                       resources:
                         description: 'A list of resources (text or binary 
content)
diff --git a/helm/camel-k/crds/crd-kamelet-binding.yaml 
b/helm/camel-k/crds/crd-kamelet-binding.yaml
index 574914b8c..549baab20 100644
--- a/helm/camel-k/crds/crd-kamelet-binding.yaml
+++ b/helm/camel-k/crds/crd-kamelet-binding.yaml
@@ -7672,7 +7672,9 @@ spec:
                             type: boolean
                           hotReload:
                             description: Enable "hot reload" when a 
secret/configmap
-                              mounted is edited (default `false`)
+                              mounted is edited (default `false`). The 
configmap/secret
+                              must be marked with 
`camel.apache.org/integration` label
+                              to be taken in account.
                             type: boolean
                           resources:
                             description: 'A list of resources (text or binary 
content)
diff --git a/helm/camel-k/crds/crd-pipe.yaml b/helm/camel-k/crds/crd-pipe.yaml
index 7984794fc..c83ee3d6a 100644
--- a/helm/camel-k/crds/crd-pipe.yaml
+++ b/helm/camel-k/crds/crd-pipe.yaml
@@ -7670,7 +7670,9 @@ spec:
                             type: boolean
                           hotReload:
                             description: Enable "hot reload" when a 
secret/configmap
-                              mounted is edited (default `false`)
+                              mounted is edited (default `false`). The 
configmap/secret
+                              must be marked with 
`camel.apache.org/integration` label
+                              to be taken in account.
                             type: boolean
                           resources:
                             description: 'A list of resources (text or binary 
content)
diff --git a/pkg/apis/camel/v1/trait/mount.go b/pkg/apis/camel/v1/trait/mount.go
index 48b44f20e..a0bcb889a 100644
--- a/pkg/apis/camel/v1/trait/mount.go
+++ b/pkg/apis/camel/v1/trait/mount.go
@@ -35,6 +35,7 @@ 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 `false`)
+       // Enable "hot reload" when a secret/configmap mounted is edited 
(default `false`). The configmap/secret must be
+       // marked with `camel.apache.org/integration` label to be taken in 
account.
        HotReload *bool `property:"hot-reload" json:"hotReload,omitempty"`
 }
diff --git a/pkg/controller/integration/integration_controller.go 
b/pkg/controller/integration/integration_controller.go
index 5129f6ade..233523a1e 100644
--- a/pkg/controller/integration/integration_controller.go
+++ b/pkg/controller/integration/integration_controller.go
@@ -37,6 +37,7 @@ import (
        "sigs.k8s.io/controller-runtime/pkg/event"
        "sigs.k8s.io/controller-runtime/pkg/handler"
        "sigs.k8s.io/controller-runtime/pkg/manager"
+       "sigs.k8s.io/controller-runtime/pkg/predicate"
        "sigs.k8s.io/controller-runtime/pkg/reconcile"
 
        "knative.dev/serving/pkg/apis/serving"
@@ -375,7 +376,11 @@ func watchIntegrationResources(c client.Client, b 
*builder.Builder) {
                                        return []reconcile.Request{}
                                }
                                return configmapEnqueueRequestsFromMapFunc(ctx, 
c, cm)
-                       })).
+                       }),
+                       
builder.WithPredicates(predicate.NewPredicateFuncs(func(object ctrl.Object) 
bool {
+                               return 
object.GetLabels()["camel.apache.org/integration"] != ""
+                       })),
+               ).
                Watches(&corev1.Secret{},
                        handler.EnqueueRequestsFromMapFunc(func(ctx 
context.Context, a ctrl.Object) []reconcile.Request {
                                secret, ok := a.(*corev1.Secret)
@@ -384,7 +389,11 @@ func watchIntegrationResources(c client.Client, b 
*builder.Builder) {
                                        return []reconcile.Request{}
                                }
                                return secretEnqueueRequestsFromMapFunc(ctx, c, 
secret)
-                       })).
+                       }),
+                       
builder.WithPredicates(predicate.NewPredicateFuncs(func(object ctrl.Object) 
bool {
+                               return 
object.GetLabels()["camel.apache.org/integration"] != ""
+                       })),
+               ).
                // Watch for the Integration Pods belonging to managed 
Integrations
                Watches(&corev1.Pod{},
                        handler.EnqueueRequestsFromMapFunc(func(ctx 
context.Context, a ctrl.Object) []reconcile.Request {
diff --git a/resources/traits.yaml b/resources/traits.yaml
index 747827bea..ddf226878 100755
--- a/resources/traits.yaml
+++ b/resources/traits.yaml
@@ -1214,7 +1214,8 @@ traits:
   - name: hot-reload
     type: bool
     description: Enable "hot reload" when a secret/configmap mounted is edited 
(default
-      `false`)
+      `false`). The configmap/secret must be marked with 
`camel.apache.org/integration`
+      label to be taken in account.
 - name: openapi
   platform: true
   profiles:

Reply via email to