From e38c6ea8841236dea3188a0eeeab3b361346545b Mon Sep 17 00:00:00 2001 From: Otavio Rodolfo Piske Date: Wed, 18 Aug 2021 11:33:48 +0200 Subject: [PATCH] Reworked logging trait dependencies As part of GH issue apache/camel-k#2541, moved the dependency to the runtime to ensure it's always present, even with custom base images or other customizations. This also allow us to manage the dependencies on a single place instead of spreading them over the codebase. --- pkg/trait/dependencies_test.go | 4 ++++ pkg/trait/logging.go | 17 ++--------------- 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/pkg/trait/dependencies_test.go b/pkg/trait/dependencies_test.go index f37c12de38..6490a8c184 100644 --- a/pkg/trait/dependencies_test.go +++ b/pkg/trait/dependencies_test.go @@ -86,6 +86,7 @@ func TestIntegrationDefaultDeps(t *testing.T) { "camel:direct", "camel:log", "mvn:org.apache.camel.quarkus:camel-quarkus-java-joor-dsl", + "mvn:io.quarkus:quarkus-logging-json", "mvn:org.apache.camel.k:camel-k-runtime"}, e.Integration.Status.Dependencies, ) @@ -134,6 +135,7 @@ func TestIntegrationCustomDeps(t *testing.T) { "camel:netty-http", "org.foo:bar", "mvn:org.apache.camel.quarkus:camel-quarkus-java-joor-dsl", + "mvn:io.quarkus:quarkus-logging-json", "mvn:org.apache.camel.k:camel-k-runtime"}, e.Integration.Status.Dependencies, ) @@ -192,6 +194,7 @@ func TestIntegrationAutoGeneratedDeps(t *testing.T) { "mvn:org.apache.camel.quarkus:camel-quarkus-rest", "mvn:org.apache.camel.quarkus:camel-quarkus-java-joor-dsl", "mvn:org.apache.camel.quarkus:camel-quarkus-xml-io-dsl", + "mvn:io.quarkus:quarkus-logging-json", "mvn:org.apache.camel.k:camel-k-runtime", "mvn:org.apache.camel.quarkus:camel-quarkus-platform-http"}, e.Integration.Status.Dependencies, @@ -238,6 +241,7 @@ func TestIntegrationCustomLoader(t *testing.T) { []string{ "camel:direct", "camel:log", + "mvn:io.quarkus:quarkus-logging-json", "mvn:org.apache.camel.quarkus:camel-quarkus-yaml-dsl", "mvn:org.apache.camel.k:camel-k-runtime"}, e.Integration.Status.Dependencies, diff --git a/pkg/trait/logging.go b/pkg/trait/logging.go index 90e107b4c2..0c97dccc7e 100644 --- a/pkg/trait/logging.go +++ b/pkg/trait/logging.go @@ -19,7 +19,6 @@ package trait import ( v1 "github.com/apache/camel-k/pkg/apis/camel/v1" - "github.com/apache/camel-k/pkg/util" "github.com/apache/camel-k/pkg/util/envvar" ) @@ -29,7 +28,6 @@ const ( envVarQuarkusLogConsoleFormat = "QUARKUS_LOG_CONSOLE_FORMAT" envVarQuarkusLogConsoleJson = "QUARKUS_LOG_CONSOLE_JSON" envVarQuarkusLogConsoleJsonPrettyPrint = "QUARKUS_LOG_CONSOLE_JSON_PRETTY_PRINT" - depQuarkusLoggingJson = "mvn:io.quarkus:quarkus-logging-json" defaultLogLevel = "INFO" ) @@ -63,22 +61,10 @@ func (l loggingTrait) Configure(environment *Environment) (bool, error) { return false, nil } - return environment.IntegrationInPhase(v1.IntegrationPhaseInitialization, v1.IntegrationPhaseDeploying, - v1.IntegrationPhaseRunning), nil + return environment.IntegrationInPhase(v1.IntegrationPhaseDeploying, v1.IntegrationPhaseRunning), nil } func (l loggingTrait) Apply(environment *Environment) error { - if environment.IntegrationInPhase(v1.IntegrationPhaseInitialization) { - if IsTrue(l.Json) { - if environment.Integration.Status.Dependencies == nil { - environment.Integration.Status.Dependencies = make([]string, 0) - } - util.StringSliceUniqueAdd(&environment.Integration.Status.Dependencies, depQuarkusLoggingJson) - } - - return nil - } - envvar.SetVal(&environment.EnvVars, envVarQuarkusLogLevel, l.Level) if l.Format != "" { @@ -91,6 +77,7 @@ func (l loggingTrait) Apply(environment *Environment) error { envvar.SetVal(&environment.EnvVars, envVarQuarkusLogConsoleJsonPrettyPrint, True) } } else { + // If the trait is false OR unset, we default to false. envvar.SetVal(&environment.EnvVars, envVarQuarkusLogConsoleJson, False) if IsNilOrTrue(l.Color) {