Skip to content

feat: add GitLab Runner scaler#7473

Open
jmif wants to merge 3 commits into
kedacore:mainfrom
jmif:jmif/gitlab-runner-scaler
Open

feat: add GitLab Runner scaler#7473
jmif wants to merge 3 commits into
kedacore:mainfrom
jmif:jmif/gitlab-runner-scaler

Conversation

@jmif
Copy link
Copy Markdown

@jmif jmif commented Feb 22, 2026

Add a new scaler that scales based on pending jobs in GitLab CI/CD pipelines. The scaler queries the GitLab Jobs API for pending jobs, supports both project and group scopes, tag-based job filtering, and uses the x-total header for efficient job counting when tag filtering is not needed.

Supports ScaledObject and ScaledJob, with FromEnv parameter variants for all configuration options.

Checklist

Fixes #5616

Relates to kedacore/keda-docs#1705

@github-actions
Copy link
Copy Markdown

Thank you for your contribution! 🙏

Please understand that we will do our best to review your PR and give you feedback as soon as possible, but please bear with us if it takes a little longer as expected.

While you are waiting, make sure to:

  • Add an entry in our changelog in alphabetical order and link related issue
  • Update the documentation, if needed
  • Add unit & e2e tests for your changes
  • GitHub checks are passing
  • Is the DCO check failing? Here is how you can fix DCO issues

Once the initial tests are successful, a KEDA member will ensure that the e2e tests are run. Once the e2e tests have been successfully completed, the PR may be merged at a later date. Please be patient.

Learn more about our contribution guide.

@keda-automation keda-automation requested a review from a team February 22, 2026 23:36
@snyk-io
Copy link
Copy Markdown

snyk-io Bot commented Feb 22, 2026

Snyk checks have passed. No issues have been found so far.

Status Scanner Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@semgrep-code-kedacore
Copy link
Copy Markdown

Semgrep found 21 no-direct-write-to-responsewriter findings:

Detected directly writing or similar in 'http.ResponseWriter.write()'. This bypasses HTML escaping that prevents cross-site scripting vulnerabilities. Instead, use the 'html/template' package and render data using 'template.Execute()'.

@jmif jmif force-pushed the jmif/gitlab-runner-scaler branch 4 times, most recently from 72c8f42 to 2f6af07 Compare February 23, 2026 03:53
Comment thread pkg/scalers/gitlab_runner_scaler_test.go Outdated
@jmif jmif force-pushed the jmif/gitlab-runner-scaler branch from 2f6af07 to 6d2d790 Compare February 23, 2026 03:58
Comment thread pkg/scalers/gitlab_runner_scaler_test.go Outdated
Add a new scaler that scales based on pending jobs in GitLab CI/CD
pipelines. Supports project and group scopes, tag-based job filtering,
and uses the x-total header optimization for efficient job counting.

Signed-off-by: jmif <jmif@users.noreply.github.com>
Signed-off-by: Joe Mifsud <joe@mifsud.me>
@jmif jmif force-pushed the jmif/gitlab-runner-scaler branch from 6d2d790 to 3f86e5d Compare February 23, 2026 04:05
@zroubalik
Copy link
Copy Markdown
Member

zroubalik commented Feb 24, 2026

/run-e2e gitlab
Update: You can check the progress here

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a new GitLab Runner Scaler that enables KEDA to scale workloads based on pending jobs in GitLab CI/CD pipelines. The scaler queries the GitLab Jobs API to determine queue length and supports both project-level and group-level scoping, with tag-based filtering for job matching and efficient x-total header usage when tag filtering is not required.

Changes:

  • Added new GitLab Runner scaler implementation supporting project and group scopes with tag-based job filtering
  • Comprehensive unit and e2e test suites with mock GitLab API server
  • Schema definitions for scaler configuration parameters

Reviewed changes

Copilot reviewed 5 out of 7 changed files in this pull request and generated no comments.

