From 3a93f15cba1f3a4517c02f10914d6cff5cfa5c60 Mon Sep 17 00:00:00 2001 From: "Adam D. Cornett" Date: Tue, 15 Oct 2024 13:16:55 -0700 Subject: [PATCH] refactor operator newcheck constructor defaults Signed-off-by: Adam D. Cornett --- cmd/preflight/cmd/defaults.go | 9 ++++----- cmd/preflight/cmd/root.go | 2 +- internal/policy/operator/deployable_by_olm.go | 3 +-- internal/runtime/defaults.go | 1 + operator/check_operator.go | 9 +++------ 5 files changed, 10 insertions(+), 14 deletions(-) diff --git a/cmd/preflight/cmd/defaults.go b/cmd/preflight/cmd/defaults.go index 813d749c..8abe645c 100644 --- a/cmd/preflight/cmd/defaults.go +++ b/cmd/preflight/cmd/defaults.go @@ -1,9 +1,8 @@ package cmd var ( - DefaultLogFile = "preflight.log" - DefaultLogLevel = "info" - DefaultNamespace = "default" - DefaultServiceAccount = "default" - DefaultScorecardWaitTime = "240" + DefaultLogFile = "preflight.log" + DefaultLogLevel = "info" + DefaultNamespace = "default" + DefaultServiceAccount = "default" ) diff --git a/cmd/preflight/cmd/root.go b/cmd/preflight/cmd/root.go index a8a464de..34a3d843 100644 --- a/cmd/preflight/cmd/root.go +++ b/cmd/preflight/cmd/root.go @@ -88,7 +88,7 @@ func initConfig(viper *spfviper.Viper) { viper.SetDefault("serviceaccount", DefaultServiceAccount) // Set up scorecard wait time default - viper.SetDefault("scorecard_wait_time", DefaultScorecardWaitTime) + viper.SetDefault("scorecard_wait_time", runtime.DefaultScorecardWaitTime) // Set up csv timout default viper.SetDefault("csv_timeout", runtime.DefaultCSVTimeout) diff --git a/internal/policy/operator/deployable_by_olm.go b/internal/policy/operator/deployable_by_olm.go index 53e2b70e..a0b93e41 100644 --- a/internal/policy/operator/deployable_by_olm.go +++ b/internal/policy/operator/deployable_by_olm.go @@ -99,8 +99,7 @@ func (p *DeployableByOlmCheck) initOpenShifeEngine() { } } -// WithCSVTimeout overrides the default csvTimeout value, for operators that take -// additional time to install. +// WithCSVTimeout customizes how long to wait for a ClusterServiceVersion to become healthy. func WithCSVTimeout(csvTimeout time.Duration) Option { return func(oc *DeployableByOlmCheck) { oc.csvTimeout = csvTimeout diff --git a/internal/runtime/defaults.go b/internal/runtime/defaults.go index ff0ab629..3c72b231 100644 --- a/internal/runtime/defaults.go +++ b/internal/runtime/defaults.go @@ -5,4 +5,5 @@ import "time" var ( DefaultCSVTimeout = 180 * time.Second DefaultSubscriptionTimeout = 180 * time.Second + DefaultScorecardWaitTime = "240" ) diff --git a/operator/check_operator.go b/operator/check_operator.go index 4c491f06..4d19d835 100644 --- a/operator/check_operator.go +++ b/operator/check_operator.go @@ -16,16 +16,14 @@ import ( type Option = func(*operatorCheck) -// TODO(): replace this value when the default in package cmd is moved to a central location -const defaultScorecardWaitTime = "240" - // NewCheck is a check runner that executes the Operator Policy. func NewCheck(image, indeximage string, kubeconfig []byte, opts ...Option) *operatorCheck { c := &operatorCheck{ image: image, kubeconfig: kubeconfig, indeximage: indeximage, - scorecardWaitTime: defaultScorecardWaitTime, + scorecardWaitTime: runtime.DefaultScorecardWaitTime, + csvTimeout: runtime.DefaultCSVTimeout, subscriptionTimeout: runtime.DefaultSubscriptionTimeout, } @@ -168,8 +166,7 @@ func WithInsecureConnection() Option { } } -// WithCSVTimeout overrides the default csvTimeout value, for operators that take -// additional time to install. +// WithCSVTimeout customizes how long to wait for a ClusterServiceVersion to become healthy. func WithCSVTimeout(csvTimeout time.Duration) Option { return func(oc *operatorCheck) { oc.csvTimeout = csvTimeout