Skip to content

Conversation

@chlins
Copy link
Member

@chlins chlins commented Jun 27, 2025

This pull request introduces a new utility function for reading environment variables and updates the job execution retention logic to use environment-configurable values. It also includes comprehensive unit tests for the new utility function. Below are the most important changes:

New Utility Function for Environment Variables

  • Added GetEnvInt64 function in src/lib/env.go to read environment variables as int64 with a default fallback value. This ensures flexibility in configuring values through environment variables.

Refactoring of Job Execution Retention Logic

  • Updated the executionSweeperCount map in src/jobservice/job/known_jobs.go to use the GetEnvInt64 function for fetching retention counts from environment variables. This allows dynamic configuration of retention counts without changing the code.
  • Imported the lib package in src/jobservice/job/known_jobs.go to utilize the new utility function.

Unit Testing for the Utility Function

  • Added src/lib/env_test.go with comprehensive test cases for GetEnvInt64, covering scenarios such as valid values, unset variables, invalid values, zero, negative, and large numbers. This ensures reliability and correctness of the function.

Thank you for contributing to Harbor!

Comprehensive Summary of your change

Issue being fixed

#20777

Please indicate you've done the following:

  • Well Written Title and Summary of the PR
  • Label the PR as needed. "release-note/ignore-for-release, release-note/new-feature, release-note/update, release-note/enhancement, release-note/community, release-note/breaking-change, release-note/docs, release-note/infra, release-note/deprecation"
  • Accepted the DCO. Commits without the DCO will delay acceptance.
  • Made sure tests are passing and test coverage is added if needed.
  • Considered the docs impact and opened a new docs issue or PR with docs changes if needed in website repository.

@chlins chlins added the release-note/update Update or Fix label Jun 27, 2025
@chlins chlins requested a review from a team as a code owner June 27, 2025 08:14
@chlins chlins assigned MinerYang and unassigned OrlinVasilev Jun 27, 2025
@chlins chlins added release-note/enhancement Label to mark PR to be added under release notes as enhancement and removed release-note/update Update or Fix labels Jun 27, 2025
@codecov
Copy link

codecov bot commented Jun 27, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 65.89%. Comparing base (c8c11b4) to head (e9a58d7).
Report is 500 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##             main   #22129       +/-   ##
===========================================
+ Coverage   45.36%   65.89%   +20.52%     
===========================================
  Files         244     1072      +828     
  Lines       13333   115713   +102380     
  Branches     2719     2925      +206     
===========================================
+ Hits         6049    76246    +70197     
- Misses       6983    35243    +28260     
- Partials      301     4224     +3923     
Flag Coverage Δ
unittests 65.89% <100.00%> (+20.52%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/jobservice/job/known_jobs.go 0.00% <ø> (ø)
src/lib/env.go 100.00% <100.00%> (ø)

... and 984 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Member

@Vad1mo Vad1mo left a comment

Choose a reason for hiding this comment

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

Why is this config option bypassing config.go, and the usual way of on how new configuration options are introduced into Harbor?

@chlins
Copy link
Member Author

chlins commented Jul 1, 2025

Why is this config option bypassing config.go, and the usual way of on how new configuration options are introduced into Harbor?

@Vad1mo Currently, not all configurations go through config. The configurations that do are generally focused on a specific function and need to be exposed to users during deployment and installation. However, some configurations don't necessarily need to be exposed—they might just be advanced settings that most users don't need to customize. Adding another config layer in such cases would actually increase complexity and maintenance costs. In my opinion, these configurations are just custom needs for a small number of users and won't be reused elsewhere, so directly reading environment variables is the simplest approach.

Copy link
Contributor

@wy65701436 wy65701436 left a comment

Choose a reason for hiding this comment

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

lgtm

@chlins chlins enabled auto-merge (squash) July 1, 2025 06:45
@chlins chlins merged commit 0f8913b into goharbor:main Jul 1, 2025
22 of 24 checks passed
AYDEV-FR pushed a commit to AYDEV-FR/harbor that referenced this pull request Jul 4, 2025
OrlinVasilev pushed a commit to OrlinVasilev/harbor that referenced this pull request Oct 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-note/enhancement Label to mark PR to be added under release notes as enhancement target/2.14.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants