Compare commits

..

6 Commits

Author SHA1 Message Date
Yusuke Kuoka
c0b8f9d483 Merge pull request #380 from summerwind/ns-flag
Use --watch-namespace flag to restrict the namespace to watch
2021-03-09 15:03:32 +09:00
Yusuke Kuoka
ced1c2321a Fix chart-testing failing due to conflict between authSecret and dummySecret 2021-03-09 14:54:55 +09:00
Yusuke Kuoka
1b8a656051 Use --watch-namespace flag to restrict the namespace to watch
Ref https://github.com/summerwind/actions-runner-controller/issues/377#issuecomment-793172995
2021-03-09 09:46:21 +09:00
Rob Whitby
1753fa3530 handle GET requests in webhook hra (#378) 2021-03-09 08:46:27 +09:00
Johannes Nicolai
8c0f3dfc79 Set runner group for runners with enterprise scope (#376)
* so far, runner group parameter is only set for runners with org scope
* now set group for enterprise runners as well
* removed null check for org scope as either org or enterprise will be set
2021-03-08 09:18:23 +09:00
Rob Whitby
dbda292f54 fix typo in examples (#373) 2021-03-08 09:18:10 +09:00
11 changed files with 54 additions and 19 deletions

View File

@@ -433,7 +433,7 @@ kind: HorizontalRunnerAutoscaler
spec: spec:
scaleTargetRef: scaleTargetRef:
name: myrunners name: myrunners
scaleUpTrigggers: scaleUpTriggers:
- githubEvent: - githubEvent:
checkRun: checkRun:
types: ["created"] types: ["created"]
@@ -492,7 +492,7 @@ kind: HorizontalRunnerAutoscaler
spec: spec:
scaleTargetRef: scaleTargetRef:
name: myrunners name: myrunners
scaleUpTrigggers: scaleUpTriggers:
- githubEvent: - githubEvent:
checkRun: checkRun:
types: ["created"] types: ["created"]
@@ -514,7 +514,7 @@ kind: HorizontalRunnerAutoscaler
spec: spec:
scaleTargetRef: scaleTargetRef:
name: myrunners name: myrunners
scaleUpTrigggers: scaleUpTriggers:
- githubEvent: - githubEvent:
pullRequest: pullRequest:
types: ["synchronize"] types: ["synchronize"]

View File

@@ -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

View File

@@ -22,6 +22,9 @@ resources:
cpu: 100m cpu: 100m
memory: 128Mi memory: 128Mi
authSecret:
create: false
# Set the following to true to create a dummy secret, allowing the manager pod to start # Set the following to true to create a dummy secret, allowing the manager pod to start
# This is only useful in CI # This is only useful in CI
createDummySecret: true createDummySecret: true

View File

@@ -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:

View File

@@ -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: {}

View File

@@ -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 {

View File

@@ -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
} }
@@ -95,6 +95,12 @@ func (autoscaler *HorizontalRunnerAutoscalerGitHubWebhook) Handle(w http.Respons
} }
}() }()
// respond ok to GET / e.g. for health check
if r.Method == http.MethodGet {
fmt.Fprintln(w, "webhook server is running")
return
}
var payload []byte var payload []byte
if len(autoscaler.SecretKeyBytes) > 0 { if len(autoscaler.SecretKeyBytes) > 0 {
@@ -224,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
@@ -238,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
@@ -326,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, ","))

View File

@@ -113,6 +113,19 @@ func TestWebhookPing(t *testing.T) {
) )
} }
func TestGetRequest(t *testing.T) {
hra := HorizontalRunnerAutoscalerGitHubWebhook{}
request, _ := http.NewRequest(http.MethodGet, "/", nil)
recorder := httptest.ResponseRecorder{}
hra.Handle(&recorder, request)
response := recorder.Result()
if response.StatusCode != http.StatusOK {
t.Errorf("want %d, got %d", http.StatusOK, response.StatusCode)
}
}
func TestGetValidCapacityReservations(t *testing.T) { func TestGetValidCapacityReservations(t *testing.T) {
now := time.Now() now := time.Now()

View File

@@ -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")

View File

@@ -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")

View File

@@ -42,7 +42,7 @@ if [ -z "${RUNNER_TOKEN}" ]; then
exit 1 exit 1
fi fi
if [ -z "${RUNNER_REPO}" ] && [ -n "${RUNNER_ORG}" ] && [ -n "${RUNNER_GROUP}" ];then if [ -z "${RUNNER_REPO}" ] && [ -n "${RUNNER_GROUP}" ];then
RUNNER_GROUP_ARG="--runnergroup ${RUNNER_GROUP}" RUNNER_GROUP_ARG="--runnergroup ${RUNNER_GROUP}"
fi fi