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 5 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
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" ]
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: extra leading whitespace

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed in d51cefc

}

@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" ]
Copy link
Collaborator

Choose a reason for hiding this comment

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

cool, I wonder if we could also assert the length of $actual as well:

Something like:

   [ "${#actual}" -eq 63 ]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oooo, nice! thx, have included it in d51cefc

Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: extra leading whitespace

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed in d51cefc

}