Skip to content

Commit 1fdde89

Browse files
authored
Revert "Include prometheus and alertmanager status in monitor status (tigera#4214)" (tigera#4273)
This reverts commit 6e55cb7.
1 parent 2b6f346 commit 1fdde89

3 files changed

Lines changed: 1 addition & 173 deletions

File tree

pkg/controller/monitor/monitor_controller.go

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222

2323
crdv1 "github.com/tigera/operator/pkg/apis/crd.projectcalico.org/v1"
2424

25-
monitoringv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
2625
corev1 "k8s.io/api/core/v1"
2726
"k8s.io/apimachinery/pkg/api/errors"
2827
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -357,48 +356,6 @@ func (r *ReconcileMonitor) Reconcile(ctx context.Context, request reconcile.Requ
357356
includeV3NetworkPolicy = true
358357
}
359358

360-
p, err := utils.GetPrometheus(ctx, r.client)
361-
if err != nil {
362-
r.status.SetDegraded(operatorv1.ResourceReadError, "An error occurred trying to retrieve the Prometheus status", err, reqLogger)
363-
return reconcile.Result{}, err
364-
}
365-
366-
if p != nil {
367-
available := monitoringv1.ConditionFalse
368-
369-
for _, cond := range p.Status.Conditions {
370-
if cond.Type == monitoringv1.Available {
371-
available = cond.Status
372-
}
373-
}
374-
375-
if available != monitoringv1.ConditionTrue {
376-
r.status.SetDegraded(operatorv1.ResourceNotReady, "Prometheus component is not available", err, reqLogger)
377-
return reconcile.Result{}, err
378-
}
379-
}
380-
381-
am, err := utils.GetAlertmanager(ctx, r.client)
382-
if err != nil {
383-
r.status.SetDegraded(operatorv1.ResourceReadError, "An error occurred trying to retrieve the Alertmanager status", err, reqLogger)
384-
return reconcile.Result{}, err
385-
}
386-
387-
if am != nil {
388-
available := monitoringv1.ConditionFalse
389-
390-
for _, cond := range am.Status.Conditions {
391-
if cond.Type == monitoringv1.Available {
392-
available = cond.Status
393-
}
394-
}
395-
396-
if available != monitoringv1.ConditionTrue {
397-
r.status.SetDegraded(operatorv1.ResourceNotReady, "Alertmanager component is not available", err, reqLogger)
398-
return reconcile.Result{}, err
399-
}
400-
}
401-
402359
// Create a component handler to manage the rendered component.
403360
hdler := utils.NewComponentHandler(log, r.client, r.scheme, instance)
404361

pkg/controller/monitor/monitor_controller_test.go

Lines changed: 1 addition & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2021-2025 Tigera, Inc. All rights reserved.
1+
// Copyright (c) 2021-2024 Tigera, Inc. All rights reserved.
22

33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -68,7 +68,6 @@ var _ = Describe("Monitor controller tests", func() {
6868
Expect(apis.AddToScheme(scheme)).NotTo(HaveOccurred())
6969
Expect(appsv1.SchemeBuilder.AddToScheme(scheme)).NotTo(HaveOccurred())
7070
Expect(rbacv1.SchemeBuilder.AddToScheme(scheme)).NotTo(HaveOccurred())
71-
Expect(monitoringv1.AddToScheme(scheme)).NotTo(HaveOccurred())
7271

7372
// Create a client that will have a crud interface of k8s objects.
7473
ctx = context.Background()
@@ -86,7 +85,6 @@ var _ = Describe("Monitor controller tests", func() {
8685
mockStatus.On("ReadyToMonitor")
8786
mockStatus.On("RemoveDeployments", mock.Anything)
8887
mockStatus.On("RemoveCertificateSigningRequests", common.TigeraPrometheusNamespace)
89-
mockStatus.On("SetDegraded", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return()
9088
mockStatus.On("SetMetaData", mock.Anything).Return()
9189

9290
// Create an object we can use throughout the test to do the monitor reconcile loops.
@@ -137,107 +135,6 @@ var _ = Describe("Monitor controller tests", func() {
137135
r.tierWatchReady.MarkAsReady()
138136
})
139137

140-
Context("prometheus resources", func() {
141-
BeforeEach(func() {
142-
// Add the Prometheus and Alertmanager instances
143-
prom := &monitoringv1.Prometheus{
144-
ObjectMeta: metav1.ObjectMeta{
145-
Name: monitor.CalicoNodePrometheus,
146-
Namespace: common.TigeraPrometheusNamespace,
147-
},
148-
Status: monitoringv1.PrometheusStatus{
149-
Conditions: []monitoringv1.Condition{
150-
{
151-
Type: monitoringv1.Available,
152-
Status: monitoringv1.ConditionTrue,
153-
},
154-
{
155-
Type: monitoringv1.Reconciled,
156-
Status: monitoringv1.ConditionTrue,
157-
},
158-
},
159-
},
160-
}
161-
Expect(cli.Create(ctx, prom)).To(BeNil())
162-
163-
alertManager := &monitoringv1.Alertmanager{
164-
ObjectMeta: metav1.ObjectMeta{
165-
Name: monitor.CalicoNodeAlertmanager,
166-
Namespace: common.TigeraPrometheusNamespace,
167-
},
168-
Status: monitoringv1.AlertmanagerStatus{
169-
Conditions: []monitoringv1.Condition{
170-
{
171-
Type: monitoringv1.Available,
172-
Status: monitoringv1.ConditionTrue,
173-
},
174-
{
175-
Type: monitoringv1.Reconciled,
176-
Status: monitoringv1.ConditionTrue,
177-
},
178-
},
179-
},
180-
}
181-
Expect(cli.Create(ctx, alertManager)).To(BeNil())
182-
})
183-
184-
It("should degrade if the prometheus statefulset isn't ready", func() {
185-
prom := &monitoringv1.Prometheus{}
186-
Expect(cli.Get(ctx, client.ObjectKey{Name: monitor.CalicoNodePrometheus, Namespace: common.TigeraPrometheusNamespace}, prom)).NotTo(HaveOccurred())
187-
188-
patch := client.MergeFrom(prom.DeepCopy())
189-
prom.Status.Conditions = []monitoringv1.Condition{
190-
{
191-
Type: monitoringv1.Available,
192-
Status: monitoringv1.ConditionFalse,
193-
},
194-
{
195-
Type: monitoringv1.Reconciled,
196-
Status: monitoringv1.ConditionTrue,
197-
},
198-
}
199-
Expect(cli.Patch(ctx, prom, patch)).To(Succeed())
200-
201-
_, err := r.Reconcile(ctx, reconcile.Request{})
202-
Expect(err).ShouldNot(HaveOccurred())
203-
204-
mockStatus.AssertCalled(GinkgoT(), "SetDegraded",
205-
operatorv1.ResourceNotReady,
206-
"Prometheus component is not available",
207-
mock.Anything,
208-
mock.Anything,
209-
)
210-
})
211-
212-
It("should degrade if the alertmanager statefulset isn't ready", func() {
213-
alertManager := &monitoringv1.Alertmanager{}
214-
Expect(cli.Get(ctx, client.ObjectKey{Name: monitor.CalicoNodeAlertmanager, Namespace: common.TigeraPrometheusNamespace}, alertManager)).NotTo(HaveOccurred())
215-
216-
patch := client.MergeFrom(alertManager.DeepCopy())
217-
alertManager.Status.Conditions = []monitoringv1.Condition{
218-
{
219-
Type: monitoringv1.Available,
220-
Status: monitoringv1.ConditionFalse,
221-
},
222-
{
223-
Type: monitoringv1.Reconciled,
224-
Status: monitoringv1.ConditionTrue,
225-
},
226-
}
227-
Expect(cli.Patch(ctx, alertManager, patch)).To(Succeed())
228-
229-
_, err := r.Reconcile(ctx, reconcile.Request{})
230-
Expect(err).ShouldNot(HaveOccurred())
231-
232-
mockStatus.AssertCalled(GinkgoT(), "SetDegraded",
233-
operatorv1.ResourceNotReady,
234-
"Alertmanager component is not available",
235-
mock.Anything,
236-
mock.Anything,
237-
)
238-
})
239-
})
240-
241138
Context("controller reconciliation", func() {
242139
var (
243140
am = &monitoringv1.Alertmanager{}

pkg/controller/utils/utils.go

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import (
2424

2525
esv1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/elasticsearch/v1"
2626
"github.com/elastic/cloud-on-k8s/v2/pkg/utils/stringsutil"
27-
monitoringv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
2827
csiv1 "sigs.k8s.io/secrets-store-csi-driver/apis/v1"
2928

3029
"github.com/go-logr/logr"
@@ -58,7 +57,6 @@ import (
5857
"github.com/tigera/operator/pkg/ctrlruntime"
5958
"github.com/tigera/operator/pkg/render"
6059
"github.com/tigera/operator/pkg/render/logstorage/eck"
61-
"github.com/tigera/operator/pkg/render/monitor"
6260
)
6361

6462
const (
@@ -860,30 +858,6 @@ func GetElasticsearch(ctx context.Context, c client.Client) (*esv1.Elasticsearch
860858
return &es, nil
861859
}
862860

863-
func GetAlertmanager(ctx context.Context, c client.Client) (*monitoringv1.Alertmanager, error) {
864-
a := monitoringv1.Alertmanager{}
865-
err := c.Get(ctx, client.ObjectKey{Name: monitor.CalicoNodeAlertmanager, Namespace: common.TigeraPrometheusNamespace}, &a)
866-
if err != nil {
867-
if errors.IsNotFound(err) {
868-
return nil, nil
869-
}
870-
return nil, err
871-
}
872-
return &a, nil
873-
}
874-
875-
func GetPrometheus(ctx context.Context, c client.Client) (*monitoringv1.Prometheus, error) {
876-
p := monitoringv1.Prometheus{}
877-
err := c.Get(ctx, client.ObjectKey{Name: monitor.CalicoNodePrometheus, Namespace: common.TigeraPrometheusNamespace}, &p)
878-
if err != nil {
879-
if errors.IsNotFound(err) {
880-
return nil, nil
881-
}
882-
return nil, err
883-
}
884-
return &p, nil
885-
}
886-
887861
// AddKubeProxyWatch creates a watch on the kube-proxy DaemonSet.
888862
func AddKubeProxyWatch(c ctrlruntime.Controller) error {
889863
ds := &appsv1.DaemonSet{

0 commit comments

Comments
 (0)