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 da56b48d9 fix(traits): don't skip for synthetic kits
da56b48d9 is described below
commit da56b48d941645bd5a07fcbf4278eb58ea6e855e
Author: Pasquale Congiusti <[email protected]>
AuthorDate: Mon May 27 11:46:07 2024 +0200
fix(traits): don't skip for synthetic kits
---
pkg/trait/camel.go | 32 ++++++++++--------
pkg/trait/camel_test.go | 22 ++++++++++++
pkg/trait/kamelets.go | 16 ++++-----
pkg/trait/kamelets_test.go | 84 ++++++++++++++++++++++++++++++++++++++++++++++
pkg/trait/mount.go | 12 ++-----
5 files changed, 135 insertions(+), 31 deletions(-)
diff --git a/pkg/trait/camel.go b/pkg/trait/camel.go
index 080976fc9..296f8993a 100644
--- a/pkg/trait/camel.go
+++ b/pkg/trait/camel.go
@@ -82,28 +82,32 @@ func (t *camelTrait) Configure(e *Environment) (bool,
*TraitCondition, error) {
func (t *camelTrait) Apply(e *Environment) error {
if e.IntegrationKit != nil && e.IntegrationKit.IsSynthetic() {
+ // Synthetic Integration Kit
+
// This is required as during init phase, the trait set by
default these values
// which are widely used in the platform for different
purposese.
if e.Integration != nil {
e.Integration.Status.RuntimeVersion = ""
e.Integration.Status.RuntimeProvider = ""
}
- return nil
- }
- if e.CamelCatalog == nil {
- if err := t.loadOrCreateCatalog(e, t.RuntimeVersion); err !=
nil {
- return err
+ } else {
+ // Managed Integration
+ if e.CamelCatalog == nil {
+ if err := t.loadOrCreateCatalog(e, t.RuntimeVersion);
err != nil {
+ return err
+ }
+ }
+ e.RuntimeVersion = e.CamelCatalog.Runtime.Version
+ if e.Integration != nil {
+ e.Integration.Status.RuntimeVersion =
e.CamelCatalog.Runtime.Version
+ e.Integration.Status.RuntimeProvider =
e.CamelCatalog.Runtime.Provider
+ }
+ if e.IntegrationKit != nil {
+ e.IntegrationKit.Status.RuntimeVersion =
e.CamelCatalog.Runtime.Version
+ e.IntegrationKit.Status.RuntimeProvider =
e.CamelCatalog.Runtime.Provider
}
}
- e.RuntimeVersion = e.CamelCatalog.Runtime.Version
- if e.Integration != nil {
- e.Integration.Status.RuntimeVersion =
e.CamelCatalog.Runtime.Version
- e.Integration.Status.RuntimeProvider =
e.CamelCatalog.Runtime.Provider
- }
- if e.IntegrationKit != nil {
- e.IntegrationKit.Status.RuntimeVersion =
e.CamelCatalog.Runtime.Version
- e.IntegrationKit.Status.RuntimeProvider =
e.CamelCatalog.Runtime.Provider
- }
+
if e.IntegrationKitInPhase(v1.IntegrationKitPhaseReady) &&
e.IntegrationInRunningPhases() {
// Get all resources
maps := t.computeConfigMaps(e)
diff --git a/pkg/trait/camel_test.go b/pkg/trait/camel_test.go
index 452f4972e..d3fe63e35 100644
--- a/pkg/trait/camel_test.go
+++ b/pkg/trait/camel_test.go
@@ -207,6 +207,28 @@ func TestApplyCamelTraitWithProperties(t *testing.T) {
}, userPropertiesCm.Data)
}
+func TestApplyCamelTraitSyntheticKitWithProperties(t *testing.T) {
+ trait, environment := createNominalCamelTest(false)
+ trait.Properties = []string{"a=b", "c=d"}
+ environment.IntegrationKit.Labels[v1.IntegrationKitTypeLabel] =
v1.IntegrationKitTypeSynthetic
+
+ configured, condition, err := trait.Configure(environment)
+ require.NoError(t, err)
+ assert.Nil(t, condition)
+ assert.True(t, configured)
+
+ err = trait.Apply(environment)
+ require.NoError(t, err)
+
+ userPropertiesCm := environment.Resources.GetConfigMap(func(cm
*corev1.ConfigMap) bool {
+ return cm.Labels["camel.apache.org/properties.type"] == "user"
+ })
+ assert.NotNil(t, userPropertiesCm)
+ assert.Equal(t, map[string]string{
+ "application.properties": "a=b\nc=d\n",
+ }, userPropertiesCm.Data)
+}
+
func TestApplyCamelTraitWithSources(t *testing.T) {
trait, environment := createNominalCamelTest(true)
diff --git a/pkg/trait/kamelets.go b/pkg/trait/kamelets.go
index f5d148fbc..cbe57786b 100644
--- a/pkg/trait/kamelets.go
+++ b/pkg/trait/kamelets.go
@@ -82,14 +82,18 @@ func (t *kameletsTrait) Configure(e *Environment) (bool,
*TraitCondition, error)
if !pointer.BoolDeref(t.Enabled, true) {
return false, NewIntegrationConditionUserDisabled("Kamelets"),
nil
}
- if e.CamelCatalog == nil {
- return false,
NewIntegrationConditionPlatformDisabledCatalogMissing(), nil
- }
if !e.IntegrationInPhase(v1.IntegrationPhaseInitialization) &&
!e.IntegrationInRunningPhases() {
return false, nil, nil
}
-
+ if t.MountPoint == "" {
+ t.MountPoint = filepath.Join(camel.BasePath, "kamelets")
+ }
if pointer.BoolDeref(t.Auto, true) {
+ if e.CamelCatalog == nil {
+ // Cannot execute this trait for synthetic
IntegrationKit. In order to use it, the
+ // user has to specify forcefully auto=false option and
pass a list of kamelets explicitly
+ return false,
NewIntegrationConditionPlatformDisabledCatalogMissing(), nil
+ }
kamelets, err := kamelets.ExtractKameletFromSources(e.Ctx,
e.Client, e.CamelCatalog, e.Resources, e.Integration)
if err != nil {
return false, nil, err
@@ -99,10 +103,6 @@ func (t *kameletsTrait) Configure(e *Environment) (bool,
*TraitCondition, error)
sort.Strings(kamelets)
t.List = strings.Join(kamelets, ",")
}
-
- if t.MountPoint == "" {
- t.MountPoint = filepath.Join(camel.BasePath, "kamelets")
- }
}
return len(t.getKameletKeys()) > 0, nil, nil
diff --git a/pkg/trait/kamelets_test.go b/pkg/trait/kamelets_test.go
index 79b4e89d4..85e606bc5 100644
--- a/pkg/trait/kamelets_test.go
+++ b/pkg/trait/kamelets_test.go
@@ -31,6 +31,7 @@ import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
+ "k8s.io/utils/pointer"
)
func TestConfigurationNoKameletsUsed(t *testing.T) {
@@ -529,6 +530,12 @@ func TestKameletConditionTrue(t *testing.T) {
assert.Equal(t, corev1.ConditionTrue, cond.Status)
assert.Equal(t, v1.IntegrationConditionKameletsAvailableReason,
cond.Reason)
assert.Contains(t, cond.Message, "[none,timer] found")
+
+ kameletsBundle := environment.Resources.GetConfigMap(func(cm
*corev1.ConfigMap) bool {
+ return cm.Labels[kubernetes.ConfigMapTypeLabel] ==
KameletBundleType
+ })
+ assert.NotNil(t, kameletsBundle)
+ assert.Contains(t, kameletsBundle.Data, "timer.kamelet.yaml", "uri:
timer:tick")
}
func createKameletsTestEnvironment(flow string, objects ...runtime.Object)
(*kameletsTrait, *Environment) {
@@ -576,3 +583,80 @@ func templateOrFail(template map[string]interface{})
*v1.Template {
t := v1.Template{RawMessage: data}
return &t
}
+
+func TestKameletSyntheticKitConditionTrue(t *testing.T) {
+ trait, environment := createKameletsTestEnvironment(
+ "",
+ &v1.Kamelet{
+ ObjectMeta: metav1.ObjectMeta{
+ Namespace: "test",
+ Name: "timer-source",
+ },
+ Spec: v1.KameletSpec{
+ Template: templateOrFail(map[string]interface{}{
+ "from": map[string]interface{}{
+ "uri": "timer:tick",
+ },
+ }),
+ },
+ })
+ environment.CamelCatalog = nil
+ environment.Integration.Spec.Sources = nil
+ trait.Auto = pointer.Bool(false)
+ trait.List = "timer-source"
+
+ enabled, condition, err := trait.Configure(environment)
+ require.NoError(t, err)
+ assert.True(t, enabled)
+ assert.Nil(t, condition)
+
+ err = trait.Apply(environment)
+ require.NoError(t, err)
+ assert.Len(t, environment.Integration.Status.Conditions, 1)
+
+ cond :=
environment.Integration.Status.GetCondition(v1.IntegrationConditionKameletsAvailable)
+ assert.NotNil(t, cond)
+ assert.Equal(t, corev1.ConditionTrue, cond.Status)
+ assert.Equal(t, v1.IntegrationConditionKameletsAvailableReason,
cond.Reason)
+ assert.Contains(t, cond.Message, "[timer-source] found")
+
+ kameletsBundle := environment.Resources.GetConfigMap(func(cm
*corev1.ConfigMap) bool {
+ return cm.Labels[kubernetes.ConfigMapTypeLabel] ==
KameletBundleType
+ })
+ assert.NotNil(t, kameletsBundle)
+ assert.Contains(t, kameletsBundle.Data, "timer-source.kamelet.yaml",
"uri: timer:tick")
+}
+
+func TestKameletSyntheticKitAutoConditionFalse(t *testing.T) {
+ trait, environment := createKameletsTestEnvironment(
+ "",
+ &v1.Kamelet{
+ ObjectMeta: metav1.ObjectMeta{
+ Namespace: "test",
+ Name: "timer-source",
+ },
+ Spec: v1.KameletSpec{
+ Template: templateOrFail(map[string]interface{}{
+ "from": map[string]interface{}{
+ "uri": "timer:tick",
+ },
+ }),
+ },
+ })
+ environment.CamelCatalog = nil
+ environment.Integration.Spec.Sources = nil
+ trait.List = "timer-source"
+
+ // Auto=true by default, so, we will need to skip as
+ // we cannot parse sources
+
+ enabled, condition, err := trait.Configure(environment)
+ require.NoError(t, err)
+ assert.False(t, enabled)
+ assert.NotNil(t, condition)
+
+ kameletsBundle := environment.Resources.GetConfigMap(func(cm
*corev1.ConfigMap) bool {
+ return cm.Labels[kubernetes.ConfigMapTypeLabel] ==
KameletBundleType
+ })
+ assert.Nil(t, kameletsBundle)
+}
diff --git a/pkg/trait/mount.go b/pkg/trait/mount.go
index 9feb91b2b..85233ff7f 100644
--- a/pkg/trait/mount.go
+++ b/pkg/trait/mount.go
@@ -75,11 +75,7 @@ func (t *mountTrait) Configure(e *Environment) (bool,
*TraitCondition, error) {
}
}
- // mount trait needs to be executed only when it has sources attached
or any trait configuration
- return len(e.Integration.AllSources()) > 0 ||
- len(t.Configs) > 0 ||
- len(t.Resources) > 0 ||
- len(t.Volumes) > 0, condition, nil
+ return true, condition, nil
}
func (t *mountTrait) Apply(e *Environment) error {
@@ -119,10 +115,8 @@ func (t *mountTrait) Apply(e *Environment) error {
}
if visited {
- // Volumes declared in the Integration resources (we skip for
synthetic kits)
- if e.IntegrationKit == nil || !e.IntegrationKit.IsSynthetic() {
- e.configureVolumesAndMounts(volumes,
&container.VolumeMounts)
- }
+ // Volumes declared in the Integration resources
+ e.configureVolumesAndMounts(volumes, &container.VolumeMounts)
// Volumes declared in the trait config/resource options
err := t.configureVolumesAndMounts(volumes,
&container.VolumeMounts)
if err != nil {