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

Add optional PodDisruptionBudget to the Helm chart #383

Merged
merged 3 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions deploy/charts/approver-policy/README.md
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Auto generated by make generate-helm-docs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions deploy/charts/approver-policy/templates/NOTES.txt
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added this NOTES file to give some warning to the user. Inspired by something @inteon added to venafi-enhanced-issuer.

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{{- if (lt (int .Values.replicaCount) 2) }}
⚠️ WARNING: Consider increasing the Helm value `replicaCount` to 2 if you require high availability.
{{- end }}

{{- if (not .Values.podDisruptionBudget.enabled) }}
⚠️ WARNING: Consider setting the Helm value `podDisruptionBudget.enabled` to true if you require high availability.
{{- end }}

CHART NAME: {{ .Chart.Name }}
CHART VERSION: {{ .Chart.Version }}
APP VERSION: {{ .Chart.AppVersion }}

{{ .Chart.Name }} is a cert-manager project.

If you're a new user, we recommend that you read the [cert-manager Approval Policy documentation] to learn more.

[cert-manager Approval Policy documentation]: https://cert-manager.io/docs/policy/approval/
16 changes: 16 additions & 0 deletions deploy/charts/approver-policy/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,19 @@ See https://github.com/cert-manager/cert-manager/issues/6329 for a list of linke
{{- if .digest -}}{{ printf "@%s" .digest }}{{- else -}}{{ printf ":%s" (default $defaultTag .tag) }}{{- end -}}
{{- end }}
{{- end }}

{{/*
Copied from
https://github.com/kyverno/kyverno/blob/df5e39c005a78f1ffe6a2eeda3f4497cc9c24384/charts/kyverno/templates/_helpers/_pdb.tpl
*/}}
{{- define "cert-manager-approver-policy.pdb.spec" -}}
{{- if and .minAvailable .maxUnavailable -}}
{{- fail "Cannot set both .minAvailable and .maxUnavailable" -}}
{{- end -}}
{{- if not .maxUnavailable -}}
minAvailable: {{ default 1 .minAvailable }}
{{- end -}}
{{- if .maxUnavailable -}}
maxUnavailable: {{ .maxUnavailable }}
{{- end -}}
{{- end -}}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Example output of the validation in this new helper.

$ helm upgrade --install -n venafi approver-policy _bin/scratch/image/cert-manager-approver-policy-v0.13.0-alpha.0-12-g075790a76f86b9-dirty.tgz --set podDisruptionBudget.enabled=true --set podDisruptionBudget.minAvailable=1 --set podDisruptionBudget.maxUnavailable=1 --set image.tag=v0.12.1
Error: UPGRADE FAILED: execution error at (cert-manager-approver-policy/templates/poddisruptionbudget.yaml:10:6): Cannot set both .minAvailable and .maxUnavailable

14 changes: 14 additions & 0 deletions deploy/charts/approver-policy/templates/poddisruptionbudget.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{{- if .Values.podDisruptionBudget.enabled -}}
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
name: {{ include "cert-manager-approver-policy.name" . }}
namespace: {{ .Release.Namespace | quote }}
labels:
{{- include "cert-manager-approver-policy.labels" . | nindent 4 }}
spec:
{{- include "cert-manager-approver-policy.pdb.spec" .Values.podDisruptionBudget | nindent 2 }}
selector:
matchLabels:
app: {{ include "cert-manager-approver-policy.name" . }}
{{- end -}}
31 changes: 31 additions & 0 deletions deploy/charts/approver-policy/values.schema.json
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Auto generated by make generate-helm-schema

Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
"podAnnotations": {
"$ref": "#/$defs/helm-values.podAnnotations"
},
"podDisruptionBudget": {
"$ref": "#/$defs/helm-values.podDisruptionBudget"
},
"replicaCount": {
"$ref": "#/$defs/helm-values.replicaCount"
},
Expand Down Expand Up @@ -358,6 +361,34 @@
"description": "Allow custom annotations to be placed on cert-manager-approver pod - optional.",
"type": "object"
},
"helm-values.podDisruptionBudget": {
"additionalProperties": false,
"properties": {
"enabled": {
"$ref": "#/$defs/helm-values.podDisruptionBudget.enabled"
},
"maxUnavailable": {
"$ref": "#/$defs/helm-values.podDisruptionBudget.maxUnavailable"
},
"minAvailable": {
"$ref": "#/$defs/helm-values.podDisruptionBudget.minAvailable"
}
},
"type": "object"
},
"helm-values.podDisruptionBudget.enabled": {
"default": false,
"description": "Enable or disable the PodDisruptionBudget resource.\n\nThis prevents downtime during voluntary disruptions such as during a Node upgrade. For example, the PodDisruptionBudget blocks `kubectl drain` if it is used on the Node where the only remaining approver-policy\nPod is currently running.",
"type": "boolean"
},
"helm-values.podDisruptionBudget.maxUnavailable": {
"description": "Configures the maximum unavailable pods for disruptions.\nCannot be used if `minAvailable` is set.",
"type": "number"
},
"helm-values.podDisruptionBudget.minAvailable": {
"description": "Configures the minimum available pods for disruptions.\nCannot be used if `maxUnavailable` is set.",
"type": "number"
},
"helm-values.replicaCount": {
"default": 1,
"description": "Number of replicas of approver-policy to run.",
Expand Down
24 changes: 22 additions & 2 deletions deploy/charts/approver-policy/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ app:

# List if signer names that approver-policy will be given permission to
# approve and deny. CertificateRequests referencing these signer names can be
# processed by approver-policy.
# processed by approver-policy.
#
# ref: https://cert-manager.io/docs/concepts/certificaterequest/#approval
# +docs:property
Expand All @@ -72,7 +72,7 @@ app:
# Create Prometheus ServiceMonitor resource for approver-policy.
enabled: false
# The value for the "prometheus" label on the ServiceMonitor. This allows
# for multiple Prometheus instances selecting difference ServiceMonitors
# for multiple Prometheus instances selecting difference ServiceMonitors
# using label selectors.
prometheusInstance: default
# The interval that the Prometheus will scrape for metrics.
Expand Down Expand Up @@ -143,6 +143,26 @@ app:
# effect: NoSchedule
tolerations: []

podDisruptionBudget:
# Enable or disable the PodDisruptionBudget resource.
#
# This prevents downtime during voluntary disruptions such as during a Node upgrade.
# For example, the PodDisruptionBudget blocks `kubectl drain`
# if it is used on the Node where the only remaining approver-policy
# Pod is currently running.
enabled: false

# Configures the minimum available pods for disruptions.
# Cannot be used if `maxUnavailable` is set.
# +docs:property
# minAvailable: 1

# Configures the maximum unavailable pods for disruptions.
# Cannot be used if `minAvailable` is set.
# +docs:property
# maxUnavailable: 1


# Optional extra volume mounts. Useful for mounting custom root CAs.
#
# For example:
Expand Down