Skip to content

Commit

Permalink
Use values instead of custom_tag logic, fix issues with mirantis repos
Browse files Browse the repository at this point in the history
Signed-off-by: Kyle Squizzato <[email protected]>
  • Loading branch information
squizzi committed Nov 1, 2024
1 parent aa8184d commit 128ad6d
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 27 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,12 @@ TEMPLATE_FOLDERS = $(patsubst $(TEMPLATES_DIR)/%,%,$(wildcard $(TEMPLATES_DIR)/*
helm-package: $(CHARTS_PACKAGE_DIR) $(EXTENSION_CHARTS_PACKAGE_DIR) helm
@make $(patsubst %,package-%-tmpl,$(TEMPLATE_FOLDERS))

bundle-images: $(IMAGES_PACKAGE_DIR) ## Create a tarball with all images used by HMC.
bundle-images: dev-apply $(IMAGES_PACKAGE_DIR) ## Create a tarball with all images used by HMC.
@BUNDLE_TARBALL=$(IMAGES_PACKAGE_DIR)/hmc-images-$(VERSION).tgz EXTENSIONS_BUNDLE_TARBALL=$(IMAGES_PACKAGE_DIR)/hmc-extension-images-$(VERSION).tgz IMG=$(IMG) KUBECTL=$(KUBECTL) YQ=$(YQ) HELM=$(HELM) NAMESPACE=$(NAMESPACE) TEMPLATES_DIR=$(TEMPLATES_DIR) KIND_CLUSTER_NAME=$(KIND_CLUSTER_NAME) $(SHELL) "scripts/bundle-images.sh"

airgap-package: bundle-images ## Create a tarball with all images and Helm charts used by HMC, useful for deploying in air-gapped environments.
@TEMPLATES_DIR=$(TEMPLATES_DIR) EXTENSION_CHARTS_PACKAGE_DIR=$(EXTENSION_CHARTS_PACKAGE_DIR) YQ=$(YQ) $(SHELL) "scripts/package-k0s-extensions-helm.sh"
tar -czf hmc-charts-images-$(VERSION).tgz ./scripts/airgap-push.sh $(CHARTS_PACKAGE_DIR) $(IMAGES_PACKAGE_DIR)
@TEMPLATES_DIR=$(TEMPLATES_DIR) EXTENSION_CHARTS_PACKAGE_DIR=$(EXTENSION_CHARTS_PACKAGE_DIR) HELM=$(HELM) YQ=$(YQ) $(SHELL) "scripts/package-k0s-extensions-helm.sh"
tar -czf hmc-charts-images-$(VERSION).tgz -C $(LOCALBIN) ./scripts/airgap-push.sh $(CHARTS_PACKAGE_DIR) $(IMAGES_PACKAGE_DIR)

package-%-tmpl:
@make TEMPLATES_SUBDIR=$(TEMPLATES_DIR)/$* $(patsubst %,package-chart-%,$(shell ls $(TEMPLATES_DIR)/$*))
Expand Down
30 changes: 11 additions & 19 deletions scripts/bundle-images.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,11 @@
# this scripts functionality.
# Usage: make bundle-images
# This script should not be run directly. Use 'make bundle-images' instead.
set -x

LABEL_KEY="cluster.x-k8s.io/provider"
IMAGES_BUNDLED="$IMG"
EXTENSION_IMAGES_BUNDLED=""

echo -e "\nBundling images for HMC, this may take awhile...\n"
echo -e "Bundling images for HMC, this may take awhile...\n"

trap ctrl_c INT

Expand Down Expand Up @@ -167,30 +165,22 @@ do
repos=$(grep -vw "{{" $template | $YQ e "${extensions_path}.repositories[] | [.url, .name] | join(\";\")")
for repo in $repos
do
URL=$(echo $repo | cut -d';' -f1)
NAME=$(echo $repo | cut -d';' -f2)

url=$(echo $repo | cut -d';' -f1)
chartname=$(echo $repo | cut -d';' -f2)
version=$(grep -vw "{{" $template |
$YQ e "${extensions_path}.charts[] | select(.name == \"$name\") | .version")

values=$(grep -vw "{{" $template |
$YQ e "${extensions_path}.charts[] | select(.name == \"$name\") | .values")
$YQ e "${extensions_path}.charts[] | select(.chartname == \"*$chartname*\") | .version")
name=$(grep -vw "{{" $template |
$YQ e "${extensions_path}.charts[] | select(.chartname == \"*$chartname*\") | .name")
grep -vw "{{" $template | $YQ e "${extensions_path}.charts[] | select(.chartname == \"*$chartname*\") | .values" > $name-values.yaml

if [[ $url == "" ]] || [[ $name == "" ]] || [[ $version == "" ]]; then
echo "Error: Failed to get URL, name, or version from $template"
exit 1
fi

# Check to see if a custom image is being used.
custom_tag=$(echo -e "$values" | $YQ e '.image.tag' -)

# Use 'helm template' to get the images used by the extension.
for image in $($HELM template --repo $url --version $version $name | $YQ -N e .spec.template.spec.containers[].image);
for image in $($HELM template --repo $url --version $version $name --values $name-values.yaml | $YQ -N e .spec.template.spec.containers[].image);
do
if [[ $custom_tag != "null" ]] || [[ -z $custom_tag ]]; then
image=$(echo $image | sed -e "s/:.*$/:$custom_tag/")
fi

docker pull $image
if [[ $? -ne 0 ]]; then
echo "Error: Failed to pull $image"
Expand All @@ -199,6 +189,8 @@ do

EXTENSION_IMAGES_BUNDLED="$EXTENSION_IMAGES_BUNDLED $image"
done

rm $name-values.yaml
done
done

Expand All @@ -225,4 +217,4 @@ do
fi
done

echo "Done! Images bundled into $BUNDLE_TARBALL"
echo "Done! Images bundled into $BUNDLE_TARBALL and $EXTENSIONS_BUNDLE_TARBALL"
7 changes: 4 additions & 3 deletions scripts/package-k0s-extensions-helm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@ for template in $(find $TEMPLATES_DIR -name 'k0s*.yaml'); do
repos=$(grep -vw "{{" $template | $YQ e "$extensions_path.repositories[] | [.url, .name] | join(\";\")")
for repo in $repos; do
url=$(echo $repo | cut -d';' -f1)
name=$(echo $repo | cut -d';' -f2)
version=$(grep -vw "{{" $template | $YQ e "$extensions_path.charts[] | select(.name == \"$name\") | .version")
chartname=$(echo $repo | cut -d';' -f2)
version=$(grep -vw "{{" $template | $YQ e "$extensions_path.charts[] | select(.chartname == \"*$chartname*\") | .version")
name=$(grep -vw "{{" $template | $YQ e "${extensions_path}.charts[] | select(.chartname == \"*$chartname*\") | .name")
if [[ $url == "" ]] || [[ $name == "" ]] || [[ $version == "" ]]; then
echo "Error: Cannot construct Helm pull command from url: $url, name: $name, version: $version: one or more vars is not populated"
exit 1
fi
if [[ ! $(find $EXTENSION_CHARTS_PACKAGE_DIR -name $name-$version*.tgz) ]]; then
echo "Helm chart $name from $url with version $version"
echo "Pulling Helm chart $name from $url with version $version"
$HELM pull --repo $url --version $version $name -d $EXTENSION_CHARTS_PACKAGE_DIR
fi
done
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ spec:
- key: CriticalAddonsOnly
effect: NoExecute
operator: Exists
- name: vsphere-csi
- name: vsphere-csi-driver
chartname: mirantis/vsphere-csi-driver
version: 0.0.2
order: 2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ spec:
- key: CriticalAddonsOnly
effect: NoExecute
operator: Exists
- name: vsphere-csi
- name: vsphere-csi-driver
chartname: mirantis/vsphere-csi-driver
version: 0.0.2
order: 3
Expand Down

0 comments on commit 128ad6d

Please sign in to comment.