Skip to content

Commit

Permalink
Fix various issues with scripts
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 ecb4a00 commit aa8184d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
8 changes: 3 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ CONTAINER_TOOL ?= docker
SHELL = /usr/bin/env bash -o pipefail
.SHELLFLAGS = -ec

.EXPORT_ALL_VARIABLES:

.PHONY: all
all: build

Expand Down Expand Up @@ -149,12 +147,12 @@ TEMPLATE_FOLDERS = $(patsubst $(TEMPLATES_DIR)/%,%,$(wildcard $(TEMPLATES_DIR)/*
.PHONY: helm-package
helm-package: $(CHARTS_PACKAGE_DIR) $(EXTENSION_CHARTS_PACKAGE_DIR) helm
@make $(patsubst %,package-%-tmpl,$(TEMPLATE_FOLDERS))
@$(SHELL) "scripts/helm-package.sh"

bundle-images: $(IMAGES_PACKAGE_DIR) ## Create a tarball with all images used by HMC.
@$(SHELL) "scripts/bundle-images.sh"
@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: helm-package bundle-images ## Create a tarball with all images and Helm charts used by HMC, useful for deploying in air-gapped environments.
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)

package-%-tmpl:
Expand Down
5 changes: 3 additions & 2 deletions scripts/bundle-images.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# 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"
Expand All @@ -35,7 +36,6 @@ function wait_for_deploy_exist() {
local interval_secs=5
local start_time


start_time=$(date +%s)

echo "Verifying provider Deployment with label: \"$deployment_label\" exists in namespace: \"$NAMESPACE\"..."
Expand All @@ -49,10 +49,11 @@ function wait_for_deploy_exist() {

output=$($KUBECTL -n "$NAMESPACE" get deploy -l $deployment_label)

if [[ output != "" ]]; then
if [[ $output != "" ]]; then
echo "Deployment in namespace: \"$NAMESPACE\" with label: \"$deployment_label\" exists."
break
else
echo "Deployment with label: \"$deployment_label\" in namespace: \"$NAMESPACE\" does not exist yet. Waiting $interval_secs seconds..."
sleep $interval_secs
fi
done
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,28 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# This script packages Helm charts affiliated with k0s extensions for airgap
# installations.
# This script should not be run directly. Use 'make airgap-package' instead.
for template in $(find $TEMPLATES_DIR -name 'k0s*.yaml'); do
if [[ $template == *"k0smotron"* ]]; then
extensions_path=".spec.k0sConfig.spec.extensions.helm"
else
extensions_path=".spec.k0sConfigSpec.k0s.spec.extensions.helm"
fi

repos=$(grep -vw "{{" $template | $(YQ) e "$extensions_path.repositories[] | [.url, .name] | join(\";\")")
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")
version=$(grep -vw "{{" $template | $YQ e "$extensions_path.charts[] | select(.name == \"$name\") | .version")
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
if [[ ! $(find $EXTENSION_CHARTS_PACKAGE_DIR -name $name-$version*.tgz) ]]; then
echo "Helm chart $name from $url with version $version"
$(HELM) pull --repo $url --version $version $name -d $(EXTENSION_CHARTS_PACKAGE_DIR)
$HELM pull --repo $url --version $version $name -d $EXTENSION_CHARTS_PACKAGE_DIR
fi
done
done

0 comments on commit aa8184d

Please sign in to comment.