diff --git a/charts/actions-runner-controller/Chart.yaml b/charts/actions-runner-controller/Chart.yaml index c9406610..3d6c079c 100644 --- a/charts/actions-runner-controller/Chart.yaml +++ b/charts/actions-runner-controller/Chart.yaml @@ -15,7 +15,7 @@ type: application # 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. # 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 diff --git a/charts/actions-runner-controller/templates/deployment.yaml b/charts/actions-runner-controller/templates/deployment.yaml index 89ade7ba..9ad817ee 100644 --- a/charts/actions-runner-controller/templates/deployment.yaml +++ b/charts/actions-runner-controller/templates/deployment.yaml @@ -35,6 +35,9 @@ spec: - "--enable-leader-election" - "--sync-period={{ .Values.syncPeriod }}" - "--docker-image={{ .Values.image.dindSidecarRepositoryAndTag }}" + {{- if .Values.scope.singleNamespace }} + - "--watch-namespace={{ default .Release.Namespace .Values.scope.watchNamespace }}" + {{- end }} command: - "/manager" env: diff --git a/charts/actions-runner-controller/values.yaml b/charts/actions-runner-controller/values.yaml index 511139a6..a73fe19b 100644 --- a/charts/actions-runner-controller/values.yaml +++ b/charts/actions-runner-controller/values.yaml @@ -100,6 +100,13 @@ env: # https_proxy: "proxy.com:8080" # 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: enabled: false labels: {} diff --git a/cmd/githubwebhookserver/main.go b/cmd/githubwebhookserver/main.go index 9a026c31..ebc2ccd3 100644 --- a/cmd/githubwebhookserver/main.go +++ b/cmd/githubwebhookserver/main.go @@ -110,7 +110,7 @@ func main() { Recorder: nil, Scheme: mgr.GetScheme(), SecretKeyBytes: []byte(webhookSecretToken), - WatchNamespace: watchNamespace, + Namespace: watchNamespace, } if err = hraGitHubWebhook.SetupWithManager(mgr); err != nil { diff --git a/controllers/horizontal_runner_autoscaler_webhook.go b/controllers/horizontal_runner_autoscaler_webhook.go index 44eb2139..be9dff64 100644 --- a/controllers/horizontal_runner_autoscaler_webhook.go +++ b/controllers/horizontal_runner_autoscaler_webhook.go @@ -53,11 +53,11 @@ type HorizontalRunnerAutoscalerGitHubWebhook struct { // the administrator is generated and specified in GitHub Web UI. 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. // Set to empty for letting it watch for all namespaces. - WatchNamespace string - Name string + Namespace string + Name string } func (autoscaler *HorizontalRunnerAutoscalerGitHubWebhook) Reconcile(request reconcile.Request) (reconcile.Result, error) { @@ -230,7 +230,7 @@ func (autoscaler *HorizontalRunnerAutoscalerGitHubWebhook) Handle(w http.Respons } func (autoscaler *HorizontalRunnerAutoscalerGitHubWebhook) findHRAsByKey(ctx context.Context, value string) ([]v1alpha1.HorizontalRunnerAutoscaler, error) { - ns := autoscaler.WatchNamespace + ns := autoscaler.Namespace var defaultListOpts []client.ListOption @@ -244,8 +244,8 @@ func (autoscaler *HorizontalRunnerAutoscalerGitHubWebhook) findHRAsByKey(ctx con opts := append([]client.ListOption{}, defaultListOpts...) opts = append(opts, client.MatchingFields{scaleTargetKey: value}) - if autoscaler.WatchNamespace != "" { - opts = append(opts, client.InNamespace(autoscaler.WatchNamespace)) + if autoscaler.Namespace != "" { + opts = append(opts, client.InNamespace(autoscaler.Namespace)) } var hraList v1alpha1.HorizontalRunnerAutoscalerList @@ -332,7 +332,7 @@ func (autoscaler *HorizontalRunnerAutoscalerGitHubWebhook) getScaleTarget(ctx co autoscaler.Log.Info( "Found too many scale targets: "+ "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.", "scaleTargets", strings.Join(scaleTargetIDs, ",")) diff --git a/controllers/integration_test.go b/controllers/integration_test.go index 2a30bdfe..b4cf84bb 100644 --- a/controllers/integration_test.go +++ b/controllers/integration_test.go @@ -131,12 +131,12 @@ func SetupIntegrationTest(ctx context.Context) *testEnvironment { Expect(err).NotTo(HaveOccurred(), "failed to setup controller") autoscalerWebhook := &HorizontalRunnerAutoscalerGitHubWebhook{ - Client: mgr.GetClient(), - Scheme: scheme.Scheme, - Log: logf.Log, - Recorder: mgr.GetEventRecorderFor("horizontalrunnerautoscaler-controller"), - Name: controllerName("horizontalrunnerautoscalergithubwebhook"), - WatchNamespace: ns.Name, + Client: mgr.GetClient(), + Scheme: scheme.Scheme, + Log: logf.Log, + Recorder: mgr.GetEventRecorderFor("horizontalrunnerautoscaler-controller"), + Name: controllerName("horizontalrunnerautoscalergithubwebhook"), + Namespace: ns.Name, } err = autoscalerWebhook.SetupWithManager(mgr) Expect(err).NotTo(HaveOccurred(), "failed to setup autoscaler webhook") diff --git a/main.go b/main.go index 1defb842..11b86980 100644 --- a/main.go +++ b/main.go @@ -63,6 +63,7 @@ func main() { runnerImage string dockerImage string + namespace string 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.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.StringVar(&namespace, "watch-namespace", "", "The namespace to watch for custom resources. Set to empty for letting it watch for all namespaces.") flag.Parse() logger := zap.New(func(o *zap.Options) { @@ -104,6 +106,7 @@ func main() { LeaderElection: enableLeaderElection, Port: 9443, SyncPeriod: &syncPeriod, + Namespace: namespace, }) if err != nil { setupLog.Error(err, "unable to start manager")