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

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

commit bafa3cd385cee283807d6b979f87393dbea02767
Author: Pasquale Congiusti <pasquale.congiu...@gmail.com>
AuthorDate: Mon May 20 13:38:12 2024 +0200

    fix(traits): logging for synthetic kits
    
    Ref #5519
---
 pkg/trait/health_test.go     | 42 ++++++++++++++++++++++++++++++++++++++++++
 pkg/trait/knative.go         |  2 +-
 pkg/trait/knative_service.go |  2 +-
 pkg/trait/logging.go         |  5 +----
 pkg/trait/logging_test.go    | 19 +++++++++++++++++++
 5 files changed, 64 insertions(+), 6 deletions(-)

diff --git a/pkg/trait/health_test.go b/pkg/trait/health_test.go
index 599b24fa6..ff76b7b24 100644
--- a/pkg/trait/health_test.go
+++ b/pkg/trait/health_test.go
@@ -23,6 +23,7 @@ import (
        "github.com/stretchr/testify/assert"
        "github.com/stretchr/testify/require"
 
+       appsv1 "k8s.io/api/apps/v1"
        corev1 "k8s.io/api/core/v1"
        metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
        "k8s.io/utils/pointer"
@@ -119,6 +120,47 @@ func TestHealthTrait(t *testing.T) {
 
 }
 
+func createNominalHealthTrait(t *testing.T) (*healthTrait, *Environment) {
+       t.Helper()
+       catalog, err := camel.DefaultCatalog()
+       assert.Nil(t, err)
+       trait, _ := newHealthTrait().(*healthTrait)
+
+       environment := &Environment{
+               CamelCatalog: catalog,
+               Catalog:      NewCatalog(nil),
+               Integration: &v1.Integration{
+                       ObjectMeta: metav1.ObjectMeta{
+                               Name:       "integration-name",
+                               Generation: 1,
+                       },
+                       Status: v1.IntegrationStatus{
+                               Phase: v1.IntegrationPhaseRunning,
+                       },
+               },
+               Resources: kubernetes.NewCollection(),
+       }
+
+       deployment := appsv1.Deployment{
+               TypeMeta: metav1.TypeMeta{
+                       Kind:       "Deployment",
+                       APIVersion: appsv1.SchemeGroupVersion.String(),
+               },
+               Spec: appsv1.DeploymentSpec{
+                       Template: corev1.PodTemplateSpec{
+                               Spec: corev1.PodSpec{
+                                       Containers: []corev1.Container{
+                                               {Name: "integration"},
+                                       },
+                               },
+                       },
+               },
+       }
+       environment.Resources.Add(&deployment)
+
+       return trait, environment
+}
+
 func TestApplyHealthTraitSyntheticKit(t *testing.T) {
        enabled := true
        ht, environment := createNominalHealthTrait(t)
diff --git a/pkg/trait/knative.go b/pkg/trait/knative.go
index e879535ce..4a8ef8dc6 100644
--- a/pkg/trait/knative.go
+++ b/pkg/trait/knative.go
@@ -150,7 +150,7 @@ func (t *knativeTrait) Configure(e *Environment) (bool, 
*TraitCondition, error)
        return true, nil, nil
 }
 
-// This is true only when the user set the enabled flag on and the auto flag 
off
+// This is true only when the user set the enabled flag on and the auto flag 
off.
 func (t *knativeTrait) isForcefullyEnabled() bool {
        return pointer.BoolDeref(t.Enabled, false) && 
!pointer.BoolDeref(t.Auto, true)
 }
diff --git a/pkg/trait/knative_service.go b/pkg/trait/knative_service.go
index 660063c00..fd6c54a3e 100644
--- a/pkg/trait/knative_service.go
+++ b/pkg/trait/knative_service.go
@@ -189,7 +189,7 @@ func (t *knativeServiceTrait) SelectControllerStrategy(e 
*Environment) (*Control
        return nil, nil
 }
 
-// This is true only when the user set the enabled flag on and the auto flag 
off
+// This is true only when the user set the enabled flag on and the auto flag 
off.
 func (t *knativeServiceTrait) isForcefullyEnabled() bool {
        return pointer.BoolDeref(t.Enabled, false) && 
!pointer.BoolDeref(t.Auto, true)
 }
diff --git a/pkg/trait/logging.go b/pkg/trait/logging.go
index aaea69eee..a03d2bdb0 100644
--- a/pkg/trait/logging.go
+++ b/pkg/trait/logging.go
@@ -55,15 +55,12 @@ func (l loggingTrait) Configure(e *Environment) (bool, 
*TraitCondition, error) {
        if !pointer.BoolDeref(l.Enabled, true) {
                return false, NewIntegrationConditionUserDisabled("Logging"), 
nil
        }
-       if e.CamelCatalog == nil {
-               return false, 
NewIntegrationConditionPlatformDisabledCatalogMissing(), nil
-       }
 
        return e.IntegrationInRunningPhases(), nil, nil
 }
 
 func (l loggingTrait) Apply(e *Environment) error {
-       if e.CamelCatalog.Runtime.Capabilities["logging"].RuntimeProperties != 
nil {
+       if e.CamelCatalog != nil && 
e.CamelCatalog.Runtime.Capabilities["logging"].RuntimeProperties != nil {
                l.setCatalogConfiguration(e)
        } else {
                l.setEnvConfiguration(e)
diff --git a/pkg/trait/logging_test.go b/pkg/trait/logging_test.go
index 507cb2b46..e0a4fa8af 100644
--- a/pkg/trait/logging_test.go
+++ b/pkg/trait/logging_test.go
@@ -31,6 +31,7 @@ import (
        v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1"
        traitv1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1/trait"
        "github.com/apache/camel-k/v2/pkg/util/camel"
+       "github.com/apache/camel-k/v2/pkg/util/envvar"
        "github.com/apache/camel-k/v2/pkg/util/kubernetes"
        "github.com/apache/camel-k/v2/pkg/util/test"
 )
@@ -151,3 +152,21 @@ func TestJsonLoggingTrait(t *testing.T) {
        assert.Equal(t, "${camel.k.logging.jsonPrettyPrint}", 
env.ApplicationProperties["quarkus.log.console.json.pretty-print"])
        assert.Equal(t, "", env.ApplicationProperties["quarkus.console.color"])
 }
+
+func TestDefaultQuarkusLogging(t *testing.T) {
+       env := createDefaultLoggingTestEnv(t)
+       // Simulate a synthetic Integration Kit for which the catalog is not 
available
+       env.CamelCatalog = nil
+       env.IntegrationKit.Labels = map[string]string{
+               v1.IntegrationKitTypeLabel: v1.IntegrationKitTypeSynthetic,
+       }
+       env.EnvVars = []corev1.EnvVar{}
+       conditions, err := NewLoggingTestCatalog().apply(env)
+
+       require.NoError(t, err)
+       assert.NotEmpty(t, conditions)
+       assert.NotEmpty(t, env.ExecutedTraits)
+
+       assert.Equal(t, &corev1.EnvVar{Name: "QUARKUS_LOG_LEVEL", Value: 
"INFO"}, envvar.Get(env.EnvVars, envVarQuarkusLogLevel))
+       assert.Equal(t, &corev1.EnvVar{Name: "QUARKUS_LOG_CONSOLE_JSON", Value: 
"false"}, envvar.Get(env.EnvVars, envVarQuarkusLogConsoleJSON))
+}

Reply via email to