jaegertracing/helm-charts

Support creating PodDisruptionBudget policies via helm chart

Opened this issue · 2 comments

z0rc commented

It would be nice to be able to specify values for podDisruptionBudget for deployments in helm chart. These policies can be created manually, but having them under same lifecycle as rest of chart is much more preferred.

Agreed.

I tried to use the "extraObjects" to do that, but I could not find any way to add the proper labels, because apparently all templated values inside the "extraObjects" list must be quoted.

Examples of what I tried and did not work:

# Error: failed to parse values.yml: error converting YAML to JSON: yaml: line 192: did not find expected node content
# helm.go:84: [debug] error converting YAML to JSON: yaml: line 192: did not find expected node content
extraObjects:
  - apiVersion: policy/v1
    kind: PodDisruptionBudget
    metadata:
      name: '{{ template "jaeger.collector.name" . }}'
      labels: # This is line 192
        {{- include "jaeger.labels" . | nindent 4 }}
        app.kubernetes.io/component: collector
    spec:
      minAvailable: 1
      selector:
        matchLabels:
          app.kubernetes.io/instance: '{{ .Release.Name }}'
          app.kubernetes.io/component: collector

# Error: failed to parse values.yml: error converting YAML to JSON: yaml: line 193: did not find expected key
# helm.go:84: [debug] error converting YAML to JSON: yaml: line 193: did not find expected key
extraObjects:
  - apiVersion: policy/v1
    kind: PodDisruptionBudget
    metadata:
      name: '{{ template "jaeger.collector.name" . }}'
      labels: # This is line 192
        '{{- include "jaeger.labels" . | nindent 4 }}'
        app.kubernetes.io/component: collector
    spec:
      minAvailable: 1
      selector:
        matchLabels:
          app.kubernetes.io/instance: '{{ .Release.Name }}'
          app.kubernetes.io/component: collector

# Renders an invalid PDB because "labels:" becomes a single multiline string
extraObjects:
  - apiVersion: policy/v1
    kind: PodDisruptionBudget
    metadata:
      name: '{{ template "jaeger.collector.name" . }}'
      labels: # This is line 192
        '{{- include "jaeger.labels" . | nindent 4 }}'
    spec:
      minAvailable: 1
      selector:
        matchLabels:
          app.kubernetes.io/instance: '{{ .Release.Name }}'
          app.kubernetes.io/component: collector

Even the documentation's example does not work! Notice the absence of quotes in line 191.

# Error: failed to parse values.yml: error converting YAML to JSON: yaml: line 190: did not find expected key
extraObjects:
  - apiVersion: policy/v1
    kind: PodDisruptionBudget
    metadata: # This is line 190
      name: {{ .Release.Name }}-somePDB
    spec:
      minAvailable: 1
      selector:
        matchLabels:
          app.kubernetes.io/instance: '{{ .Release.Name }}'
          app.kubernetes.io/component: collector

I also tried using a template to set "spec.minAvailable" based on the minimum number of replicas of the Horizontal Pod Autoscaler, but since everything templated becomes a string it renders and invalid PDB.

@oncipriani, You're seeing that error as values files must be valid YAML before being parsed by helm. The example in README.md is not valid YAML, and therefore not valid (I have fixed this in #580). To get your desired outcome, you'll need to add the templating commands while also keeping your values file valid YAML. Unfortunately in this situation I can't think of a very nice, simple way of doing this; one hacky way to do this would be:

extraObjects:
  - apiVersion: policy/v1
    kind: PodDisruptionBudget
    metadata:
      name: '{{ template "jaeger.collector.name" . }}'
      labels:
        app.kubernetes.io/component: collector{{- include "jaeger.labels" . | nindent 4 }}
    spec:
      minAvailable: 1
      selector:
        matchLabels:
          app.kubernetes.io/instance: '{{ .Release.Name }}'
          app.kubernetes.io/component: collector