vectordotdev / helm-charts

Helm charts for Vector.
https://vector.dev
Mozilla Public License 2.0
101 stars 89 forks source link

enhancement(vector): Add `persistence.retentionPolicy` for configuring Statefulset PVC retention policy #347

Open alemuro opened 7 months ago

alemuro commented 7 months ago

Hello! 👋

This PR adds a new variable in the values.yaml file: persistence.retentionPolicy.

This allow users to define which is the PVC retention policy for the created Statefulsets. Kubernetes by default sets a Remain policy, meaning that no PVC are removed when the Statefulset is down-scaled or removed. With this new setting, users can tell Kubernetes to remove these disks, for example for non production environment.

This variable has a default set to {}, meaning that this setting will not be applied and Kubernetes will apply its default value, so current statefulsets will not be affected.

More info about this new feature here: https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/#persistentvolumeclaim-retention

Some tests

I've run the following commands to ensure that the output is expected:

Using this setting on a K8S cluster below 1.23: Setting do not appear on the rendered statefulset.

$ helm template \                        
      -s templates/statefulset.yaml  \
      --kube-version "1.22" --set 'persistence.retentionPolicy.whenDeleted=Delete' \
      . |                  
      yq -r '.spec.persistentVolumeClaimRetentionPolicy'
null

Using this setting on a k8s cluster above 1.23: Setting appears on the rendered statefulset.

$ helm template \
      -s templates/statefulset.yaml  \
      --kube-version "1.27" --set 'persistence.retentionPolicy.whenDeleted=Delete' \
      . |
      yq -r '.spec.persistentVolumeClaimRetentionPolicy'
{
  "whenDeleted": "Delete"
}

$ helm template \
      -s templates/statefulset.yaml  \
      --kube-version "1.27" \
      --set 'persistence.retentionPolicy.whenScaled=Delete' \
      . |
      yq -r '.spec.persistentVolumeClaimRetentionPolicy'
{
  "whenScaled": "Delete"
}

Using the default value in a k8s cluster above 1.23: Setting do not appear on the rendered statefulset.

$ helm template \
      -s templates/statefulset.yaml  \
      --kube-version "1.27" \                                                                            
      . |
      yq -r '.spec.persistentVolumeClaimRetentionPolicy'
null