title: Create a prometheus-operator `PrometheusRule` (CRD) from a raw Prometheus rule file?
body: <p>A Prometheus rules file like this:</p>
  
  <pre><code>groups:
  - name: ./example.rules
    rules:
    - alert: ExampleAlert
      expr: vector(1)
  </code></pre>
  
  <p>The Kubernetes prometheus-operator requires an extra layer of yaml configuration data and looks like this:</p>
  
  <pre><code>apiVersion: monitoring.coreos.com/v1
  kind: PrometheusRule
  metadata:
    creationTimestamp: null
    labels:
      prometheus: example
      role: alert-rules
    name: prometheus-example-rules
  spec:
    groups:
    - name: ./example.rules
      rules:
      - alert: ExampleAlert
        expr: vector(1)
  </code></pre>
  
  <p>With files using the former, raw Prometheus rule format, I can use Prometheus <code>promtool</code> to run unit tests. (see link 3 below)</p>
  
  <p>With files using the latter, extended PrometheusRule format, I can use <code>kubectl apply -f prometheus_rule_file.yaml</code> to load the rules into my prometheus-operator installation.</p>
  
  <p>I want to write and maintain rules in one of these file formats and be able to use the same rule file both with promtool's unit test system and to load the same rule into a prometheus-operator installation. I don't see an easy way to do this.</p>
  
  <p>Is there a way I can have a rule using the raw Prometheus rule format and load it into a prometheus-operator PrometheusRule without maintaining a separate redundant yaml file and without writing a customized tool to convert it?</p>
  
  <ol>
  <li><a href="https://prometheus.io/docs/prometheus/latest/configuration/alerting_rules/" rel="noreferrer">https://prometheus.io/docs/prometheus/latest/configuration/alerting_rules/</a></li>
  <li><a href="https://github.com/coreos/prometheus-operator/blob/master/Documentation/user-guides/alerting.md" rel="noreferrer">https://github.com/coreos/prometheus-operator/blob/master/Documentation/user-guides/alerting.md</a></li>
  <li><a href="https://prometheus.io/docs/prometheus/latest/configuration/unit_testing_rules/" rel="noreferrer">https://prometheus.io/docs/prometheus/latest/configuration/unit_testing_rules/</a></li>
  </ol>