From 2a3bf9802943ec91f482d9f025c8b01e1f970e46 Mon Sep 17 00:00:00 2001 From: Pujitha Paladugu <10557236+pujitha24@users.noreply.github.com> Date: Thu, 6 Aug 2026 15:13:25 -0700 Subject: [PATCH] fix(tektonresult): default watcher logs_api from spec Motivation: setting spec.logs_api: true on a TektonResult (or via TektonConfig) enables the LOGS_API env var on the tekton-results-api deployment, but the tekton-results-watcher deployment has its own, separate -logs_api command-line flag that defaults to false. That flag is what actually makes the Watcher forward TaskRun/PipelineRun logs to the API server; nothing defaulted it from the top-level logs_api setting, so users following the documented example (setting only the top-level logs_api) got an API server with logging enabled but a Watcher that never sends logs, and logs were never stored. Approach: default Result.Watcher.LogsAPI from the top-level ResultsAPIProperties.LogsAPI in Result.setDefaults() whenever the user has not explicitly set spec.watcher.logs_api, mirroring the adjacent RouteEnabled/RouteTLSTermination defaulting already in that function. An explicit spec.watcher.logs_api value is never overridden. This defaulting runs wherever Result.setDefaults() runs today, i.e. when a TektonResult is created/updated via TektonConfig (the documented install path). TektonResult.SetDefaults does not call Result.setDefaults() at all, so a CR applied directly as a standalone `kind: TektonResult` (bypassing TektonConfig) does not get this or the pre-existing RouteEnabled default either; that gap predates this change and is not addressed here. Validation: added TestResult_SetDefaultsWatcherLogsAPI, a table test covering propagate-true, propagate-false, no-override-when-explicit, and no-op-when-top-level-unset. Confirmed by temporarily reverting the fix that the two propagation subtests fail without it and pass with it: go test ./pkg/apis/operator/v1alpha1/... \ -run TestResult_SetDefaultsWatcherLogsAPI -v Also ran, all passing: go build ./... go test ./pkg/apis/operator/v1alpha1/... \ ./pkg/reconciler/kubernetes/tektonresult/... \ ./pkg/reconciler/kubernetes/tektonconfig/... gofmt -l on both changed files (clean) golangci-lint could not be run in this sandbox (its download step fails a checksum check with no network access); go vet ./pkg/apis/ operator/v1alpha1/... was run instead and reported nothing. Report: https://github.com/tektoncd/operator/issues/2600 Signed-off-by: Pujitha Paladugu <10557236+pujitha24@users.noreply.github.com> --- .../v1alpha1/tektonresult_defaults.go | 8 ++ .../v1alpha1/tektonresult_defaults_test.go | 92 +++++++++++++++++++ 2 files changed, 100 insertions(+) diff --git a/pkg/apis/operator/v1alpha1/tektonresult_defaults.go b/pkg/apis/operator/v1alpha1/tektonresult_defaults.go index 48721aca05..a5e0812625 100644 --- a/pkg/apis/operator/v1alpha1/tektonresult_defaults.go +++ b/pkg/apis/operator/v1alpha1/tektonresult_defaults.go @@ -39,4 +39,12 @@ func (c *Result) setDefaults() { if c.RouteTLSTermination == "" { c.RouteTLSTermination = "edge" } + + // The Watcher only forwards logs to the API server when its own + // logs_api flag is set; enabling the API server's logs_api alone does + // not do this. Default the Watcher to match unless the user set + // watcher.logs_api explicitly. + if c.LogsAPI != nil && c.Watcher.LogsAPI == nil { + c.Watcher.LogsAPI = c.LogsAPI + } } diff --git a/pkg/apis/operator/v1alpha1/tektonresult_defaults_test.go b/pkg/apis/operator/v1alpha1/tektonresult_defaults_test.go index 1ec7acbc7e..ead253b17c 100644 --- a/pkg/apis/operator/v1alpha1/tektonresult_defaults_test.go +++ b/pkg/apis/operator/v1alpha1/tektonresult_defaults_test.go @@ -100,3 +100,95 @@ func TestResult_SetDefaultsRoutes(t *testing.T) { t.Errorf("failed to set defaults %s", diff.PrintWantGot(d)) } } + +func TestResult_SetDefaultsWatcherLogsAPI(t *testing.T) { + tests := []struct { + name string + r *Result + want *Result + }{ + { + name: "propagates enabled logs_api to watcher when unset", + r: &Result{ + ResultsAPIProperties: ResultsAPIProperties{ + LogsAPI: ptr.Bool(true), + RouteEnabled: ptr.Bool(true), + }, + }, + want: &Result{ + ResultsAPIProperties: ResultsAPIProperties{ + LogsAPI: ptr.Bool(true), + RouteEnabled: ptr.Bool(true), + RouteTLSTermination: "edge", + }, + Watcher: ResultsWatcherProperties{ + LogsAPI: ptr.Bool(true), + }, + }, + }, + { + name: "propagates disabled logs_api to watcher when unset", + r: &Result{ + ResultsAPIProperties: ResultsAPIProperties{ + LogsAPI: ptr.Bool(false), + RouteEnabled: ptr.Bool(true), + }, + }, + want: &Result{ + ResultsAPIProperties: ResultsAPIProperties{ + LogsAPI: ptr.Bool(false), + RouteEnabled: ptr.Bool(true), + RouteTLSTermination: "edge", + }, + Watcher: ResultsWatcherProperties{ + LogsAPI: ptr.Bool(false), + }, + }, + }, + { + name: "does not override an explicit watcher logs_api", + r: &Result{ + ResultsAPIProperties: ResultsAPIProperties{ + LogsAPI: ptr.Bool(true), + RouteEnabled: ptr.Bool(true), + }, + Watcher: ResultsWatcherProperties{ + LogsAPI: ptr.Bool(false), + }, + }, + want: &Result{ + ResultsAPIProperties: ResultsAPIProperties{ + LogsAPI: ptr.Bool(true), + RouteEnabled: ptr.Bool(true), + RouteTLSTermination: "edge", + }, + Watcher: ResultsWatcherProperties{ + LogsAPI: ptr.Bool(false), + }, + }, + }, + { + name: "leaves watcher logs_api unset when API logs_api is unset", + r: &Result{ + ResultsAPIProperties: ResultsAPIProperties{ + RouteEnabled: ptr.Bool(true), + }, + }, + want: &Result{ + ResultsAPIProperties: ResultsAPIProperties{ + RouteEnabled: ptr.Bool(true), + RouteTLSTermination: "edge", + }, + }, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + tt.r.setDefaults() + if d := cmp.Diff(tt.want, tt.r); d != "" { + t.Errorf("failed to set defaults %s", diff.PrintWantGot(d)) + } + }) + } +}