apiVersion: operator.victoriametrics.com/v1beta1
kind: VMRule
metadata:
  name: alerts-flux-resources
spec:
  groups:
  - name: flux-resources-alerts
    rules:
    - alert: HelmReleaseNotReady
      expr: gotk_resource_info{customresource_kind="HelmRelease", ready!="True"} > 0
      for: 5m
      labels:
        severity: major
        service: fluxcd
        exported_instance: '{{ $labels.exported_namespace }}/{{ $labels.name }}'
      annotations:
        summary: "HelmRelease {{ $labels.name }} in namespace {{ $labels.exported_namespace }} is not ready"
        description: "HelmRelease {{ $labels.name }} in namespace {{ $labels.exported_namespace }} is in an unready state for more than 15 minutes."

    - alert: GitRepositorySyncFailed
      expr: gotk_resource_info{customresource_kind="GitRepository", ready!="True"} > 0
      for: 5m
      labels:
        severity: major
        service: fluxcd
        exported_instance: '{{ $labels.exported_namespace }}/{{ $labels.name }}'
      annotations:
        summary: "GitRepository {{ $labels.name }} in namespace {{ $labels.exported_namespace }} sync failed"
        description: "GitRepository {{ $labels.name }} in namespace {{ $labels.exported_namespace }} has not been successfully synced for more than 15 minutes."

    - alert: KustomizationNotApplied
      expr: gotk_resource_info{customresource_kind="Kustomization", ready!="True"} > 0
      for: 5m
      labels:
        severity: major
        service: fluxcd
        exported_instance: '{{ $labels.exported_namespace }}/{{ $labels.name }}'
      annotations:
        summary: "Kustomization {{ $labels.name }} in namespace {{ $labels.exported_namespace }} is not applied"
        description: "Kustomization {{ $labels.name }} in namespace {{ $labels.exported_namespace }} is not successfully applied for more than 15 minutes."

    - alert: ImageRepositorySyncFailed
      expr: gotk_resource_info{customresource_kind="ImageRepository", ready!="True"} > 0
      for: 5m
      labels:
        severity: major
        service: fluxcd
        exported_instance: '{{ $labels.exported_namespace }}/{{ $labels.name }}'
      annotations:
        summary: "ImageRepository {{ $labels.name }} in namespace {{ $labels.exported_namespace }} sync failed"
        description: "ImageRepository {{ $labels.name }} in namespace {{ $labels.exported_namespace }} has not been successfully synced for more than 15 minutes."

    - alert: HelmChartFailed
      expr: gotk_resource_info{customresource_kind="HelmChart", ready!="True"} > 0
      for: 5m
      labels:
        severity: major
        service: fluxcd
        exported_instance: '{{ $labels.exported_namespace }}/{{ $labels.name }}'
      annotations:
        summary: "HelmChart {{ $labels.name }} in namespace {{ $labels.exported_namespace }} has failed"
        description: "HelmChart {{ $labels.name }} in namespace {{ $labels.exported_namespace }} is not ready for more than 15 minutes."

    - alert: HelmReleaseSuspended
      expr: gotk_resource_info{customresource_kind="HelmRelease", suspended="true"} > 0
      for: 5m
      labels:
        severity: warning
        service: fluxcd
        exported_instance: '{{ $labels.exported_namespace }}/{{ $labels.name }}'
      annotations:
        summary: "HelmRelease {{ $labels.name }} in namespace {{ $labels.exported_namespace }} is suspended"
        description: "HelmRelease {{ $labels.name }} in namespace {{ $labels.exported_namespace }} has been suspended."

    - alert: GitRepositorySuspended
      expr: gotk_resource_info{customresource_kind="GitRepository", suspended="true"} > 0
      for: 5m
      labels:
        severity: warning
        service: fluxcd
        exported_instance: '{{ $labels.exported_namespace }}/{{ $labels.name }}'
      annotations:
        summary: "GitRepository {{ $labels.name }} in namespace {{ $labels.exported_namespace }} is suspended"
        description: "GitRepository {{ $labels.name }} in namespace {{ $labels.exported_namespace }} has been suspended."

    - alert: KustomizationSuspended
      expr: gotk_resource_info{customresource_kind="Kustomization", suspended="true"} > 0
      for: 5m
      labels:
        severity: warning
        service: fluxcd
        exported_instance: '{{ $labels.exported_namespace }}/{{ $labels.name }}'
      annotations:
        summary: "Kustomization {{ $labels.name }} in namespace {{ $labels.exported_namespace }} is suspended"
        description: "Kustomization {{ $labels.name }} in namespace {{ $labels.exported_namespace }} has been suspended."

    - alert: ImageRepositorySuspended
      expr: gotk_resource_info{customresource_kind="ImageRepository", suspended="true"} > 0
      for: 5m
      labels:
        severity: warning
        service: fluxcd
        exported_instance: '{{ $labels.exported_namespace }}/{{ $labels.name }}'
      annotations:
        summary: "ImageRepository {{ $labels.name }} in namespace {{ $labels.exported_namespace }} is suspended"
        description: "ImageRepository {{ $labels.name }} in namespace {{ $labels.exported_namespace }} has been suspended."

    - alert: HelmChartSuspended
      expr: gotk_resource_info{customresource_kind="HelmChart", suspended="true"} > 0
      for: 5m
      labels:
        severity: warning
        service: fluxcd
        exported_instance: '{{ $labels.exported_namespace }}/{{ $labels.name }}'
      annotations:
        summary: "HelmChart {{ $labels.name }} in namespace {{ $labels.exported_namespace }} is suspended"
        description: "HelmChart {{ $labels.name }} in namespace {{ $labels.exported_namespace }} has been suspended."
