Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Allow the operator to wait for CRDs to be installed#8551

Draft
haanhvu wants to merge 3 commits intoprometheus-operator:mainprometheus-operator/prometheus-operator:mainfrom
haanhvu:issue7459haanhvu/prometheus-operator:issue7459Copy head branch name to clipboard
Draft

Allow the operator to wait for CRDs to be installed#8551
haanhvu wants to merge 3 commits intoprometheus-operator:mainprometheus-operator/prometheus-operator:mainfrom
haanhvu:issue7459haanhvu/prometheus-operator:issue7459Copy head branch name to clipboard

Conversation

@haanhvu
Copy link
Copy Markdown
Contributor

@haanhvu haanhvu commented May 1, 2026

Description

Closes: #7459

This PR add flags that users can use to set the waiting time for CRDs to be installed. --crds-wait-to-be-installed sets the CRDs to wait for. --crd-installed-waiting-time sets the waiting time during which the operator checks every second whether the CRDs are installed. Both flags need to be set together.

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

Unit tests for:

  • Setting flag values
  • The operator waits and checks for CRDs installed until timeout

Changelog entry

Allow the operator to wait for CRDs to be installed

Signed-off-by: haanhvu <haanhvu888@gmail.com>
@haanhvu haanhvu requested a review from a team as a code owner May 1, 2026 09:07
@haanhvu haanhvu marked this pull request as draft May 1, 2026 09:13
haanhvu added 2 commits May 5, 2026 15:36
Signed-off-by: haanhvu <haanhvu888@gmail.com>
Signed-off-by: haanhvu <haanhvu888@gmail.com>
Copy link
Copy Markdown
Contributor

@simonpasquier simonpasquier left a comment

Choose a reason for hiding this comment

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

Thanks for tackling this!

Comment thread cmd/operator/main.go
fs.Float64Var(&memlimitRatio, "auto-gomemlimit-ratio", defaultMemlimitRatio, "The ratio of reserved GOMEMLIMIT memory to the detected maximum container or system memory. The value should be greater than 0.0 and less than 1.0. Default: 0.0 (disabled).")
fs.BoolVar(&disableUnmanagedPrometheusConfiguration, "disable-unmanaged-prometheus-configuration", false, "Disable support for unmanaged Prometheus configuration when all resource selectors are nil. As stated in the API documentation, unmanaged Prometheus configuration is a deprecated feature which can be avoided with '.spec.additionalScrapeConfigs' or the ScrapeConfig CRD. Default: false.")
fs.DurationVar(&crdInstalledWaitingTime, "crd-installed-waiting-time", 0, "The waiting time for a CRD to be installed. During this time, the operator checks every second whether the CRD is installed. Need to be set together with --crds-wait-to-be-installed for the operator to know what CRDs to wait for.")
fs.Var(&crdsWaitToBeInstalled, "crds-wait-to-be-installed", "CRDs that the operator will wait to be installed. Valid values are storageclass, scrapeconfig, prometheus, prometheusagent, alertmanager, thanosruler. Need to be set with crd-installed-waiting-time so that the operator knows how long to wait for.")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'd remove storageclass since it's not managed by the operator. We should also add servicemonitor, podmonitor and probe (or remove scrapeconfigs if we want to limit ourselves to workload resources). I'm not sure we should use the singular or plural form or the CamelCase form.
Also the operator can have a default timeout value.

Suggested change
fs.Var(&crdsWaitToBeInstalled, "crds-wait-to-be-installed", "CRDs that the operator will wait to be installed. Valid values are storageclass, scrapeconfig, prometheus, prometheusagent, alertmanager, thanosruler. Need to be set with crd-installed-waiting-time so that the operator knows how long to wait for.")
fs.Var(&crdsWaitToBeInstalled, "check-for-crds-on-startup", "Comma-separated list of Custom Resource Definitions that should be present in the cluster and which the operator should have access to. By default, no check is performed. Valid values are scrapeconfigs, prometheuses, prometheusagents, alertmanagers, thanosrulers.")

Comment thread cmd/operator/main.go

fs.Float64Var(&memlimitRatio, "auto-gomemlimit-ratio", defaultMemlimitRatio, "The ratio of reserved GOMEMLIMIT memory to the detected maximum container or system memory. The value should be greater than 0.0 and less than 1.0. Default: 0.0 (disabled).")
fs.BoolVar(&disableUnmanagedPrometheusConfiguration, "disable-unmanaged-prometheus-configuration", false, "Disable support for unmanaged Prometheus configuration when all resource selectors are nil. As stated in the API documentation, unmanaged Prometheus configuration is a deprecated feature which can be avoided with '.spec.additionalScrapeConfigs' or the ScrapeConfig CRD. Default: false.")
fs.DurationVar(&crdInstalledWaitingTime, "crd-installed-waiting-time", 0, "The waiting time for a CRD to be installed. During this time, the operator checks every second whether the CRD is installed. Need to be set together with --crds-wait-to-be-installed for the operator to know what CRDs to wait for.")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
fs.DurationVar(&crdInstalledWaitingTime, "crd-installed-waiting-time", 0, "The waiting time for a CRD to be installed. During this time, the operator checks every second whether the CRD is installed. Need to be set together with --crds-wait-to-be-installed for the operator to know what CRDs to wait for.")
fs.DurationVar(&crdInstalledWaitingTime, "check-for-crds-on-startup-timeout", time.Minute, "How long the operator will wait for Custom Resource Definitions to be present on startup before exiting with error. Only relevant when --check-for-crds-on-startup is defined.")

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

By time.Minute, you want to set the default value to 1min? Why 1min here? I thought that not all users need this feature, so I set the default value as 0. (0 means no wait, but the operator still checks once.)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Indeed it works for me too. I was thinking about the original issue report but I agree that exiting early if the crds aren't present is also fine (the container will keep restarting until the CRDs are present).

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.

Prometheus Operator Should Retry CRD Detection if Not Found

2 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.