mirror of
https://github.com/coreos/prometheus-operator.git
synced 2026-02-05 06:45:27 +01:00
Merge pull request #8236 from Arpit529Srivastava/feat-issue-5681
feat: report deprecated field usage in reconciled condition
This commit is contained in:
@@ -598,7 +598,7 @@ func (c *Operator) sync(ctx context.Context, key string) error {
|
||||
}
|
||||
|
||||
logger := c.logger.With("key", key)
|
||||
logDeprecatedFields(logger, am)
|
||||
c.recordDeprecatedFields(key, logger, am)
|
||||
|
||||
logger.Info("sync alertmanager")
|
||||
|
||||
@@ -1866,19 +1866,27 @@ func (c *Operator) createOrUpdateClusterTLSConfigSecret(ctx context.Context, a *
|
||||
return nil
|
||||
}
|
||||
|
||||
func logDeprecatedFields(logger *slog.Logger, a *monitoringv1.Alertmanager) {
|
||||
func (c *Operator) recordDeprecatedFields(key string, logger *slog.Logger, a *monitoringv1.Alertmanager) {
|
||||
deprecationWarningf := "field %q is deprecated, field %q should be used instead"
|
||||
var deprecations []string
|
||||
|
||||
if a.Spec.BaseImage != "" {
|
||||
logger.Warn(fmt.Sprintf(deprecationWarningf, "spec.baseImage", "spec.image"))
|
||||
deprecations = append(deprecations, fmt.Sprintf(deprecationWarningf, "spec.baseImage", "spec.image"))
|
||||
}
|
||||
|
||||
if a.Spec.Tag != "" {
|
||||
logger.Warn(fmt.Sprintf(deprecationWarningf, "spec.tag", "spec.image"))
|
||||
deprecations = append(deprecations, fmt.Sprintf(deprecationWarningf, "spec.tag", "spec.image"))
|
||||
}
|
||||
|
||||
if a.Spec.SHA != "" {
|
||||
logger.Warn(fmt.Sprintf(deprecationWarningf, "spec.sha", "spec.image"))
|
||||
deprecations = append(deprecations, fmt.Sprintf(deprecationWarningf, "spec.sha", "spec.image"))
|
||||
}
|
||||
|
||||
if len(deprecations) > 0 {
|
||||
for _, m := range deprecations {
|
||||
logger.Warn(m)
|
||||
}
|
||||
c.reconciliations.SetReasonAndMessage(key, operator.DeprecatedFieldsInUseReason, strings.Join(deprecations, "; "))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -27,6 +27,10 @@ const (
|
||||
// NoSelectedResourcesReason is used in status conditions to indicate that
|
||||
// a workload resource selected no configuration resources.
|
||||
NoSelectedResourcesReason = "NoSelectedResources"
|
||||
|
||||
// DeprecatedFieldsInUseReason is used in status conditions to indicate that
|
||||
// the resource uses deprecated fields.
|
||||
DeprecatedFieldsInUseReason = "DeprecatedFieldsInUse"
|
||||
)
|
||||
|
||||
type StatusReconciler interface {
|
||||
|
||||
@@ -58,7 +58,7 @@ const (
|
||||
noSelectedResourcesMessage = "No ServiceMonitor, PodMonitor, Probe, ScrapeConfig, and PrometheusRule have been selected."
|
||||
|
||||
unmanagedConfigurationReason = "ConfigurationUnmanaged"
|
||||
unmanagedConfigurationMessage = "the operator doesn't manage the Prometheus configuration secret because neither serviceMonitorSelector nor podMonitorSelector, nor probeSelector, nor scrapeConfigSelector is specified. Unmanaged Prometheus configuration is deprecated, use additionalScrapeConfigs or the ScrapeConfig Custom Resource Definition instead."
|
||||
unmanagedConfigurationMessage = "the operator doesn't manage the Prometheus configuration secret because neither serviceMonitorSelector nor podMonitorSelector, nor probeSelector, nor scrapeConfigSelector is specified. Unmanaged Prometheus configuration is deprecated, use additionalScrapeConfigs or the ScrapeConfig Custom Resource Definition instead. Unmanaged Prometheus configuration can also be disabled from the operator's command-line (check './operator --help')."
|
||||
)
|
||||
|
||||
// Operator manages the life cycle of Prometheus deployments and
|
||||
@@ -833,7 +833,7 @@ func (c *Operator) sync(ctx context.Context, key string) error {
|
||||
}
|
||||
|
||||
logger := c.logger.With("key", key)
|
||||
c.logDeprecatedFields(logger, p)
|
||||
c.recordDeprecatedFields(key, logger, p)
|
||||
|
||||
statusCleanup := func() error {
|
||||
return c.configResStatusCleanup(ctx, p)
|
||||
@@ -1225,45 +1225,53 @@ func (c *Operator) UpdateStatus(ctx context.Context, key string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Operator) logDeprecatedFields(logger *slog.Logger, p *monitoringv1.Prometheus) {
|
||||
func (c *Operator) recordDeprecatedFields(key string, logger *slog.Logger, p *monitoringv1.Prometheus) {
|
||||
deprecationWarningf := "field %q is deprecated, field %q should be used instead"
|
||||
var deprecations []string
|
||||
|
||||
//nolint:staticcheck // Ignore SA1019 this field is marked as deprecated.
|
||||
if p.Spec.BaseImage != "" {
|
||||
logger.Warn(fmt.Sprintf(deprecationWarningf, "spec.baseImage", "spec.image"))
|
||||
deprecations = append(deprecations, fmt.Sprintf(deprecationWarningf, "spec.baseImage", "spec.image"))
|
||||
}
|
||||
|
||||
//nolint:staticcheck // Ignore SA1019 this field is marked as deprecated.
|
||||
if p.Spec.Tag != "" {
|
||||
logger.Warn(fmt.Sprintf(deprecationWarningf, "spec.tag", "spec.image"))
|
||||
deprecations = append(deprecations, fmt.Sprintf(deprecationWarningf, "spec.tag", "spec.image"))
|
||||
}
|
||||
|
||||
//nolint:staticcheck // Ignore SA1019 this field is marked as deprecated.
|
||||
if p.Spec.SHA != "" {
|
||||
logger.Warn(fmt.Sprintf(deprecationWarningf, "spec.sha", "spec.image"))
|
||||
deprecations = append(deprecations, fmt.Sprintf(deprecationWarningf, "spec.sha", "spec.image"))
|
||||
}
|
||||
|
||||
if p.Spec.Thanos != nil {
|
||||
//nolint:staticcheck // Ignore SA1019 this field is marked as deprecated.
|
||||
if p.Spec.BaseImage != "" {
|
||||
logger.Warn(fmt.Sprintf(deprecationWarningf, "spec.thanos.baseImage", "spec.thanos.image"))
|
||||
if p.Spec.Thanos.BaseImage != nil && *p.Spec.Thanos.BaseImage != "" {
|
||||
deprecations = append(deprecations, fmt.Sprintf(deprecationWarningf, "spec.thanos.baseImage", "spec.thanos.image"))
|
||||
}
|
||||
|
||||
//nolint:staticcheck // Ignore SA1019 this field is marked as deprecated.
|
||||
if p.Spec.Tag != "" {
|
||||
logger.Warn(fmt.Sprintf(deprecationWarningf, "spec.thanos.tag", "spec.thanos.image"))
|
||||
if p.Spec.Thanos.Tag != nil && *p.Spec.Thanos.Tag != "" {
|
||||
deprecations = append(deprecations, fmt.Sprintf(deprecationWarningf, "spec.thanos.tag", "spec.thanos.image"))
|
||||
}
|
||||
|
||||
//nolint:staticcheck // Ignore SA1019 this field is marked as deprecated.
|
||||
if p.Spec.SHA != "" {
|
||||
logger.Warn(fmt.Sprintf(deprecationWarningf, "spec.thanos.sha", "spec.thanos.image"))
|
||||
if p.Spec.Thanos.SHA != nil && *p.Spec.Thanos.SHA != "" {
|
||||
deprecations = append(deprecations, fmt.Sprintf(deprecationWarningf, "spec.thanos.sha", "spec.thanos.image"))
|
||||
}
|
||||
}
|
||||
|
||||
if len(deprecations) > 0 {
|
||||
for _, m := range deprecations {
|
||||
logger.Warn(m)
|
||||
}
|
||||
c.reconciliations.SetReasonAndMessage(key, operator.DeprecatedFieldsInUseReason, strings.Join(deprecations, "; "))
|
||||
return
|
||||
}
|
||||
|
||||
if c.unmanagedPrometheusConfiguration(p) {
|
||||
logger.Warn("the operator doesn't manage the Prometheus configuration secret because neither serviceMonitorSelector nor podMonitorSelector, nor probeSelector is specified")
|
||||
logger.Warn("unmanaged Prometheus configuration is deprecated, use additionalScrapeConfigs or the ScrapeConfig instead")
|
||||
logger.Warn("unmanaged Prometheus configuration can also be disabled from the operator's command-line (check './operator --help')")
|
||||
logger.Warn(unmanagedConfigurationMessage)
|
||||
c.reconciliations.SetReasonAndMessage(key, unmanagedConfigurationReason, unmanagedConfigurationMessage)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1363,7 +1371,6 @@ func (c *Operator) createOrUpdateConfigurationSecret(ctx context.Context, logger
|
||||
// wants to manage configuration themselves. Let's create an empty Secret
|
||||
// if it doesn't exist.
|
||||
if c.unmanagedPrometheusConfiguration(p) {
|
||||
c.reconciliations.SetReasonAndMessage(operator.KeyForObject(p), unmanagedConfigurationReason, unmanagedConfigurationMessage)
|
||||
|
||||
s, err := prompkg.MakeConfigurationSecret(p, c.config, nil)
|
||||
if err != nil {
|
||||
|
||||
@@ -512,6 +512,8 @@ func (o *Operator) sync(ctx context.Context, key string) error {
|
||||
|
||||
logger.Info("sync thanos-ruler")
|
||||
|
||||
o.recordDeprecatedFields(key, logger, tr)
|
||||
|
||||
if err := operator.CheckStorageClass(ctx, o.canReadStorageClass, o.kclient, tr.Spec.Storage); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -617,6 +619,23 @@ func (o *Operator) sync(ctx context.Context, key string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *Operator) recordDeprecatedFields(key string, logger *slog.Logger, tr *monitoringv1.ThanosRuler) {
|
||||
deprecationWarningf := "field %q is deprecated, field %q should be used instead"
|
||||
var deprecations []string
|
||||
|
||||
//nolint:staticcheck // Ignore SA1019 this field is marked as deprecated.
|
||||
if len(tr.Spec.PrometheusRulesExcludedFromEnforce) > 0 {
|
||||
deprecations = append(deprecations, fmt.Sprintf(deprecationWarningf, "spec.prometheusRulesExcludedFromEnforce", "spec.excludedFromEnforcement"))
|
||||
}
|
||||
|
||||
if len(deprecations) > 0 {
|
||||
for _, m := range deprecations {
|
||||
logger.Warn(m)
|
||||
}
|
||||
o.reconciliations.SetReasonAndMessage(key, operator.DeprecatedFieldsInUseReason, strings.Join(deprecations, "; "))
|
||||
}
|
||||
}
|
||||
|
||||
// updateConfigResourcesStatus updates the status of the selected configuration
|
||||
// resources (PrometheusRules).
|
||||
func (o *Operator) updateConfigResourcesStatus(ctx context.Context, tr *monitoringv1.ThanosRuler, rules operator.PrometheusRuleSelection) error {
|
||||
|
||||
Reference in New Issue
Block a user