Skip to content

fix(scheduling): strip quotes from cron schedule spec before parsing - #1686

Merged
nicholas-fedor merged 1 commit into
mainfrom
fix/1685-cron-schedule-validation
May 27, 2026
Merged

fix(scheduling): strip quotes from cron schedule spec before parsing#1686
nicholas-fedor merged 1 commit into
mainfrom
fix/1685-cron-schedule-validation

Conversation

@nicholas-fedor

@nicholas-fedor nicholas-fedor commented May 27, 2026

Copy link
Copy Markdown
Owner

This PR implements input validation for values wrapped with quotations to Watchtower's schedule configuration option.

Problem

When users configure WATCHTOWER_SCHEDULE in Docker Compose with quotes (e.g., WATCHTOWER_SCHEDULE="0 0 2 * * *"), Docker Compose passes the literal quote characters as part of the environment variable value. The cron parser (robfig/cron/v3) then fails with strconv.Atoi: parsing "\"0": invalid syntax because it tries to parse "0 as an integer. This is a common Docker Compose pattern and was not handled by Watchtower.

Solution

Strip single and double quotes from the schedule specification string before passing it to the cron parser, following the same pattern already used for DOCKER_API_VERSION in the flags package. The fix is applied at the point of consumption in the scheduling code, protecting against quotes from any source (env var or CLI flag).

Changes

  • internal/scheduling/scheduling.go -- Added strings.Trim(scheduleSpec, "') to strip wrapping quotes from the schedule spec before cron parsing, and added "strings" import
  • internal/scheduling/scheduling_test.go -- Added TestRunUpgradesOnSchedule_QuotedScheduleSpec with 6 test cases covering double-quoted cron, single-quoted cron, double-quoted descriptor, unquoted variants, and double-quoted invalid specs

Summary by CodeRabbit

Release Notes

  • Bug Fixes
    • Schedule specifications now properly handle quoted cron expressions, accepting both single and double-quoted inputs alongside unquoted formats (e.g., "0 0 2 * * *", '0 0 2 * * *', or @hourly).

Review Change Stack

- Trim surrounding single and double quotes from scheduleSpec to handle values passed via Docker Compose or environment variables
- Add test cases for quoted and unquoted cron specs and descriptors to ensure correct parsing
@nicholas-fedor nicholas-fedor linked an issue May 27, 2026 that may be closed by this pull request
3 tasks
@coderabbitai

coderabbitai Bot commented May 27, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ed9ef551-8ff5-416c-a42a-972efb65d49f

📥 Commits

Reviewing files that changed from the base of the PR and between 0b2ed83 and a693f0b.

📒 Files selected for processing (2)
  • internal/scheduling/scheduling.go
  • internal/scheduling/scheduling_test.go

Walkthrough

The PR adds quote normalization to the schedule specification input in RunUpgradesOnSchedule. The implementation trims surrounding single and double quote characters before registering the schedule with the cron scheduler, with test coverage verifying both quoted and unquoted specs work correctly.

Changes

Schedule spec quote normalization

Layer / File(s) Summary
Schedule spec quote normalization and test coverage
internal/scheduling/scheduling.go, internal/scheduling/scheduling_test.go
The strings import is added, scheduleSpec is trimmed of surrounding quote characters before scheduler.AddFunc is called, and a table-driven test validates that quoted and unquoted cron expressions with seconds, descriptor formats like @hourly, and invalid specs are all handled correctly.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: stripping quotes from cron schedule specifications before parsing, which matches the primary code modification in scheduling.go.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 12 complexity · 17 duplication

Metric Results
Complexity 12
Duplication 17

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@codecov

codecov Bot commented May 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1686      +/-   ##
==========================================
+ Coverage   74.60%   74.79%   +0.19%     
==========================================
  Files          59       59              
  Lines        9839     9949     +110     
==========================================
+ Hits         7340     7441     +101     
- Misses       2237     2243       +6     
- Partials      262      265       +3     
Files with missing lines Coverage Δ
internal/scheduling/scheduling.go 88.52% <100.00%> (+0.09%) ⬆️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@nicholas-fedor
nicholas-fedor merged commit d284ce8 into main May 27, 2026
19 of 20 checks passed
@nicholas-fedor
nicholas-fedor deleted the fix/1685-cron-schedule-validation branch May 27, 2026 20:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Parsing cron schedule failing

1 participant