Skip to content

feat(promotion-windows): add promotion windows for auto-promotion#5544

Open
LittaKake wants to merge 1 commit intoakuity:mainfrom
LittaKake:kake/promotionwindows/add
Open

feat(promotion-windows): add promotion windows for auto-promotion#5544
LittaKake wants to merge 1 commit intoakuity:mainfrom
LittaKake:kake/promotionwindows/add

Conversation

@LittaKake
Copy link

@LittaKake LittaKake commented Dec 29, 2025

Promotion Windows

This PR partly adds the requested feature for allowing/disallowing promotions based on time windows as tracked here #1328.

PR introduces a new CRD, PromotionWindow, which can be referenced from ProjectConfig.spec.promotionPolicies[].promotionWindows to control when automatic promotions are allowed or denied.

I opted for a CRD for re-usability of common timewindows (such as weekends). Its also easier to re-use if its ever decided to put a reference field in either stage or warehouse aswell.

Note

The PR opts for putting promotionWindows directly below promotionPolicies for now, but it could be better to rework the spec with ...promotionPolicies[].autoPromotion.enabled and ...promotionPolicies[].autoPromotion.promotionWindows instead. But I want someones opinion on this before proceeding.

PromotionWindow CRD

A PromotionWindow defines, in spec, a time window using the following fields:

  • kind: Either allow or deny, determining whether promotions are permitted or blocked while the window is active.
  • schedule: A cron expression (parsed using robfig/cron) defining when the window starts.
  • duration: How long the window remains active after each scheduled start.
  • timeZone: An IANA time zone (e.g. UTC, Europe/Oslo) resolved via Go’s time package / tzdata.

Example

Define a PromotionWindow that allows promotions during weekdays:

apiVersion: kargo.akuity.io/v1alpha1
kind: PromotionWindow
metadata:
  name: allow-weekend
  namespace: my-project
spec:
  kind: "allow"
  schedule: "0 0 * * 1-5"
  duration: "24h"
  timeZone: "Europe/xxx"

Reference the window from a ProjectConfig:

apiVersion: kargo.akuity.io/v1alpha1
kind: ProjectConfig
metadata:
  name: my-project
  namespace: my-project
spec:
  promotionPolicies:
  - stageSelector:
      name: automation-window-test
    autoPromotionEnabled: true
    promotionWindows:
    - name: allow-weekend
      kind: PromotionWindow

Evaluation

The evaluation of promotionWindows are as follows

// CheckPromotionWindows checks all defined promotion windows to determine if
// promotion is allowed at the current time. It follows these rules:
//
//  1. If no promotion windows are defined, promotions are allowed by default.
//  2. If a allow window is defined, the current time must fall within the allow windows for
//     promotion to be allowed.
//  3. If a deny window is defined, the current time must not fall within any deny windows for
//     promotion to be allowed.
//  4. If both a allow and deny window is active, the deny window takes precedence and
//     promotions are denied.
// 5. If both a allow and deny window are defined, but none are active, promotions are denied.

Considerations

  1. In the future, create ClusterPromotionWindow to enable re-use of typical windows (such as christmas, weekends, etc)

@LittaKake LittaKake requested review from a team as code owners December 29, 2025 17:56
@netlify
Copy link

netlify bot commented Dec 29, 2025

Deploy Preview for docs-kargo-io ready!

Name Link
🔨 Latest commit 1dddda1
🔍 Latest deploy log https://app.netlify.com/projects/docs-kargo-io/deploys/6952e7b25585b30008f02efc
😎 Deploy Preview https://deploy-preview-5544.docs.kargo.io
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@LittaKake LittaKake marked this pull request as draft December 29, 2025 17:57
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +105 to +111
loc, err := time.LoadLocation(promotionWindowSpec.TimeZone)
if err != nil {
return false, fmt.Errorf("unable to load time zone: %w", err)

Choose a reason for hiding this comment

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

P1 Badge Default to UTC when timeZone is omitted

checkPromotionWindow always calls time.LoadLocation(promotionWindowSpec.TimeZone) and treats a missing timeZone as an error, even though the CRD/docs describe the field as optional with a UTC default. Any PromotionWindow created without a timeZone now returns an error from CheckPromotionWindows, which bubbles up through autoPromotionAllowed and blocks Stage reconciliation/auto-promotion. Please default to UTC when the field is empty instead of erroring.

Useful? React with 👍 / 👎.

Copy link
Author

Choose a reason for hiding this comment

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

@LittaKake LittaKake marked this pull request as ready for review December 29, 2025 20:07
Signed-off-by: Kristoffer Fagerbekk <fagerbekk@hotmail.com>
Signed-off-by: Kristoffer Fagerbekk <kristoffer.fagerbekk@cognite.com>
@LittaKake LittaKake force-pushed the kake/promotionwindows/add branch from ca3f560 to 1dddda1 Compare December 29, 2025 20:42
@sstarcher
Copy link

Conceptually if you had auto promotion on and had a promotion window. If something was wrong with the release to prevent it from being promoted to the next env you would need to modify this CR and disable the window. Is that the correct structure you imagine?

@LittaKake
Copy link
Author

Conceptually if you had auto promotion on and had a promotion window. If something was wrong with the release to prevent it from being promoted to the next env you would need to modify this CR and disable the window. Is that the correct structure you imagine?

My intent isn't to have this CR used for adhoc disabling of autopromotion. If thats what you mean.

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.

2 participants