Skip to content

Commit

Permalink
fix(traits): logging for synthetic kits
Browse files Browse the repository at this point in the history
Ref #5519
  • Loading branch information
squakez committed May 20, 2024
1 parent c5f07cd commit 33d8524
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pkg/trait/knative.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/trait/knative_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
5 changes: 1 addition & 4 deletions pkg/trait/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
19 changes: 19 additions & 0 deletions pkg/trait/logging_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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))
}

0 comments on commit 33d8524

Please sign in to comment.