-
Notifications
You must be signed in to change notification settings - Fork 22
Add script to validate length of clustergroup chart and pattern names #643
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
Merged
dminnear-rh
merged 5 commits into
validatedpatterns:main
from
dminnear-rh:limit-pattern-group-names
Oct 9, 2025
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a1b23c8
add script to validate length of clustergroup chart and pattern names
dminnear-rh 3d7bfad
enforce that pattern name is set in values-global.yaml
dminnear-rh d286c3c
update ci workflow to test common updates on MCG
dminnear-rh c9ee2e0
reference utility container from validatedpatterns quay org
dminnear-rh ff07a5f
add arm runner for common scripts test
dminnear-rh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| MAX_CALCULATED_LENGTH=47 | ||
|
|
||
| print_explanation() { | ||
| echo "--------------------------------------------------------------------------------" | ||
| echo "Validation Explanation:" | ||
| echo "This script ensures that generated Kubernetes resource names do not exceed the 63-character limit." | ||
| echo "A DNS-compatible name is constructed in the 'clustergroup' Helm chart using the following pattern:" | ||
| echo " -> {{ .Values.clusterGroup.name }}-gitops-server-{{ .Values.global.pattern }}-{{ .Values.clusterGroup.name }}" | ||
| echo "" | ||
| echo "The total length is calculated as:" | ||
| echo " (2 * length of 'clusterGroup.name') + length of 'global.pattern' + 15 (for '-gitops-server-') + 1 (for the namespace separator '-')" | ||
| echo "" | ||
| echo "To stay under the 63-character limit, the variable part of the name must be less than $MAX_CALCULATED_LENGTH characters:" | ||
| echo " (2 * length of 'clusterGroup.name') + length of 'global.pattern' < $MAX_CALCULATED_LENGTH" | ||
| echo "--------------------------------------------------------------------------------" | ||
| } | ||
|
|
||
| if [ ! -f "values-global.yaml" ]; then | ||
| echo "Error: Global values file 'values-global.yaml' not found." | ||
| exit 1 | ||
| fi | ||
|
|
||
| global_pattern=$(yq .global.pattern "values-global.yaml") | ||
|
|
||
| if [ "$global_pattern" == "null" ] || [ -z "$global_pattern" ]; then | ||
| echo "Error: '.global.pattern' not found or is empty in 'values-global.yaml'." | ||
| exit 1 | ||
| fi | ||
| pattern_length=${#global_pattern} | ||
|
|
||
| echo "Validating that the pattern and clustergroup names don't exceed DNS limits after the pattern is installed." | ||
| echo "" | ||
|
|
||
| validation_failed=false | ||
|
|
||
| for file in values-*.yaml; do | ||
| group_name=$(yq .clusterGroup.name "$file") | ||
|
|
||
| if [ "$group_name" != "null" ] && [ -n "$group_name" ]; then | ||
| group_name_length=${#group_name} | ||
| total_length=$(( (2 * group_name_length) + pattern_length )) | ||
|
|
||
| echo "Checking file: $file" | ||
|
|
||
| if [ "$total_length" -ge "$MAX_CALCULATED_LENGTH" ]; then | ||
| echo " -> FAILED: Length of clustergroup '$group_name' and pattern '$global_pattern' will exceed DNS limits in clustergroup chart. Please shorten one or both." | ||
| echo "" | ||
| validation_failed=true | ||
| else | ||
| echo " -> PASSED: Length of clustergroup '$group_name' and pattern '$global_pattern' are within clustergroup chart limits." | ||
| echo "" | ||
| fi | ||
| fi | ||
| done | ||
|
|
||
| if $validation_failed; then | ||
| echo "One or more cluster group names failed the length validation." | ||
| print_explanation | ||
| exit 1 | ||
| else | ||
| echo "All names are within clustergroup chart limits." | ||
| exit 0 | ||
| fi |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add a fallback to the old ways here? I am just not remembering when we introduced the .global.pattern. Unless you're sure we have it set everywhere that is
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure it is set everywhere (although it probably should be). What if we use
yq --exit-status .global.pattern values-global.yamlto enforce that it is set. Then, rather than falling back to the directory name, we enforce they have a proper value.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So we error out if it does not have it set? Yeah let's go for that! I suppose the pattern's that don't have it, probably won't update common much anyways
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added the check:
so if it's not set (or if the pattern name is set to be an empty string) we'll error out: