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

Truncate pre-delete-controller Job name to 63 characters #506

Merged
merged 6 commits into from
Dec 19, 2023
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## Unreleased

Fix:
* Helm: rename and truncate the pre-delete cleanup job to 63 characters: [GH-506](https://github.com/hashicorp/vault-secrets-operator/pull/501)

## 0.4.2 (December 7th, 2023)

Fix:
Expand Down
10 changes: 8 additions & 2 deletions chart/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,10 @@ spec:
apiVersion: batch/v1
kind: Job
metadata:
name: {{ include "vso.chart.fullname" . }}-pre-delete-controller-cleanup
# This name is truncated because kubernetes applies labels to the job which contain the job and pod
# name, and labels are limited to 63 characters. If we do not truncate the user will not have any
# feedback until after runtime.
name: {{ printf "%s-%s" "pdcc" (include "vso.chart.fullname" .) | trunc 63 | trimSuffix "-" }}
namespace: {{ .Release.Namespace }}
labels:
{{- include "vso.chart.labels" . | nindent 4 }}
Expand All @@ -159,7 +162,10 @@ metadata:
spec:
template:
metadata:
name: {{ include "vso.chart.fullname" . }}-pre-delete-controller-cleanup
# This name is truncated because kubernetes applies labels to the job which contain the job and pod
# name, and labels are limited to 63 characters. If we do not truncate the user will not have any
# feedback until after runtime.
name: {{ printf "%s-%s" "pdcc" (include "vso.chart.fullname" .) | trunc 63 | trimSuffix "-" }}
spec:
serviceAccountName: {{ include "vso.chart.fullname" . }}-controller-manager
securityContext:
Expand Down
28 changes: 28 additions & 0 deletions test/unit/deployment.bats
Original file line number Diff line number Diff line change
Expand Up @@ -691,3 +691,31 @@ load _helpers
local actual=$(echo "$object" | yq '.[4]' | tee /dev/stderr)
[ "${actual}" = "--bar=qux" ]
}


#--------------------------------------------------------------------
# pre-delete-controller

@test "controller/Deployment: pre-delete-controller Job name is not truncated by default" {
cd `chart_dir`
local object=$(helm template \
-s templates/deployment.yaml \
. | tee /dev/stderr |
yq 'select(.kind == "Job") | .metadata' | tee /dev/stderr)

local actual=$(echo "$object" | yq '.name' | tee /dev/stderr)
[ "${actual}" = "pdcc-release-name-vault-secrets-operator" ]
}

@test "controller/Deployment: pre-delete-controller Job name is truncated to 63 characters" {
cd `chart_dir`
local object=$(helm template \
-s templates/deployment.yaml \
--set fullnameOverride=abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz \
. | tee /dev/stderr |
yq 'select(.kind == "Job") | .metadata' | tee /dev/stderr)

local actual=$(echo "$object" | yq '.name' | tee /dev/stderr)
[ "${actual}" = "pdcc-abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef" ]
[ "${#actual}" -eq 63 ]
}