Skip to content

Commit

Permalink
resourcegen: add flag to configure logging
Browse files Browse the repository at this point in the history
Signed-off-by: Paul Meyer <[email protected]>
  • Loading branch information
katexochen committed Aug 15, 2024
1 parent 7f0bb43 commit 5ffe7be
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion e2e/internal/contrasttest/contrasttest.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions internal/kuberesource/mutators.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,15 +195,15 @@ 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:
if r.Spec != nil && r.Spec.Template != nil &&
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),
)
}
}
Expand Down
13 changes: 13 additions & 0 deletions internal/kuberesource/resourcegen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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] <set>...\n", os.Args[0])
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5ffe7be

Please sign in to comment.