Skip to content

Commit

Permalink
truncate job name to 63 chars
Browse files Browse the repository at this point in the history
  • Loading branch information
kschoche committed Dec 19, 2023
1 parent 61b77f2 commit 5fabe07
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
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
27 changes: 27 additions & 0 deletions test/unit/deployment.bats
Original file line number Diff line number Diff line change
Expand Up @@ -691,3 +691,30 @@ 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" ]
}

0 comments on commit 5fabe07

Please sign in to comment.