diff --git a/e2e/internal/contrasttest/contrasttest.go b/e2e/internal/contrasttest/contrasttest.go index e157fce17e..f235ab17df 100644 --- a/e2e/internal/contrasttest/contrasttest.go +++ b/e2e/internal/contrasttest/contrasttest.go @@ -128,7 +128,7 @@ func (ct *ContrastTest) Init(t *testing.T, resources []any) { resources = kuberesource.PatchNamespaces(resources, ct.Namespace) resources = kuberesource.PatchServiceMeshAdminInterface(resources, 9901) resources = kuberesource.PatchCoordinatorMetrics(resources, 9102) - resources = kuberesource.AddLogging(resources, "debug") + resources = kuberesource.AddLogging(resources, "debug", "*") unstructuredResources, err := kuberesource.ResourcesToUnstructured(resources) require.NoError(err) diff --git a/internal/kuberesource/mutators.go b/internal/kuberesource/mutators.go index 43a9da52a1..4df9bc7fa9 100644 --- a/internal/kuberesource/mutators.go +++ b/internal/kuberesource/mutators.go @@ -195,7 +195,7 @@ func AddLoadBalancers(resources []any) []any { } // AddLogging modifies Contrast Coordinators among the resources to enable debug logging. -func AddLogging(resources []any, level string) []any { +func AddLogging(resources []any, level, subsystem string) []any { for _, resource := range resources { switch r := resource.(type) { case *applyappsv1.StatefulSetApplyConfiguration: @@ -203,7 +203,7 @@ func AddLogging(resources []any, level string) []any { r.Spec.Template.Annotations["contrast.edgeless.systems/pod-role"] == "coordinator" { r.Spec.Template.Spec.Containers[0].WithEnv( NewEnvVar("CONTRAST_LOG_LEVEL", level), - NewEnvVar("CONTRAST_LOG_SUBSYSTEMS", "*"), + NewEnvVar("CONTRAST_LOG_SUBSYSTEMS", subsystem), ) } } diff --git a/internal/kuberesource/resourcegen/main.go b/internal/kuberesource/resourcegen/main.go index e568427e2a..0800fabf37 100644 --- a/internal/kuberesource/resourcegen/main.go +++ b/internal/kuberesource/resourcegen/main.go @@ -20,6 +20,7 @@ func main() { addLoadBalancers := flag.Bool("add-load-balancers", false, "Add load balancers to selected services") addNamespaceObject := flag.Bool("add-namespace-object", false, "Add namespace object with the given namespace") addPortForwarders := flag.Bool("add-port-forwarders", false, "Add port forwarder pods for all services") + addLogging := flag.Bool("add-logging", false, "Add logging configuration, based on CONTRAST_LOG_LEVEL and CONTRAST_LOG_SUBSYSTEMS environment variables") rawPlatform := flag.String("platform", "", "Deployment platform to generate the runtime configuration for") flag.Usage = func() { fmt.Fprintf(os.Stderr, "Usage: %s [flags] ...\n", os.Args[0]) @@ -76,6 +77,18 @@ func main() { resources = kuberesource.AddLoadBalancers(resources) } + if *addLogging { + logLevel := os.Getenv("CONTRAST_LOG_LEVEL") + if logLevel == "" { + logLevel = "info" + } + logSubSystems := os.Getenv("CONTRAST_LOG_SUBSYSTEMS") + if logSubSystems == "" { + logSubSystems = "*" + } + resources = kuberesource.AddLogging(resources, logLevel, logSubSystems) + } + var replacements map[string]string if *imageReplacementsPath != "" { f, err := os.Open(*imageReplacementsPath) diff --git a/justfile b/justfile index 711a96295b..02da231000 100644 --- a/justfile +++ b/justfile @@ -86,6 +86,7 @@ populate target=default_deploy_target platform=default_platform: --image-replacements ./{{ workspace_dir }}/just.containerlookup \ --namespace {{ target }}${namespace_suffix-} \ --add-port-forwarders \ + --add-logging \ --platform {{ platform }} \ {{ target }} coordinator > ./{{ workspace_dir }}/deployment/deployment.yml echo "{{ target }}${namespace_suffix-}" > ./{{ workspace_dir }}/just.namespace