Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support creating PodDisruptionBudget policies via helm chart #240

Open
z0rc opened this issue Apr 28, 2021 · 2 comments
Open

Support creating PodDisruptionBudget policies via helm chart #240

z0rc opened this issue Apr 28, 2021 · 2 comments

Comments

@z0rc
Copy link

z0rc commented Apr 28, 2021

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.

@oncipriani
Copy link

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.

@Tomy8s
Copy link

Tomy8s commented May 27, 2024

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants