Skip to content

Commit d14d828

Browse files
committed
Remove the central service monitor
1 parent 1c92fc6 commit d14d828

File tree

4 files changed

+1
-115
lines changed

4 files changed

+1
-115
lines changed

controllers/monitor.go

+1-48
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ import (
1313
)
1414

1515
const (
16-
centralServiceMonitorTemplatePath = "service/service-monitor-central.tmpl.yaml"
17-
localServiceMonitorTemplatePath = "service/service-monitor-local.tmpl.yaml"
16+
localServiceMonitorTemplatePath = "service/service-monitor-local.tmpl.yaml"
1817
)
1918

2019
type ServiceMonitorConfig struct {
@@ -23,52 +22,6 @@ type ServiceMonitorConfig struct {
2322
ServiceName string
2423
}
2524

26-
// createCentralServiceMonitorObject generates the ServiceMonitor spec for central ServiceMonitor
27-
func createCentralServiceMonitorObject(ctx context.Context, deploymentNamespace string) (*monitoringv1.ServiceMonitor, error) {
28-
29-
config := ServiceMonitorConfig{
30-
Namespace: deploymentNamespace,
31-
ComponentName: componentName,
32-
ServiceName: serviceMonitorName,
33-
}
34-
35-
var serviceMonitor *monitoringv1.ServiceMonitor
36-
serviceMonitor, err := templateParser.ParseResource[monitoringv1.ServiceMonitor](centralServiceMonitorTemplatePath, config, reflect.TypeOf(&monitoringv1.ServiceMonitor{}))
37-
if err != nil {
38-
log.FromContext(ctx).Error(err, "Error parsing the central ServiceMonitor template")
39-
return nil, err
40-
}
41-
42-
return serviceMonitor, nil
43-
}
44-
45-
// ensureCentralServiceMonitor ensures that the central ServiceMonitor is created
46-
func (r *TrustyAIServiceReconciler) ensureCentralServiceMonitor(ctx context.Context) error {
47-
serviceMonitor, err := createCentralServiceMonitorObject(ctx, r.Namespace)
48-
if err != nil {
49-
return err
50-
}
51-
52-
// Check if this ServiceMonitor already exists
53-
found := &monitoringv1.ServiceMonitor{}
54-
err = r.Get(ctx, types.NamespacedName{Name: serviceMonitor.Name, Namespace: serviceMonitor.Namespace}, found)
55-
if err != nil {
56-
if errors.IsNotFound(err) {
57-
log.FromContext(ctx).Info("Creating a new central ServiceMonitor", "ServiceMonitor.Namespace", serviceMonitor.Namespace, "ServiceMonitor.Name", serviceMonitor.Name)
58-
err = r.Create(ctx, serviceMonitor)
59-
if err != nil {
60-
log.FromContext(ctx).Error(err, "Failed to create central ServiceMonitor", "ServiceMonitor.Namespace", serviceMonitor.Namespace, "ServiceMonitor.Name", serviceMonitor.Name)
61-
return err
62-
}
63-
} else {
64-
log.FromContext(ctx).Error(err, "Failed to get central ServiceMonitor", "ServiceMonitor.Namespace", serviceMonitor.Namespace, "ServiceMonitor.Name", serviceMonitor.Name)
65-
return err
66-
}
67-
}
68-
69-
return nil
70-
}
71-
7225
// createLocalServiceMonitorObject generates the ServiceMonitor spec for a local ServiceMonitor
7326
func createLocalServiceMonitorObject(ctx context.Context, deploymentNamespace string, serviceMonitorName string) (*monitoringv1.ServiceMonitor, error) {
7427

controllers/monitor_test.go

-32
Original file line numberDiff line numberDiff line change
@@ -24,38 +24,6 @@ var _ = Describe("Service Monitor Reconciliation", func() {
2424
ctx = context.Background()
2525
})
2626

27-
Context("When creating a central ServiceMonitor", func() {
28-
29-
It("Should have correct values", func() {
30-
31-
err := reconciler.ensureCentralServiceMonitor(ctx)
32-
Expect(err).ToNot(HaveOccurred())
33-
34-
// Define the ServiceMonitor object and fetch from the cluster
35-
serviceMonitor := &monitoringv1.ServiceMonitor{}
36-
err = k8sClient.Get(ctx, types.NamespacedName{Name: serviceMonitorName, Namespace: reconciler.Namespace}, serviceMonitor)
37-
Expect(err).NotTo(HaveOccurred())
38-
39-
Expect(serviceMonitor.ObjectMeta.Name).To(Equal(serviceMonitorName))
40-
Expect(serviceMonitor.ObjectMeta.Namespace).To(Equal(reconciler.Namespace))
41-
Expect(serviceMonitor.Labels["modelmesh-service"]).To(Equal("modelmesh-serving"))
42-
43-
Expect(serviceMonitor.Spec.Selector.MatchLabels["app.kubernetes.io/part-of"]).To(Equal(componentName))
44-
45-
Expect(serviceMonitor.Spec.NamespaceSelector.Any).To(BeTrue())
46-
47-
Expect(serviceMonitor.Spec.Endpoints).To(HaveLen(1))
48-
endpoint := serviceMonitor.Spec.Endpoints[0]
49-
Expect(endpoint.BearerTokenSecret.Key).To(Equal(""))
50-
Expect(endpoint.HonorLabels).To(BeTrue())
51-
52-
Expect(endpoint.Path).To(Equal("/q/metrics"))
53-
Expect(endpoint.Scheme).To(Equal("http"))
54-
Expect(endpoint.Params["match[]"]).To(ConsistOf("{__name__= \"trustyai_spd\"}", "{__name__= \"trustyai_dir\"}"))
55-
56-
})
57-
})
58-
5927
Context("When creating a local ServiceMonitor", func() {
6028
var instance *trustyaiopendatahubiov1alpha1.TrustyAIService
6129
It("Should have correct values", func() {

controllers/templates/service/service-monitor-central.tmpl.yaml

-29
This file was deleted.

controllers/trustyaiservice_controller.go

-6
Original file line numberDiff line numberDiff line change
@@ -217,12 +217,6 @@ func (r *TrustyAIServiceReconciler) Reconcile(ctx context.Context, req ctrl.Requ
217217
return ctrl.Result{}, err
218218
}
219219

220-
// Central Service Monitor
221-
err = r.ensureCentralServiceMonitor(ctx)
222-
if err != nil {
223-
return RequeueWithError(err)
224-
}
225-
226220
// Create route
227221
// TODO: Change argument order
228222
err = r.ReconcileRoute(instance, ctx)

0 commit comments

Comments
 (0)