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)) + } + }) + } +}