Skip to content

Commit

Permalink
fix(controller): filter confimap/secret watches
Browse files Browse the repository at this point in the history
  • Loading branch information
squakez committed Feb 7, 2024
1 parent 6e3080c commit 5d28e26
Show file tree
Hide file tree
Showing 15 changed files with 65 additions and 22 deletions.
8 changes: 6 additions & 2 deletions config/crd/bases/camel.apache.org_integrationplatforms.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion config/crd/bases/camel.apache.org_integrations.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion config/crd/bases/camel.apache.org_kameletbindings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion config/crd/bases/camel.apache.org_pipes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion docs/modules/ROOT/partials/apis/camel-k-crds.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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.


|===
Expand Down
3 changes: 2 additions & 1 deletion docs/modules/traits/pages/mount.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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.

|===

Expand Down
12 changes: 6 additions & 6 deletions e2e/common/config/config_reload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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())
Expand All @@ -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",
Expand All @@ -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())
Expand All @@ -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",
Expand All @@ -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())
Expand Down
10 changes: 10 additions & 0 deletions e2e/support/test_support.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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,
}
Expand Down Expand Up @@ -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",
Expand All @@ -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,
}
Expand Down
8 changes: 6 additions & 2 deletions helm/camel-k/crds/crd-integration-platform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion helm/camel-k/crds/crd-integration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion helm/camel-k/crds/crd-kamelet-binding.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion helm/camel-k/crds/crd-pipe.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion pkg/apis/camel/v1/trait/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
13 changes: 11 additions & 2 deletions pkg/controller/integration/integration_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand All @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion resources/traits.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 5d28e26

Please sign in to comment.