Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/operator/operands/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ var KaiServicesForServiceMonitor = []struct {
Port string
JobLabel string
}{
{"queuecontroller", "metrics", "queuecontroller"},
{"queue-controller", "metrics", "queue-controller"},
}

func AllControllersAvailable(
Expand Down
4 changes: 2 additions & 2 deletions pkg/operator/operands/known_types/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,10 @@ func getCurrentServiceMonitorState(ctx context.Context, runtimeClient client.Cli
if err != nil {
// If field indexer is not available, fall back to listing all ServiceMonitor resources
// and filter by owner reference manually
log.FromContext(ctx).Info("Failed to list ServiceMonitor. error: %v", err)
log.FromContext(ctx).Info("Failed to list ServiceMonitor", "error", err)
err = runtimeClient.List(ctx, serviceMonitorList)
if err != nil {
log.FromContext(ctx).Error(err, "Failed to manually list ServiceMonitor resource. error: %v", err)
log.FromContext(ctx).Error(err, "Failed to manually list ServiceMonitor resource", "error", err)
return nil, err
}

Expand Down
8 changes: 4 additions & 4 deletions pkg/operator/operands/prometheus/prometheus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ var _ = Describe("Prometheus", func() {
It("should return Prometheus object when Prometheus Operator is installed", func(ctx context.Context) {
objects, err := prometheus.DesiredState(ctx, fakeKubeClient, kaiConfig)
Expect(err).To(BeNil())
Expect(len(objects)).To(Equal(3)) // ServiceAccount, Prometheus, 1 ServiceMonitor
Expect(len(objects)).To(Equal(4)) // ServiceAccount, Prometheus, 2 ServiceMonitors

prometheusObj := test_utils.FindTypeInObjects[*monitoringv1.Prometheus](objects)
Expect(prometheusObj).NotTo(BeNil())
Expand All @@ -131,7 +131,7 @@ var _ = Describe("Prometheus", func() {

objects, err := prometheus.DesiredState(ctx, fakeKubeClient, kaiConfig)
Expect(err).To(BeNil())
Expect(len(objects)).To(Equal(3)) // ServiceAccount, Prometheus, 1 ServiceMonitor
Expect(len(objects)).To(Equal(4)) // ServiceAccount, Prometheus, 2 ServiceMonitor

prometheusObj := test_utils.FindTypeInObjects[*monitoringv1.Prometheus](objects)
Expect(prometheusObj).NotTo(BeNil())
Expand Down Expand Up @@ -474,11 +474,11 @@ var _ = Describe("prometheusForKAIConfig", func() {
// The function skips Prometheus CR creation and only creates ServiceMonitors
Expect(err).To(BeNil())
Expect(objects).NotTo(BeNil())
Expect(len(objects)).To(Equal(1)) // 1 ServiceMonitor
Expect(len(objects)).To(Equal(2)) // 2 ServiceMonitors

serviceMonitor := test_utils.FindTypeInObjects[*monitoringv1.ServiceMonitor](objects)
Expect(serviceMonitor).NotTo(BeNil())
Expect((*serviceMonitor).Name).To(Equal("queuecontroller"))
Expect((*serviceMonitor).Name).To(Equal("queue-controller"))
})

It("should return empty objects list when ServiceMonitors are disabled", func(ctx context.Context) {
Expand Down
32 changes: 32 additions & 0 deletions pkg/operator/operands/prometheus/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ func serviceMonitorsForKAIConfig(
return nil, err
}

serviceMonitorObj.GetLabels()["accounting"] = mainResourceName

// Set the ServiceMonitor spec from configuration
serviceMonitorSpec := monitoringv1.ServiceMonitorSpec{
JobLabel: kaiService.JobLabel,
Expand Down Expand Up @@ -186,6 +188,36 @@ func serviceMonitorsForKAIConfig(
serviceMonitorObj.(*monitoringv1.ServiceMonitor).Spec = serviceMonitorSpec
serviceMonitors = append(serviceMonitors, serviceMonitorObj)
}

kubeStateMetric := &monitoringv1.ServiceMonitor{
ObjectMeta: metav1.ObjectMeta{
Name: "kube-state-metrics",
Namespace: kaiConfig.Spec.Namespace,
Labels: map[string]string{
"accounting": mainResourceName,
},
},
Spec: monitoringv1.ServiceMonitorSpec{
JobLabel: "kube-state-metrics",
NamespaceSelector: monitoringv1.NamespaceSelector{
MatchNames: []string{"monitoring", "default"},
},
Selector: metav1.LabelSelector{
MatchLabels: map[string]string{
"app.kubernetes.io/name": "kube-state-metrics",
},
},
Endpoints: []monitoringv1.Endpoint{
{
Port: "http",
BearerTokenFile: "/var/run/secrets/kubernetes.io/serviceaccount/token",
Interval: "30s",
},
},
},
}

serviceMonitors = append(serviceMonitors, kubeStateMetric)
return serviceMonitors, nil
}

Expand Down
Loading