newrelic-kubernetes-operator icon indicating copy to clipboard operation
newrelic-kubernetes-operator copied to clipboard

kubectl apply silently fails if `type` is omitted from a condition spec (misleads the user)

Open sanderblue opened this issue 4 years ago • 0 comments

Description

When attempting to apply an AlertsPolicy configuration that includes an alert condition that omits the condition's type field, running kubectl apply silently fails and makes it seem like the apply was successful.

Example that causes a silent fail

apiVersion: nr.k8s.newrelic.com/v1
kind: AlertsPolicy
metadata:
  name: my-policy
spec:
  account_id: *******
  api_key: *******
  name: "my policy" 
  region: "us"

  conditions:
    - spec:
        # Note the omission of `type` in this condition spec
        name: "My NRQL Alert Condition"
        nrql:
          query: "SELECT average(duration) FROM Transaction WHERE appName = 'Dummy App'"
          evaluationOffset: 3
        enabled: true
        terms:
          - threshold: "5"
            threshold_occurrences: "ALL"
            threshold_duration: 180
            priority: "CRITICAL"
            operator: "ABOVE"
        violationTimeLimit: "ONE_HOUR"
        valueFunction: "SINGLE_VALUE"

Run kubectl apply for the above configuration and the user will still see the "success" output

alertspolicy.nr.k8s.newrelic.com/my-policy configured

Go Version

1.14.3

Expected behavior

With the provided invalid configuration mentioned above, kubectl apply should end up with a hard fail and kill the process, then display an error message letting the user know they are missing the required type field on the condition spec.

Steps To Reproduce

Steps to reproduce the behavior:

  1. Use the config above.
  2. Run kubectl apply -f ./the_policy.yaml
  3. See error: which is that no error actually happens (this should actually display an error message since it's missing the type field)

sanderblue avatar Jun 30 '20 00:06 sanderblue