Skip to content

feat: introduce default version flags for Prometheus, Alertmanager and Thanos - #8651

Open
davidquan1 wants to merge 7 commits into
prometheus-operator:mainfrom
davidquan1:issue8641-add-default-version
Open

feat: introduce default version flags for Prometheus, Alertmanager and Thanos#8651
davidquan1 wants to merge 7 commits into
prometheus-operator:mainfrom
davidquan1:issue8641-add-default-version

Conversation

@davidquan1

@davidquan1 davidquan1 commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Description

Currently, the Prometheus Operator defaults to the latest stable version of operands (e.g., Prometheus v3.12.0) if .spec.version is omitted in the Custom Resource. This creates a "silent trap" for platform maintainers who use the -default-base-image flags to globally enforce specific, security-hardened LTS images (especially via digests).

In such cases, the Operator continues to render configuration based on its hardcoded bleeding-edge defaults. This leads to functional disconnects, such as generating invalid YAML schema (e.g., the storage.tsdb.retention field introduced in v3.11.0) for older LTS versions (like v3.5.4), causing operand pods to crash.

This PR introduces three new command-line flags to bridge this gap:

  • -prometheus-default-version
  • -alertmanager-default-version
  • -thanos-default-version
    These flags allow maintainers to explicitly sync the "assumed default version" with their "overridden default image," ensuring functional consistency by default when .spec.version is not defined in the Custom Resources.

Closes: #8641

Type of change

What type of changes does your code introduce to the Prometheus operator? Put an x in the box that apply.

  • CHANGE (fix or feature that would cause existing functionality to not work as expected)
  • FEATURE (non-breaking change which adds functionality)
  • BUGFIX (non-breaking change which fixes an issue)
  • ENHANCEMENT (non-breaking change which improves existing functionality)
  • NONE (if none of the other choices apply. Example, tooling, build system, CI, docs, etc.)

Verification

  • Added unit tests in pkg/prometheus/promcfg_test.go to verify that NewConfigGenerator respects the custom default version.
  • Added unit tests in pkg/alertmanager/statefulset_test.go and pkg/thanos/statefulset_test.go to ensure StatefulSet image paths and configuration logic use the provided default versions as fallbacks.
  • Verified that all new tests pass and existing functionality remains intact.

Changelog entry

[ENHANCEMENT] Introduce --prometheus-default-version, --alertmanager-default-version, and --thanos-default-version flags to explicitly define default fallback versions for configuration rendering and image building.

@davidquan1
davidquan1 requested a review from a team as a code owner June 25, 2026 03:17
@davidquan1
davidquan1 force-pushed the issue8641-add-default-version branch 2 times, most recently from 9e0c894 to 578989b Compare June 25, 2026 05:51
…n, and --thanos-default-version flags to the operator. These flags allow user to define the default version used for configuration rendering and image building when .spec.version is omitted in Custom Resources. This ensures functional consistency when using custom base images (e.g., security-hardened LTS images via digests) that differ from the operator's hardcoded defaults.

Signed-off-by: David Quan <david.quan@broadcom.com>
@davidquan1
davidquan1 force-pushed the issue8641-add-default-version branch from 578989b to 5bbf627 Compare June 25, 2026 06:02
@davidquan1

Copy link
Copy Markdown
Contributor Author

Hi @simonpasquier,

Could you please help review this PR? It implements the requested flags for setting default component versions (Prometheus, Alertmanager, and Thanos) in the operator.

Thanks!

Comment thread cmd/operator/main.go Outdated
Comment thread cmd/operator/main.go Outdated
Comment thread cmd/operator/main.go Outdated
Comment thread pkg/alertmanager/operator.go Outdated
Comment thread pkg/alertmanager/operator_test.go
Comment thread pkg/alertmanager/statefulset.go Outdated
Signed-off-by: David Quan <david.quan@broadcom.com>
Signed-off-by: David Quan <david.quan@broadcom.com>
@davidquan1
davidquan1 force-pushed the issue8641-add-default-version branch from 7b08880 to f577e7e Compare July 1, 2026 08:29
…mage is used

Signed-off-by: David Quan <david.quan@broadcom.com>
… empty config safely

Signed-off-by: David Quan <david.quan@broadcom.com>
Signed-off-by: David Quan <david.quan@broadcom.com>
@davidquan1
davidquan1 force-pushed the issue8641-add-default-version branch 2 times, most recently from f53cfb5 to 5ec0491 Compare July 1, 2026 11:07
Signed-off-by: David Quan <david.quan@broadcom.com>
@davidquan1
davidquan1 force-pushed the issue8641-add-default-version branch from 5ec0491 to 93dbb16 Compare July 1, 2026 11:15
@davidquan1

Copy link
Copy Markdown
Contributor Author

Hi @simonpasquier,

All comments have been addressed. Here is a summary of the changes:

  • Help Text: Clarified the help text for the new default version flags as requested.
  • Redundant Logic: Removed the redundant assignments in the bootstrap function.
  • Tests & Fallback Logic: I initially reverted the test changes as suggested. However, doing so caused several unit tests (such as TestProvisionAlertmanagerConfiguration) to fail with: strconv.ParseUint: parsing "": invalid syntax.
    This happened because in the unit test context, the CLI flags are not evaluated, leaving the config version as an empty string. To address this gracefully without inflating the test code, I improved the fallback logic in the production code (e.g., in pkg/alertmanager/operator.go). It now safely falls back to operator.DefaultAlertmanagerVersion if both Spec.Version and the CLI config flag are empty. This makes the production code more robust against uninitialized configurations while keeping our test changes to a bare minimum.
  • Upstream Sync: I've also merged the latest upstream/main to resolve conflicts and ensured that no upstream test cases were accidentally dropped during the process.

The PR is now ready for another look. Could you please review it again when you have a moment? Thank you!

@davidquan1
davidquan1 requested a review from simonpasquier July 1, 2026 11:59
@davidquan1

Copy link
Copy Markdown
Contributor Author

Hi @simonpasquier,
Could you please help review this again ? Thanks.

@davidquan1

Copy link
Copy Markdown
Contributor Author

Hi @simonpasquier,
Could you please help review this? Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

v0.92.0 generates invalid YAML for Prometheus v3: "field retention not found in type config.plain"

2 participants