Skip to content

Commit

Permalink
Reworked logging trait dependencies
Browse files Browse the repository at this point in the history
As part of GH issue #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.
  • Loading branch information
orpiske committed Sep 1, 2021
1 parent 9b97075 commit e38c6ea
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 15 deletions.
4 changes: 4 additions & 0 deletions pkg/trait/dependencies_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down Expand Up @@ -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,
)
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
17 changes: 2 additions & 15 deletions pkg/trait/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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"
)

Expand Down Expand Up @@ -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 != "" {
Expand All @@ -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) {
Expand Down

0 comments on commit e38c6ea

Please sign in to comment.