Skip to content

Commit 305bb6d

Browse files
fix unit tests and remove comments
1 parent f226c77 commit 305bb6d

File tree

2 files changed

+126
-180
lines changed

2 files changed

+126
-180
lines changed

controllers/monitor.go

Lines changed: 0 additions & 164 deletions
Original file line numberDiff line numberDiff line change
@@ -13,98 +13,6 @@ import (
1313
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
1414
)
1515

16-
//func (r *DPAReconciler) ReconcileServiceMonitor(log logr.Logger) (bool, error) {
17-
//
18-
// dpa := oadpv1alpha1.DataProtectionApplication{}
19-
// if err := r.Get(r.Context, r.NamespacedName, &dpa); err != nil {
20-
// return false, err
21-
// }
22-
//
23-
// serviceMonitor := &monitor.ServiceMonitor{
24-
// ObjectMeta: metav1.ObjectMeta{
25-
// Name: "oadp-operator",
26-
// Namespace: r.NamespacedName.Namespace,
27-
// },
28-
// }
29-
//
30-
// op, err := controllerutil.CreateOrUpdate(r.Context, r.Client, serviceMonitor, func() error {
31-
//
32-
// if serviceMonitor.ObjectMeta.CreationTimestamp.IsZero() {
33-
// serviceMonitor.Spec.Selector = metav1.LabelSelector{
34-
// MatchLabels: map[string]string{
35-
// oadpv1alpha1.OadpOperatorLabel: "true",
36-
// "app": "oadp-operator",
37-
// },
38-
// }
39-
// }
40-
//
41-
// // update service monitor
42-
// return r.buildServiceMonitor(serviceMonitor, &dpa)
43-
// })
44-
//
45-
// if err != nil {
46-
// return false, err
47-
// }
48-
//
49-
// //TODO: Review service monitor status and report errors and conditions
50-
//
51-
// if op == controllerutil.OperationResultCreated || op == controllerutil.OperationResultUpdated {
52-
// // Trigger event to indicate service monitor was created or updated
53-
// r.EventRecorder.Event(serviceMonitor,
54-
// corev1.EventTypeNormal,
55-
// "ServiceMonitorReconciled",
56-
// fmt.Sprintf("performed %s on service monitor %s/%s", op, serviceMonitor.Namespace, serviceMonitor.Name),
57-
// )
58-
// }
59-
// return true, nil
60-
//}
61-
//
62-
//func (r *DPAReconciler) buildServiceMonitor(serviceMonitor *monitor.ServiceMonitor, dpa *oadpv1alpha1.DataProtectionApplication) error {
63-
//
64-
// if dpa == nil {
65-
// return fmt.Errorf("dpa CR cannot be nil")
66-
// }
67-
//
68-
// if serviceMonitor == nil {
69-
// return fmt.Errorf("service monitor cannot be nil")
70-
// }
71-
//
72-
// // Setting controller owner reference on the service monitor
73-
// err := controllerutil.SetControllerReference(dpa, serviceMonitor, r.Scheme)
74-
// if err != nil {
75-
// return err
76-
// }
77-
//
78-
// serviceMonitor.Spec.Selector = metav1.LabelSelector{
79-
// MatchLabels: map[string]string{
80-
// oadpv1alpha1.OadpOperatorLabel: "true",
81-
// "app": "oadp-operator",
82-
// },
83-
// }
84-
//
85-
// serviceMonitor.Labels = map[string]string{
86-
// oadpv1alpha1.OadpOperatorLabel: "true",
87-
// "app": "oadp-operator",
88-
// }
89-
//
90-
// serviceMonitor.Spec.Endpoints = []monitor.Endpoint{
91-
// {
92-
// Interval: "30s",
93-
// Port: "metrics",
94-
// },
95-
// }
96-
//
97-
// serviceMonitor.Spec.JobLabel = "app"
98-
//
99-
// serviceMonitor.Spec.NamespaceSelector = monitor.NamespaceSelector{
100-
// MatchNames: []string{
101-
// dpa.Namespace,
102-
// },
103-
// }
104-
//
105-
// return nil
106-
//}
107-
10816
func (r *DPAReconciler) ReconcileVeleroServiceMonitor(log logr.Logger) (bool, error) {
10917

11018
dpa := oadpv1alpha1.DataProtectionApplication{}
@@ -206,78 +114,6 @@ func (r *DPAReconciler) buildVeleroServiceMonitor(serviceMonitor *monitor.Servic
206114
return nil
207115
}
208116

209-
//func (r *DPAReconciler) ReconcileMetricsSVC(log logr.Logger) (bool, error) {
210-
// dpa := oadpv1alpha1.DataProtectionApplication{}
211-
// if err := r.Get(r.Context, r.NamespacedName, &dpa); err != nil {
212-
// return false, err
213-
// }
214-
//
215-
// svc := corev1.Service{
216-
// ObjectMeta: metav1.ObjectMeta{
217-
// Name: "oadp-operator-metrics",
218-
// Namespace: r.NamespacedName.Namespace,
219-
// },
220-
// }
221-
//
222-
// // Create SVC
223-
// op, err := controllerutil.CreateOrUpdate(r.Context, r.Client, &svc, func() error {
224-
// // TODO: check for svc status condition errors and respond here
225-
// err := r.updateMetricsSVC(&svc, &dpa)
226-
//
227-
// return err
228-
// })
229-
// if err != nil {
230-
// return false, err
231-
// }
232-
// if op == controllerutil.OperationResultCreated || op == controllerutil.OperationResultUpdated {
233-
// // Trigger event to indicate SVC was created or updated
234-
// r.EventRecorder.Event(&svc,
235-
// corev1.EventTypeNormal,
236-
// "MetricsServiceReconciled",
237-
// fmt.Sprintf("performed %s on service %s/%s", op, svc.Namespace, svc.Name),
238-
// )
239-
// }
240-
//
241-
// return true, nil
242-
//}
243-
//
244-
//func (r *DPAReconciler) updateMetricsSVC(svc *corev1.Service, dpa *oadpv1alpha1.DataProtectionApplication) error {
245-
// // Setting controller owner reference on the metrics svc
246-
// err := controllerutil.SetControllerReference(dpa, svc, r.Scheme)
247-
// if err != nil {
248-
// return err
249-
// }
250-
//
251-
// // when updating the spec fields we update each field individually
252-
// // to get around the immutable fields
253-
// svc.Spec.Selector = map[string]string{
254-
// oadpv1alpha1.OadpOperatorLabel: "true",
255-
// "control-plane": "controller-manager",
256-
// }
257-
//
258-
// svc.Spec.Type = corev1.ServiceTypeClusterIP
259-
// svc.Spec.Ports = []corev1.ServicePort{
260-
// {
261-
// Name: "metrics",
262-
// Port: int32(2112),
263-
// Protocol: corev1.ProtocolTCP,
264-
// TargetPort: intstr.IntOrString{
265-
// IntVal: int32(2112),
266-
// },
267-
// },
268-
// }
269-
//
270-
// svc.Spec.ClusterIP = "None"
271-
//
272-
// svc.Spec.SessionAffinity = "None"
273-
//
274-
// svc.Labels = map[string]string{
275-
// oadpv1alpha1.OadpOperatorLabel: "true",
276-
// "app": "oadp-operator",
277-
// }
278-
// return nil
279-
//}
280-
281117
func (r *DPAReconciler) ReconcileVeleroMetricsSVC(log logr.Logger) (bool, error) {
282118
dpa := oadpv1alpha1.DataProtectionApplication{}
283119
if err := r.Get(r.Context, r.NamespacedName, &dpa); err != nil {

0 commit comments

Comments
 (0)