Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace UpdateStatus() for ApplyStatus ThanosRuler #5913

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 2 additions & 6 deletions pkg/alertmanager/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ import (
)

const (
resyncPeriod = 5 * time.Minute
prometheusOperatorFieldManager = "PrometheusOperator"
resyncPeriod = 5 * time.Minute
)

var (
Expand Down Expand Up @@ -806,9 +805,7 @@ func (c *Operator) UpdateStatus(ctx context.Context, key string) error {
a.Status.Conditions = operator.UpdateConditions(a.Status.Conditions, availableCondition, reconciledCondition)
a.Status.Paused = a.Spec.Paused

aac := ApplyConfigurationFromAlertmanager(a)

if _, err = c.mclient.MonitoringV1().Alertmanagers(a.Namespace).ApplyStatus(ctx, aac, metav1.ApplyOptions{FieldManager: prometheusOperatorFieldManager, Force: true}); err != nil {
if _, err = c.mclient.MonitoringV1().Alertmanagers(a.Namespace).ApplyStatus(ctx, ApplyConfigurationFromAlertmanager(a), metav1.ApplyOptions{FieldManager: operator.PrometheusOperatorFieldManager, Force: true}); err != nil {
return errors.Wrap(err, "failed to apply status subresource")
}

Expand Down Expand Up @@ -1793,7 +1790,6 @@ func tlsAssetsSecretName(name string) string {

func ApplyConfigurationFromAlertmanager(a *monitoringv1.Alertmanager) *monitoringv1ac.AlertmanagerApplyConfiguration {
asac := monitoringv1ac.AlertmanagerStatus().
WithPaused(a.Status.Paused).
WithPaused(a.Status.Paused).
WithReplicas(a.Status.Replicas).
WithAvailableReplicas(a.Status.AvailableReplicas).
Expand Down
2 changes: 2 additions & 0 deletions pkg/operator/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ import (
monitoringv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
)

const PrometheusOperatorFieldManager = "PrometheusOperator"

var (
syncsDesc = prometheus.NewDesc(
"prometheus_operator_syncs",
Expand Down
29 changes: 26 additions & 3 deletions pkg/thanos/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
"k8s.io/client-go/tools/cache"

monitoringv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
monitoringv1ac "github.com/prometheus-operator/prometheus-operator/pkg/client/applyconfiguration/monitoring/v1"
monitoringclient "github.com/prometheus-operator/prometheus-operator/pkg/client/versioned"
"github.com/prometheus-operator/prometheus-operator/pkg/informers"
"github.com/prometheus-operator/prometheus-operator/pkg/k8sutil"
Expand Down Expand Up @@ -689,11 +690,10 @@ func (o *Operator) UpdateStatus(ctx context.Context, key string) error {
availableCondition := stsReporter.Update(tr)
reconciledCondition := o.reconciliations.GetCondition(key, tr.Generation)
tr.Status.Conditions = operator.UpdateConditions(tr.Status.Conditions, availableCondition, reconciledCondition)

tr.Status.Paused = tr.Spec.Paused

if _, err = o.mclient.MonitoringV1().ThanosRulers(tr.Namespace).UpdateStatus(ctx, tr, metav1.UpdateOptions{}); err != nil {
return errors.Wrap(err, "failed to update status subresource")
if _, err = o.mclient.MonitoringV1().ThanosRulers(tr.Namespace).ApplyStatus(ctx, applyConfigurationFromThanosRuler(tr), metav1.ApplyOptions{FieldManager: operator.PrometheusOperatorFieldManager, Force: true}); err != nil {
return errors.Wrap(err, "failed to apply status subresource")
}

return nil
Expand Down Expand Up @@ -803,3 +803,26 @@ func (o *Operator) enqueueForNamespace(store cache.Store, nsName string) {
)
}
}

func applyConfigurationFromThanosRuler(a *monitoringv1.ThanosRuler) *monitoringv1ac.ThanosRulerApplyConfiguration {
trac := monitoringv1ac.ThanosRulerStatus().
WithPaused(a.Status.Paused).
WithReplicas(a.Status.Replicas).
WithAvailableReplicas(a.Status.AvailableReplicas).
WithUpdatedReplicas(a.Status.UpdatedReplicas).
WithUnavailableReplicas(a.Status.UnavailableReplicas)

for _, condition := range a.Status.Conditions {
trac.WithConditions(
Copy link
Contributor

Choose a reason for hiding this comment

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

(suggestion) this can be extracted to pkg/operator/operator.go (or a new pkg/operator/applyconfiguration.go) and shared with Alertmanager.

monitoringv1ac.Condition().
WithType(condition.Type).
WithStatus(condition.Status).
WithLastTransitionTime(condition.LastTransitionTime).
WithReason(condition.Reason).
WithMessage(condition.Message).
WithObservedGeneration(condition.ObservedGeneration),
)
}

return monitoringv1ac.ThanosRuler(a.Name, a.Namespace).WithStatus(trac)
}