feat: default scale down flag (#963)
Resolves #899 Co-authored-by: Callum <callum@domain.com> Co-authored-by: Yusuke Kuoka <ykuoka@gmail.com>
This commit is contained in:
		
							parent
							
								
									13bfa2da4e
								
							
						
					
					
						commit
						24aae58dbc
					
				|  | @ -191,9 +191,10 @@ func TestDetermineDesiredReplicas_RepositoryRunner(t *testing.T) { | ||||||
| 			client := newGithubClient(server) | 			client := newGithubClient(server) | ||||||
| 
 | 
 | ||||||
| 			h := &HorizontalRunnerAutoscalerReconciler{ | 			h := &HorizontalRunnerAutoscalerReconciler{ | ||||||
| 				Log:          log, | 				Log:                   log, | ||||||
| 				GitHubClient: client, | 				GitHubClient:          client, | ||||||
| 				Scheme:       scheme, | 				Scheme:                scheme, | ||||||
|  | 				DefaultScaleDownDelay: DefaultScaleDownDelay, | ||||||
| 			} | 			} | ||||||
| 
 | 
 | ||||||
| 			rd := v1alpha1.RunnerDeployment{ | 			rd := v1alpha1.RunnerDeployment{ | ||||||
|  | @ -441,9 +442,10 @@ func TestDetermineDesiredReplicas_OrganizationalRunner(t *testing.T) { | ||||||
| 			client := newGithubClient(server) | 			client := newGithubClient(server) | ||||||
| 
 | 
 | ||||||
| 			h := &HorizontalRunnerAutoscalerReconciler{ | 			h := &HorizontalRunnerAutoscalerReconciler{ | ||||||
| 				Log:          log, | 				Log:                   log, | ||||||
| 				Scheme:       scheme, | 				Scheme:                scheme, | ||||||
| 				GitHubClient: client, | 				GitHubClient:          client, | ||||||
|  | 				DefaultScaleDownDelay: DefaultScaleDownDelay, | ||||||
| 			} | 			} | ||||||
| 
 | 
 | ||||||
| 			rd := v1alpha1.RunnerDeployment{ | 			rd := v1alpha1.RunnerDeployment{ | ||||||
|  |  | ||||||
|  | @ -47,13 +47,13 @@ const ( | ||||||
| // HorizontalRunnerAutoscalerReconciler reconciles a HorizontalRunnerAutoscaler object
 | // HorizontalRunnerAutoscalerReconciler reconciles a HorizontalRunnerAutoscaler object
 | ||||||
| type HorizontalRunnerAutoscalerReconciler struct { | type HorizontalRunnerAutoscalerReconciler struct { | ||||||
| 	client.Client | 	client.Client | ||||||
| 	GitHubClient *github.Client | 	GitHubClient          *github.Client | ||||||
| 	Log          logr.Logger | 	Log                   logr.Logger | ||||||
| 	Recorder     record.EventRecorder | 	Recorder              record.EventRecorder | ||||||
| 	Scheme       *runtime.Scheme | 	Scheme                *runtime.Scheme | ||||||
| 
 | 	CacheDuration         time.Duration | ||||||
| 	CacheDuration time.Duration | 	DefaultScaleDownDelay time.Duration | ||||||
| 	Name          string | 	Name                  string | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| const defaultReplicas = 1 | const defaultReplicas = 1 | ||||||
|  | @ -497,7 +497,7 @@ func (r *HorizontalRunnerAutoscalerReconciler) computeReplicasWithCache(log logr | ||||||
| 	if hra.Spec.ScaleDownDelaySecondsAfterScaleUp != nil { | 	if hra.Spec.ScaleDownDelaySecondsAfterScaleUp != nil { | ||||||
| 		scaleDownDelay = time.Duration(*hra.Spec.ScaleDownDelaySecondsAfterScaleUp) * time.Second | 		scaleDownDelay = time.Duration(*hra.Spec.ScaleDownDelaySecondsAfterScaleUp) * time.Second | ||||||
| 	} else { | 	} else { | ||||||
| 		scaleDownDelay = DefaultScaleDownDelay | 		scaleDownDelay = r.DefaultScaleDownDelay | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	var scaleDownDelayUntil *time.Time | 	var scaleDownDelayUntil *time.Time | ||||||
|  |  | ||||||
							
								
								
									
										14
									
								
								main.go
								
								
								
								
							
							
						
						
									
										14
									
								
								main.go
								
								
								
								
							|  | @ -74,6 +74,7 @@ func main() { | ||||||
| 		syncPeriod           time.Duration | 		syncPeriod           time.Duration | ||||||
| 
 | 
 | ||||||
| 		gitHubAPICacheDuration time.Duration | 		gitHubAPICacheDuration time.Duration | ||||||
|  | 		defaultScaleDownDelay  time.Duration | ||||||
| 
 | 
 | ||||||
| 		runnerImage            string | 		runnerImage            string | ||||||
| 		runnerImagePullSecrets stringSlice | 		runnerImagePullSecrets stringSlice | ||||||
|  | @ -111,6 +112,7 @@ func main() { | ||||||
| 	flag.StringVar(&c.BasicauthPassword, "github-basicauth-password", c.BasicauthPassword, "Password for GitHub basic auth to use instead of PAT or GitHub APP in case it's running behind a proxy API") | 	flag.StringVar(&c.BasicauthPassword, "github-basicauth-password", c.BasicauthPassword, "Password for GitHub basic auth to use instead of PAT or GitHub APP in case it's running behind a proxy API") | ||||||
| 	flag.StringVar(&c.RunnerGitHubURL, "runner-github-url", c.RunnerGitHubURL, "GitHub URL to be used by runners during registration") | 	flag.StringVar(&c.RunnerGitHubURL, "runner-github-url", c.RunnerGitHubURL, "GitHub URL to be used by runners during registration") | ||||||
| 	flag.DurationVar(&gitHubAPICacheDuration, "github-api-cache-duration", 0, "DEPRECATED: The duration until the GitHub API cache expires. Setting this to e.g. 10m results in the controller tries its best not to make the same API call within 10m to reduce the chance of being rate-limited. Defaults to mostly the same value as sync-period. If you're tweaking this in order to make autoscaling more responsive, you'll probably want to tweak sync-period, too") | 	flag.DurationVar(&gitHubAPICacheDuration, "github-api-cache-duration", 0, "DEPRECATED: The duration until the GitHub API cache expires. Setting this to e.g. 10m results in the controller tries its best not to make the same API call within 10m to reduce the chance of being rate-limited. Defaults to mostly the same value as sync-period. If you're tweaking this in order to make autoscaling more responsive, you'll probably want to tweak sync-period, too") | ||||||
|  | 	flag.DurationVar(&defaultScaleDownDelay, "default-scale-down-delay", controllers.DefaultScaleDownDelay, "The approximate delay for a scale down followed by a scale up, used to prevent flapping (down->up->down->... loop)") | ||||||
| 	flag.DurationVar(&syncPeriod, "sync-period", 10*time.Minute, "Determines the minimum frequency at which K8s resources managed by this controller are reconciled. When you use autoscaling, set to a lower value like 10 minute, because this corresponds to the minimum time to react on demand change.") | 	flag.DurationVar(&syncPeriod, "sync-period", 10*time.Minute, "Determines the minimum frequency at which K8s resources managed by this controller are reconciled. When you use autoscaling, set to a lower value like 10 minute, because this corresponds to the minimum time to react on demand change.") | ||||||
| 	flag.Var(&commonRunnerLabels, "common-runner-labels", "Runner labels in the K1=V1,K2=V2,... format that are inherited all the runners created by the controller. See https://github.com/actions-runner-controller/actions-runner-controller/issues/321 for more information") | 	flag.Var(&commonRunnerLabels, "common-runner-labels", "Runner labels in the K1=V1,K2=V2,... format that are inherited all the runners created by the controller. See https://github.com/actions-runner-controller/actions-runner-controller/issues/321 for more information") | ||||||
| 	flag.StringVar(&namespace, "watch-namespace", "", "The namespace to watch for custom resources. Set to empty for letting it watch for all namespaces.") | 	flag.StringVar(&namespace, "watch-namespace", "", "The namespace to watch for custom resources. Set to empty for letting it watch for all namespaces.") | ||||||
|  | @ -212,6 +214,7 @@ func main() { | ||||||
| 	log.Info( | 	log.Info( | ||||||
| 		"Initializing actions-runner-controller", | 		"Initializing actions-runner-controller", | ||||||
| 		"github-api-cache-duration", gitHubAPICacheDuration, | 		"github-api-cache-duration", gitHubAPICacheDuration, | ||||||
|  | 		"default-scale-down-delay", defaultScaleDownDelay, | ||||||
| 		"sync-period", syncPeriod, | 		"sync-period", syncPeriod, | ||||||
| 		"runner-image", runnerImage, | 		"runner-image", runnerImage, | ||||||
| 		"docker-image", dockerImage, | 		"docker-image", dockerImage, | ||||||
|  | @ -220,11 +223,12 @@ func main() { | ||||||
| 	) | 	) | ||||||
| 
 | 
 | ||||||
| 	horizontalRunnerAutoscaler := &controllers.HorizontalRunnerAutoscalerReconciler{ | 	horizontalRunnerAutoscaler := &controllers.HorizontalRunnerAutoscalerReconciler{ | ||||||
| 		Client:        mgr.GetClient(), | 		Client:                mgr.GetClient(), | ||||||
| 		Log:           log.WithName("horizontalrunnerautoscaler"), | 		Log:                   log.WithName("horizontalrunnerautoscaler"), | ||||||
| 		Scheme:        mgr.GetScheme(), | 		Scheme:                mgr.GetScheme(), | ||||||
| 		GitHubClient:  ghClient, | 		GitHubClient:          ghClient, | ||||||
| 		CacheDuration: gitHubAPICacheDuration, | 		CacheDuration:         gitHubAPICacheDuration, | ||||||
|  | 		DefaultScaleDownDelay: defaultScaleDownDelay, | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	runnerPodReconciler := &controllers.RunnerPodReconciler{ | 	runnerPodReconciler := &controllers.RunnerPodReconciler{ | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue