Use --watch-namespace flag to restrict the namespace to watch
Ref https://github.com/summerwind/actions-runner-controller/issues/377#issuecomment-793172995
This commit is contained in:
		
							parent
							
								
									1753fa3530
								
							
						
					
					
						commit
						1b8a656051
					
				|  | @ -15,7 +15,7 @@ type: application | ||||||
| # This is the chart version. This version number should be incremented each time you make changes | # This is the chart version. This version number should be incremented each time you make changes | ||||||
| # to the chart and its templates, including the app version. | # to the chart and its templates, including the app version. | ||||||
| # Versions are expected to follow Semantic Versioning (https://semver.org/) | # Versions are expected to follow Semantic Versioning (https://semver.org/) | ||||||
| version: 0.7.0 | version: 0.8.0 | ||||||
| 
 | 
 | ||||||
| home: https://github.com/summerwind/actions-runner-controller | home: https://github.com/summerwind/actions-runner-controller | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -35,6 +35,9 @@ spec: | ||||||
|         - "--enable-leader-election" |         - "--enable-leader-election" | ||||||
|         - "--sync-period={{ .Values.syncPeriod }}" |         - "--sync-period={{ .Values.syncPeriod }}" | ||||||
|         - "--docker-image={{ .Values.image.dindSidecarRepositoryAndTag }}" |         - "--docker-image={{ .Values.image.dindSidecarRepositoryAndTag }}" | ||||||
|  |         {{- if .Values.scope.singleNamespace }} | ||||||
|  |         - "--watch-namespace={{ default .Release.Namespace .Values.scope.watchNamespace }}" | ||||||
|  |         {{- end }} | ||||||
|         command: |         command: | ||||||
|         - "/manager" |         - "/manager" | ||||||
|         env: |         env: | ||||||
|  |  | ||||||
|  | @ -100,6 +100,13 @@ env: | ||||||
|   # https_proxy: "proxy.com:8080" |   # https_proxy: "proxy.com:8080" | ||||||
|   # no_proxy: "" |   # no_proxy: "" | ||||||
| 
 | 
 | ||||||
|  | scope: | ||||||
|  |   # If true, the controller will only watch custom resources in a single namespace | ||||||
|  |   singleNamespace: false | ||||||
|  |   # If `scope.singleNamespace=true`, the controller will only watch custom resources in this namespace | ||||||
|  |   # The default value is "", which means the namespace of the controller | ||||||
|  |   watchNamespace: "" | ||||||
|  | 
 | ||||||
