bjw-s / helm-charts

A collection of Helm charts
https://bjw-s.github.io/helm-charts/
Apache License 2.0
524 stars 98 forks source link

Flipped validations for `ServiceMonitor.spec.selector.match{Label,Expression}s` #317

Closed zakame closed 2 months ago

zakame commented 2 months ago

Details

What steps did you take and what happened:

Hi, first of all, thanks for this great template! πŸ™

Now, given a serviceMonitor definition like:

serviceMonitor:
  main:
    enabled: true
    selector:
      matchLabels:
        app.kubernetes.io/name: foo
        app.kubernetes.io/instance: foo

We're getting this from helm template...:

- serviceMonitor.main.selector.matchLabels: Invalid type. Expected: array, given: object

What did you expect to happen:

This previously worked without issue in app-template-2.6.0.

Anything else you would like to add:

matchExpressions and matchLabels validations for ServiceMonitor.spec.selector are flipped - matchLabels should take an object, while matchExpressions should take an array:

https://github.com/bjw-s/helm-charts/blob/0a42b82a82f61119e123acee5ac38b151a5cbd1a/charts/library/common/schemas/serviceMonitor.json#L28-L48

$ kubectl explain serviceMonitor.spec.selector.matchLabels
GROUP:      monitoring.coreos.com
KIND:       ServiceMonitor
VERSION:    v1

FIELD: matchLabels <map[string]string>

DESCRIPTION:
    matchLabels is a map of {key,value} pairs. A single {key,value} in the
    matchLabels map is equivalent to an element of matchExpressions, whose key
    field is "key", the operator is "In", and the values array contains only
    "value". The requirements are ANDed.
$ kubectl explain serviceMonitor.spec.selector.matchExpressions
GROUP:      monitoring.coreos.com
KIND:       ServiceMonitor
VERSION:    v1

FIELD: matchExpressions <[]Object>

DESCRIPTION:
    matchExpressions is a list of label selector requirements. The requirements
    are ANDed.
    A label selector requirement is a selector that contains values, a key, and
    an operator that relates the key and values.

FIELDS:
  key   <string> -required-
    key is the label key that the selector applies to.

  operator      <string> -required-
    operator represents a key's relationship to a set of values. Valid operators
    are In, NotIn, Exists and DoesNotExist.

  values        <[]string>
    values is an array of string values. If the operator is In or NotIn, the
    values array must be non-empty. If the operator is Exists or DoesNotExist,
    the values array must be empty. This array is replaced during a strategic
    merge patch.

Additional Information:

bjw-s commented 2 months ago

Thanks for raising this issue! Great catch! I am willing to bet that this was a copy/pasta error on my side πŸ˜… I've just pushed a fix that should correct the issue. Please let me know if that fixes the issue for you.

zakame commented 2 months ago

Wow, thanks for the prompt response! Yep we can confirm it works now πŸŽ‰ Thanks again!