Show a summary per file
File Description
pkg/scalers/gitlab_runner_scaler.go Core scaler implementation with GitLab API integration, tag filtering logic, and pagination support
pkg/scalers/gitlab_runner_scaler_test.go Comprehensive unit tests covering metadata parsing, API interactions, tag filtering, and error scenarios
tests/scalers/gitlab_runner/gitlab_runner_test.go E2e tests with mock nginx-based GitLab API server testing scale out/in behavior
schema/generated/scalers-schema.yaml YAML schema definition for the gitlab-runner scaler parameters
schema/generated/scalers-schema.json JSON schema definition for the gitlab-runner scaler parameters
pkg/scaling/scalers_builder.go Registration of the new scaler in the builder
CHANGELOG.md Changelog entry documenting the new scaler

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown
Member

@zroubalik zroubalik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Supports ScaledObject and ScaledJob, with FromEnv parameter variants for all configuration options.

I haven't reviewed the PR yet, but TBH I am not sure we should do this, I would rather completely remove the FromEnv method from KEDA.
CC @kedacore/keda-core-maintainers

@rickbrouwer
Copy link
Copy Markdown
Member

Supports ScaledObject and ScaledJob, with FromEnv parameter variants for all configuration options.

I haven't reviewed the PR yet, but TBH I am not sure we should do this, I would rather completely remove the FromEnv method from KEDA. CC @kedacore/keda-core-maintainers

Yes, true. Let's not allow this for new scalers.

@dttung2905
Copy link
Copy Markdown
Contributor

Supports ScaledObject and ScaledJob, with FromEnv parameter variants for all configuration options.

I haven't reviewed the PR yet, but TBH I am not sure we should do this, I would rather completely remove the FromEnv method from KEDA. CC @kedacore/keda-core-maintainers

Yes, true. Let's not allow this for new scalers.

same with me

Comment thread pkg/scalers/gitlab_runner_scaler.go Outdated
Comment thread pkg/scalers/gitlab_runner_scaler.go Outdated
Comment thread pkg/scalers/gitlab_runner_scaler.go Outdated
Comment thread pkg/scalers/gitlab_runner_scaler.go
Comment thread pkg/scalers/gitlab_runner_scaler.go
Comment thread pkg/scalers/gitlab_runner_scaler.go Outdated
Comment thread pkg/scalers/gitlab_runner_scaler.go Outdated
Comment thread pkg/scalers/gitlab_runner_scaler.go Outdated
Comment thread pkg/scalers/gitlab_runner_scaler.go Outdated
@jmif
Copy link
Copy Markdown
Author

jmif commented Mar 2, 2026

Updated - removed all resolvedEnv/FromEnv support from the scaler.

@keda-automation keda-automation requested a review from a team March 2, 2026 20:19
Remove resolvedEnv/FromEnv support per maintainer guidance that new
scalers should not use this pattern. Remove redundant 'optional' from
fields that already have 'default' values. Refactor URL construction
to use net/url for safe encoding and path escaping. Add max page limit
(100) to pagination loops to prevent unbounded iteration. Remove URL
and response body from error messages to avoid SSRF information leaks.
Regenerate scalers schema to reflect metadata changes.

Signed-off-by: Joe Mifsud <joe@mifsud.me>
@jmif jmif force-pushed the jmif/gitlab-runner-scaler branch from f7869a2 to 769b6ff Compare March 2, 2026 21:28
@rickbrouwer
Copy link
Copy Markdown
Member

rickbrouwer commented Apr 4, 2026

/run-e2e gitlab
Update: You can check the progress here

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 7 changed files in this pull request and generated 3 comments.

Comment on lines +161 to +164
if rem, _ := strconv.Atoi(remaining); rem == 0 {
resetTime, _ := strconv.ParseInt(r.Header.Get("RateLimit-Reset"), 10, 64)

return nil, r.Header, r.StatusCode, fmt.Errorf("GitLab API rate limit exceeded, resets at %s", time.Unix(resetTime, 0))
Comment on lines +135 to +136
func (s *gitlabRunnerScaler) getGitLabRequest(ctx context.Context, url string) ([]byte, http.Header, int, error) {
req, err := http.NewRequestWithContext(ctx, "GET", url, nil)
Comment on lines +210 to +211
s.logger.Info("reached maximum page limit for group projects", "maxPages", gitlabMaxPages)
break
@rickbrouwer rickbrouwer added the waiting-author-response All PR's or Issues where we are waiting for a response from the author label May 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

waiting-author-response All PR's or Issues where we are waiting for a response from the author

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GitLab Runner Scaler

5 participants