diff --git a/cmd/deploy_test.go b/cmd/deploy_test.go index a8130eed..afc6cda4 100644 --- a/cmd/deploy_test.go +++ b/cmd/deploy_test.go @@ -222,6 +222,18 @@ central: }, }, + { + name: "config file sets crs issue retries", + config: ` +securedCluster: + crsIssueRetries: 5 +`, + args: []string{"--config", configFilePath}, + assert: func(t *testing.T, cfg deployer.Config) { + assert.Equal(t, uint(5), cfg.SecuredCluster.CRSIssueRetries, "SecuredCluster.CRSIssueRetries mismatch") + }, + }, + { name: "flags can override earlier specified config file", config: ` diff --git a/internal/deployer/config.go b/internal/deployer/config.go index fdaf3ef2..d1eba101 100644 --- a/internal/deployer/config.go +++ b/internal/deployer/config.go @@ -431,6 +431,7 @@ type SecuredClusterConfig struct { EarlyReadiness *bool `yaml:"earlyReadiness,omitempty"` Metadata CRMetadata `yaml:"metadata,omitempty"` Spec map[string]interface{} `yaml:"spec,omitempty"` + CRSIssueRetries uint `yaml:"crsIssueRetries,omitempty"` } func (s *SecuredClusterConfig) EarlyReadinessEnabled() bool { @@ -450,6 +451,7 @@ func DefaultSecuredClusterConfig() SecuredClusterConfig { cfg.DeployTimeout = DefaultSecuredClusterWaitTimeout cfg.Namespace = "acs-sensor" cfg.EarlyReadiness = new(true) + cfg.CRSIssueRetries = DefaultCRSIssueRetries return cfg } diff --git a/internal/deployer/crs.go b/internal/deployer/crs.go index 6938ff97..38a1b106 100644 --- a/internal/deployer/crs.go +++ b/internal/deployer/crs.go @@ -49,7 +49,7 @@ type crsGenResponse struct { // generateCRS is a retrying wrapper on top of generateCRSOnce. func (d *Deployer) generateCRS(ctx context.Context, clusterName string) (string, error) { - const maxAttempts = 20 + maxAttempts := d.config.SecuredCluster.CRSIssueRetries + 1 const retryWaitTime = 10 * time.Second client, err := d.centralHTTPClient() @@ -58,7 +58,7 @@ func (d *Deployer) generateCRS(ctx context.Context, clusterName string) (string, } var lastErr error - for attempt := 1; attempt <= maxAttempts; attempt++ { + for attempt := uint(1); attempt <= maxAttempts; attempt++ { if attempt > 1 { log.Infof("Retrying CRS generation (attempt %d/%d) after %v...", attempt, maxAttempts, retryWaitTime) select { diff --git a/internal/deployer/deployer.go b/internal/deployer/deployer.go index 09d6384b..e5b75310 100644 --- a/internal/deployer/deployer.go +++ b/internal/deployer/deployer.go @@ -31,6 +31,7 @@ import ( var ( DefaultCentralWaitTimeout = 20 * time.Minute DefaultSecuredClusterWaitTimeout = 20 * time.Minute + DefaultCRSIssueRetries = uint(20) pauseReconcileAnnotationKey = "stackrox.io/pause-reconcile"