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 4317da83d0f15137b12da6a2204d2543bd9e4603 Author: Pasquale Congiusti <[email protected]> AuthorDate: Mon May 20 13:38:12 2024 +0200 fix(traits): logging for synthetic kits Ref #5519 --- pkg/trait/knative.go | 2 +- pkg/trait/knative_service.go | 2 +- pkg/trait/logging.go | 5 +---- pkg/trait/logging_test.go | 19 +++++++++++++++++++ 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/pkg/trait/knative.go b/pkg/trait/knative.go index 1fc98f3f8..a50950f0e 100644 --- a/pkg/trait/knative.go +++ b/pkg/trait/knative.go @@ -154,7 +154,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 dca734ee0..5a9358d01 100644 --- a/pkg/trait/knative_service.go +++ b/pkg/trait/knative_service.go @@ -192,7 +192,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 a1c701ee3..54c7a69d6 100644 --- a/pkg/trait/logging.go +++ b/pkg/trait/logging.go @@ -58,15 +58,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 2ff847ac6..1a2bae6d3 100644 --- a/pkg/trait/logging_test.go +++ b/pkg/trait/logging_test.go @@ -32,6 +32,7 @@ import ( traitv1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1/trait" "github.com/apache/camel-k/v2/pkg/util/boolean" "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" ) @@ -152,3 +153,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)) +}
