Skip to content
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
19 changes: 10 additions & 9 deletions .github/workflows/pattern-sh-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
strategy:
matrix:
# Fedora is not an option yet
os: [ubuntu-latest, ubuntu-22.04]
os: [ubuntu-latest, ubuntu-22.04, ubuntu-24.04-arm]
runs-on: ${{ matrix.os }}
permissions:
contents: read
Expand All @@ -29,12 +29,6 @@ jobs:
with:
persist-credentials: false

- name: Install Podman on Ubuntu
if: contains(matrix.os, 'ubuntu')
run: |
sudo apt-get update
sudo apt-get install -y podman

# Currently we do not do MacOSX as it is not free, maybe in the future
# - name: Install Podman on macOS
# if: contains(matrix.os, 'macos')
Expand All @@ -46,7 +40,14 @@ jobs:
- name: Verify Podman Installation
run: podman --version

- name: Clone MCG and update common
run: |
git clone --depth 1 https://github.com/hybrid-cloud-patterns/multicloud-gitops mcg
cp -r scripts/ mcg/common/scripts
cp Makefile mcg/common

- name: Run pattern.sh script
run: |
export TARGET_BRANCH=main
./scripts/pattern-util.sh make validate-origin
cd mcg
./pattern.sh make validate-origin
./pattern.sh make show
17 changes: 9 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
NAME ?= $(shell basename "`pwd`")
NAME ?= $(shell yq .global.pattern values-global.yaml)
Copy link
Contributor

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

Copy link
Contributor Author

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.yaml to enforce that it is set. Then, rather than falling back to the directory name, we enforce they have a proper value.

Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added the check:

ifeq ($(NAME),)
$(error Pattern name MUST be set in values-global.yaml with the value .global.pattern)
endif
ifeq ($(NAME),null)
$(error Pattern name MUST be set in values-global.yaml with the value .global.pattern)
endif

so if it's not set (or if the pattern name is set to be an empty string) we'll error out:

❯ make show
make -f common/Makefile show
make[1]: Entering directory '/home/drewminnear/gh-repos/dminnear-rh/multicloud-gitops'
common/Makefile:7: *** Pattern name MUST be set in values-global.yaml with the value .global.pattern.  Stop.
make[1]: Leaving directory '/home/drewminnear/gh-repos/dminnear-rh/multicloud-gitops'
make: *** [Makefile:12: show] Error 2


ifeq ($(NAME),)
$(error Pattern name MUST be set in values-global.yaml with the value .global.pattern)
endif
ifeq ($(NAME),null)
$(error Pattern name MUST be set in values-global.yaml with the value .global.pattern)
endif

ifneq ($(origin TARGET_SITE), undefined)
TARGET_SITE_OPT=--set main.clusterGroupName=$(TARGET_SITE)
Expand Down Expand Up @@ -189,13 +196,7 @@ validate-schema: ## validates values files against schema in common/clustergroup

.PHONY: validate-prereq
validate-prereq: ## verify pre-requisites
$(eval GLOBAL_PATTERN := $(shell yq -r .global.pattern values-global.yaml))
@if [ $(NAME) != $(GLOBAL_PATTERN) ]; then\
echo "";\
echo "WARNING: folder directory is \"$(NAME)\" and global.pattern is set to \"$(GLOBAL_PATTERN)\"";\
echo "this can create problems. Please make sure they are the same!";\
echo "";\
fi
@common/scripts/validate-names-length.sh
@if [ ! -f /run/.containerenv ]; then\
echo "Checking prerequisites:";\
echo -n " Check for python-kubernetes: ";\
Expand Down
2 changes: 1 addition & 1 deletion scripts/pattern-util.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function version {
}

if [ -z "$PATTERN_UTILITY_CONTAINER" ]; then
PATTERN_UTILITY_CONTAINER="quay.io/hybridcloudpatterns/utility-container"
PATTERN_UTILITY_CONTAINER="quay.io/validatedpatterns/utility-container"
fi
# If PATTERN_DISCONNECTED_HOME is set it will be used to populate both PATTERN_UTILITY_CONTAINER
# and PATTERN_INSTALL_CHART automatically
Expand Down
65 changes: 65 additions & 0 deletions scripts/validate-names-length.sh
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