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: 2 additions & 0 deletions charts/coralogix-operator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,6 @@ Kubernetes: `>=1.16.0-0`
| serviceMonitor.namespace | string | `""` | If not set, the service monitor will be created in the same namespace as the operator. |
| serviceMonitor.namespaceSelector.enabled | bool | `false` | Useful when the service monitor is deployed in a different namespace than the operator. |
| tolerations | list | `[]` | ref: https://kubernetes.io/docs/concepts/configuration/taint-and-toleration/ |
| volumeMounts | list | `[]` | Additional volumeMounts on the output Deployment definition. |
| volumes | list | `[]` | Additional volumes on the output Deployment definition. |

21 changes: 19 additions & 2 deletions internal/controller/prometheusrule_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"errors"
"fmt"
"reflect"
"regexp"
"strings"
"time"

Expand Down Expand Up @@ -224,7 +225,11 @@ func (r *PrometheusRuleReconciler) convertPrometheusRuleAlertToCxAlert(ctx conte
for alertName, rules := range alertMap {
for i, rule := range rules {
alert := &coralogixv1beta1.Alert{}
alertName := fmt.Sprintf("%s-%s-%d", prometheusRule.Name, alertName, i)
alertName := fmt.Sprintf("%s-%s-%d",
prometheusRule.Name,
sanitizeName(alertName),
i,
)
alertsToKeep[alertName] = true
if err := config.GetClient().Get(ctx, client.ObjectKey{Namespace: prometheusRule.Namespace, Name: alertName}, alert); err != nil {
if k8serrors.IsNotFound(err) {
Expand Down Expand Up @@ -425,7 +430,7 @@ func prometheusAlertToMetricThreshold(rule prometheus.Rule, priority coralogixv1
Threshold: resource.MustParse("0"),
ForOverPct: 100,
OfTheLast: coralogixv1beta1.MetricTimeWindow{
DynamicDuration: ptr.To(string(ptr.Deref(rule.For, ""))),
DynamicDuration: ptr.To(string(ptr.Deref(rule.For, "1m"))),
},
ConditionType: coralogixv1beta1.MetricThresholdConditionTypeMoreThan,
},
Expand Down Expand Up @@ -466,6 +471,18 @@ func getOwnerReference(promRule *prometheus.PrometheusRule) metav1.OwnerReferenc
}
}

// sanitizeName converts any string into a valid Kubernetes resource name
// according to RFC 1123 (lowercase alphanumeric, '-', or '.').
func sanitizeName(name string) string {
name = strings.ToLower(name)
// Replace any invalid characters (anything not a-z, 0-9, '-', or '.') with '-'
re := regexp.MustCompile(`[^a-z0-9.-]+`)
name = re.ReplaceAllString(name, "-")
// Trim leading/trailing non-alphanumeric characters
name = strings.Trim(name, "-.")
return name
}

// SetupWithManager sets up the controller with the Manager.
func (r *PrometheusRuleReconciler) SetupWithManager(mgr ctrl.Manager) error {
shouldTrackPrometheusRules := func(labels map[string]string) bool {
Expand Down
Loading