diff --git a/cmd/kubekite/main.go b/cmd/kubekite/main.go index ceeefe4..385af10 100644 --- a/cmd/kubekite/main.go +++ b/cmd/kubekite/main.go @@ -26,6 +26,7 @@ func main() { var kubeNamespace string var jobTemplateYaml string var kubeTimeout int + var concurrency int var format = logging.MustStringFormatter( `%{color}%{time:15:04:05.000} %{shortfile} ▶ %{level:.4s} %{id:03x}%{color:reset} %{message}`, @@ -45,6 +46,7 @@ func main() { flag.StringVar(&kubeNamespace, "kube-namespace", "default", "Kubernetes namespace to run jobs in") flag.StringVar(&jobTemplateYaml, "job-template", "job.yaml", "Path to your job template YAML file") flag.IntVar(&kubeTimeout, "kube-timeout", 15, "Timeout (in seconds) for Kubernetes API requests. Set to 0 for no timeout. Default: 15") + flag.IntVar(&concurrency, "concurrency", 25, "Number of concurrent jobs the job watcher is able to create. Default: 25") flag.Parse() @@ -82,7 +84,7 @@ func main() { log.Fatal("Error starting Buildkite API client:", err) } - jobChan := buildkite.StartBuildkiteWatcher(ctx, wg, bkc, bkOrg, bkPipeline) + jobChan := buildkite.StartBuildkiteWatcher(ctx, wg, bkc, bkOrg, bkPipeline, concurrency) go func(cancel context.CancelFunc) { // If we get a SIGINT or SIGTERM, cancel the context and unblock 'done' diff --git a/pkg/buildkite/client.go b/pkg/buildkite/client.go index 85d2016..dcbea65 100644 --- a/pkg/buildkite/client.go +++ b/pkg/buildkite/client.go @@ -39,8 +39,8 @@ func NewBuildkiteClient(bkAPIToken string, debug bool) (*buildkite.Client, error } // StartBuildkiteWatcher starts a watcher that monitors a pipeline for new jobs -func StartBuildkiteWatcher(ctx context.Context, wg *sync.WaitGroup, client *buildkite.Client, org string, pipeline string) chan string { - c := make(chan string, 10) +func StartBuildkiteWatcher(ctx context.Context, wg *sync.WaitGroup, client *buildkite.Client, org string, pipeline string, concurrency int) chan string { + c := make(chan string, concurrency) go watchBuildkiteJobs(ctx, wg, client, org, pipeline, c) diff --git a/rbac/rbac.yaml b/rbac/rbac.yaml index 1cd1fc0..003dc36 100644 --- a/rbac/rbac.yaml +++ b/rbac/rbac.yaml @@ -2,7 +2,7 @@ apiVersion: rbac.authorization.k8s.io/v1 kind: Role metadata: name: kubekite - namespace: default + namespace: buildkite rules: - apiGroups: [""] resources: ["pods"] @@ -20,7 +20,7 @@ apiVersion: rbac.authorization.k8s.io/v1 kind: RoleBinding metadata: name: kubekite - namespace: default + namespace: buildkite roleRef: apiGroup: rbac.authorization.k8s.io kind: Role @@ -28,4 +28,4 @@ roleRef: subjects: - kind: ServiceAccount name: kubekite - namespace: default + namespace: buildkite