| githubWebhookServer: | githubWebhookServer: | ||||||
|   enabled: false |   enabled: false | ||||||
|   labels: {} |   labels: {} | ||||||
|  |  | ||||||
|  | @ -110,7 +110,7 @@ func main() { | ||||||
| 		Recorder:       nil, | 		Recorder:       nil, | ||||||
| 		Scheme:         mgr.GetScheme(), | 		Scheme:         mgr.GetScheme(), | ||||||
| 		SecretKeyBytes: []byte(webhookSecretToken), | 		SecretKeyBytes: []byte(webhookSecretToken), | ||||||
| 		WatchNamespace: watchNamespace, | 		Namespace:      watchNamespace, | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	if err = hraGitHubWebhook.SetupWithManager(mgr); err != nil { | 	if err = hraGitHubWebhook.SetupWithManager(mgr); err != nil { | ||||||
|  |  | ||||||
|  | @ -53,10 +53,10 @@ type HorizontalRunnerAutoscalerGitHubWebhook struct { | ||||||
| 	// the administrator is generated and specified in GitHub Web UI.
 | 	// the administrator is generated and specified in GitHub Web UI.
 | ||||||
| 	SecretKeyBytes []byte | 	SecretKeyBytes []byte | ||||||
| 
 | 
 | ||||||
| 	// WatchNamespace is the namespace to watch for HorizontalRunnerAutoscaler's to be
 | 	// Namespace is the namespace to watch for HorizontalRunnerAutoscaler's to be
 | ||||||
| 	// scaled on Webhook.
 | 	// scaled on Webhook.
 | ||||||
| 	// Set to empty for letting it watch for all namespaces.
 | 	// Set to empty for letting it watch for all namespaces.
 | ||||||
| 	WatchNamespace string | 	Namespace string | ||||||
| 	Name      string | 	Name      string | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -230,7 +230,7 @@ func (autoscaler *HorizontalRunnerAutoscalerGitHubWebhook) Handle(w http.Respons | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (autoscaler *HorizontalRunnerAutoscalerGitHubWebhook) findHRAsByKey(ctx context.Context, value string) ([]v1alpha1.HorizontalRunnerAutoscaler, error) { | func (autoscaler *HorizontalRunnerAutoscalerGitHubWebhook) findHRAsByKey(ctx context.Context, value string) ([]v1alpha1.HorizontalRunnerAutoscaler, error) { | ||||||
| 	ns := autoscaler.WatchNamespace | 	ns := autoscaler.Namespace | ||||||
| 
 | 
 | ||||||
| 	var defaultListOpts []client.ListOption | 	var defaultListOpts []client.ListOption | ||||||
| 
 | 
 | ||||||
|  | @ -244,8 +244,8 @@ func (autoscaler *HorizontalRunnerAutoscalerGitHubWebhook) findHRAsByKey(ctx con | ||||||
| 		opts := append([]client.ListOption{}, defaultListOpts...) | 		opts := append([]client.ListOption{}, defaultListOpts...) | ||||||
| 		opts = append(opts, client.MatchingFields{scaleTargetKey: value}) | 		opts = append(opts, client.MatchingFields{scaleTargetKey: value}) | ||||||
| 
 | 
 | ||||||
| 		if autoscaler.WatchNamespace != "" { | 		if autoscaler.Namespace != "" { | ||||||
| 			opts = append(opts, client.InNamespace(autoscaler.WatchNamespace)) | 			opts = append(opts, client.InNamespace(autoscaler.Namespace)) | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		var hraList v1alpha1.HorizontalRunnerAutoscalerList | 		var hraList v1alpha1.HorizontalRunnerAutoscalerList | ||||||
|  | @ -332,7 +332,7 @@ func (autoscaler *HorizontalRunnerAutoscalerGitHubWebhook) getScaleTarget(ctx co | ||||||
| 		autoscaler.Log.Info( | 		autoscaler.Log.Info( | ||||||
| 			"Found too many scale targets: "+ | 			"Found too many scale targets: "+ | ||||||
| 				"It must be exactly one to avoid ambiguity. "+ | 				"It must be exactly one to avoid ambiguity. "+ | ||||||
| 				"Either set WatchNamespace for the webhook-based autoscaler to let it only find HRAs in the namespace, "+ | 				"Either set Namespace for the webhook-based autoscaler to let it only find HRAs in the namespace, "+ | ||||||
| 				"or update Repository or Organization fields in your RunnerDeployment resources to fix the ambiguity.", | 				"or update Repository or Organization fields in your RunnerDeployment resources to fix the ambiguity.", | ||||||
| 			"scaleTargets", strings.Join(scaleTargetIDs, ",")) | 			"scaleTargets", strings.Join(scaleTargetIDs, ",")) | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -136,7 +136,7 @@ func SetupIntegrationTest(ctx context.Context) *testEnvironment { | ||||||
| 			Log:       logf.Log, | 			Log:       logf.Log, | ||||||
| 			Recorder:  mgr.GetEventRecorderFor("horizontalrunnerautoscaler-controller"), | 			Recorder:  mgr.GetEventRecorderFor("horizontalrunnerautoscaler-controller"), | ||||||
| 			Name:      controllerName("horizontalrunnerautoscalergithubwebhook"), | 			Name:      controllerName("horizontalrunnerautoscalergithubwebhook"), | ||||||
| 			WatchNamespace: ns.Name, | 			Namespace: ns.Name, | ||||||
| 		} | 		} | ||||||
| 		err = autoscalerWebhook.SetupWithManager(mgr) | 		err = autoscalerWebhook.SetupWithManager(mgr) | ||||||
| 		Expect(err).NotTo(HaveOccurred(), "failed to setup autoscaler webhook") | 		Expect(err).NotTo(HaveOccurred(), "failed to setup autoscaler webhook") | ||||||
|  |  | ||||||
							
								
								
									
										3
									
								
								main.go
								
								
								
								
							
							
						
						
									
										3
									
								
								main.go
								
								
								
								
							|  | @ -63,6 +63,7 @@ func main() { | ||||||
| 
 | 
 | ||||||
| 		runnerImage string | 		runnerImage string | ||||||
| 		dockerImage string | 		dockerImage string | ||||||
|  | 		namespace   string | ||||||
| 
 | 
 | ||||||
| 		commonRunnerLabels commaSeparatedStringSlice | 		commonRunnerLabels commaSeparatedStringSlice | ||||||
| 	) | 	) | ||||||
|  | @ -84,6 +85,7 @@ func main() { | ||||||
| 	flag.StringVar(&c.AppPrivateKey, "github-app-private-key", c.AppPrivateKey, "The path of a private key file to authenticate as a GitHub App") | 	flag.StringVar(&c.AppPrivateKey, "github-app-private-key", c.AppPrivateKey, "The path of a private key file to authenticate as a GitHub App") | ||||||
| 	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/summerwind/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/summerwind/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.Parse() | 	flag.Parse() | ||||||
| 
 | 
 | ||||||
| 	logger := zap.New(func(o *zap.Options) { | 	logger := zap.New(func(o *zap.Options) { | ||||||
|  | @ -104,6 +106,7 @@ func main() { | ||||||
| 		LeaderElection:     enableLeaderElection, | 		LeaderElection:     enableLeaderElection, | ||||||
| 		Port:               9443, | 		Port:               9443, | ||||||
| 		SyncPeriod:         &syncPeriod, | 		SyncPeriod:         &syncPeriod, | ||||||
|  | 		Namespace:          namespace, | ||||||
| 	}) | 	}) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		setupLog.Error(err, "unable to start manager") | 		setupLog.Error(err, "unable to start manager") | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue