title: Using jsonnet to update Prometheus operator default rule
body: <p>I am trying to override the Default rules in Kube-Prometheus-Stack.
  I have enabled default rules when Kube-Prometheus-Stack was deployed.
  I tried with jsonnet as shown in this example <a href="https://github.com/prometheus-operator/kube-prometheus/blob/master/docs/developing-prometheus-rules-and-grafana-dashboards.md" rel="nofollow noreferrer">https://github.com/prometheus-operator/kube-prometheus/blob/master/docs/developing-prometheus-rules-and-grafana-dashboards.md</a>.</p>
  <p>But I think I am not following the steps correctly so its not working as expected.</p>
  <p>I followed the below steps..Kindly validate and please let me know what I am missing here.</p>
  <p>Created a jsonnet file (my-custom-update.jsonnet) to update a rule &quot;KubePodCrashLooping&quot;,</p>
  <pre><code> local filter = {
    prometheusAlerts+:: {
      groups: std.map(
        function(group)
          if group.name == 'kubernetes-apps' then
            group {
              rules: std.filter(function(rule)
                rule.alert != &quot;KubePodCrashLooping&quot;,
                group.rules
              )
            }
          else
            group,
        super.groups
      ),
    },
  };
  local update = {
    prometheusAlerts+:: {
      groups: std.map(
        function(group)
          if group.name == 'kubernetes-apps' then
            group {
              rules: std.map(
                function(rule)
                  if rule.alert == &quot;KubePodCrashLooping&quot; then
                    rule {
                      expr: &quot;kube_statefulset_status_replicas_ready{job=\&quot;kube-state-metrics\&quot;,statefulset!=\&quot;vault\&quot;} != kube_statefulset_status_replicas{job=\&quot;kube-state-metrics\&quot;,statefulset!=\&quot;vault\&quot;}&quot;
                    }
                  else
                    rule,
                  group.rules
              )
            }
          else
            group,
        super.groups
      ),
    },
  };
  local kp = (import 'kube-prometheus/kube-prometheus.libsonnet') + filter + update + {
      prometheusAlerts+:: (import 'prometheus-rules.json'),
  };
  
  { ['00namespace-' + name]: kp.kubePrometheus[name] for name in std.objectFields(kp.kubePrometheus) } +
  { ['0prometheus-operator-' + name]: kp.prometheusOperator[name] for name in std.objectFields(kp.prometheusOperator) } +
  { ['node-exporter-' + name]: kp.nodeExporter[name] for name in std.objectFields(kp.nodeExporter) } +
  { ['kube-state-metrics-' + name]: kp.kubeStateMetrics[name] for name in std.objectFields(kp.kubeStateMetrics) } +
  { ['alertmanager-' + name]: kp.alertmanager[name] for name in std.objectFields(kp.alertmanager) } +
  { ['prometheus-' + name]: kp.prometheus[name] for name in std.objectFields(kp.prometheus) } +
  { ['prometheus-adapter-' + name]: kp.prometheusAdapter[name] for name in std.objectFields(kp.prometheusAdapter) } +
  { ['grafana-' + name]: kp.grafana[name] for name in std.objectFields(kp.grafana) } 
  </code></pre>
  <p>Build this jsonnet file with the build.sh script provided in the document,</p>
  <pre><code>./build.sh my-custom-update.jsonnet
  </code></pre>
  <p>This has actually deleted the &quot;KubePodCrashLooping&quot; rule instead of updating it.
  This created all the yaml files under manifests directory</p>
  <p>I think I am missing something..Please advice.</p>