Skip to content

Commit 9b33c4f

Browse files
authored
Merge pull request #418 from mbaldessari/common-automatic-update
common automatic update
2 parents 7aa4105 + 73fdad0 commit 9b33c4f

File tree

2 files changed

+40
-8
lines changed

2 files changed

+40
-8
lines changed

common/Makefile

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,7 @@ preview-%:
6868

6969
.PHONY: operator-deploy
7070
operator-deploy operator-upgrade: validate-prereq validate-origin validate-cluster ## runs helm install
71-
@set -e -o pipefail
72-
# Retry five times because the CRD might not be fully installed yet
73-
for i in {1..5}; do \
74-
helm template --include-crds --name-template $(NAME) $(PATTERN_INSTALL_CHART) $(HELM_OPTS) | oc apply -f- && break || sleep 10; \
75-
done
71+
@common/scripts/deploy-pattern.sh $(NAME) $(PATTERN_INSTALL_CHART) $(HELM_OPTS)
7672

7773
.PHONY: uninstall
7874
uninstall: ## runs helm uninstall
@@ -129,12 +125,22 @@ token-kubeconfig: ## Create a local ~/.kube/config with password (not usually ne
129125

130126
# We only check the remote ssh git branch's existance if we're not running inside a container
131127
# as getting ssh auth working inside a container seems a bit brittle
128+
# If the main repoUpstreamURL field is set, then we need to check against
129+
# that and not target_repo
132130
.PHONY: validate-origin
133131
validate-origin: ## verify the git origin is available
134132
@echo "Checking repository:"
135-
@echo -n " $(TARGET_REPO) - branch '$(TARGET_BRANCH)': "
136-
@git ls-remote --exit-code --heads $(TARGET_REPO) $(TARGET_BRANCH) >/dev/null &&\
137-
echo "OK" || (echo "NOT FOUND"; exit 1)
133+
$(eval UPSTREAMURL := $(shell yq -r '.main.git.repoUpstreamURL // (.main.git.repoUpstreamURL = "")' values-global.yaml))
134+
@if [ -z "$(UPSTREAMURL)" ]; then\
135+
echo -n " $(TARGET_REPO) - branch '$(TARGET_BRANCH)': ";\
136+
git ls-remote --exit-code --heads $(TARGET_REPO) $(TARGET_BRANCH) >/dev/null &&\
137+
echo "OK" || (echo "NOT FOUND"; exit 1);\
138+
else\
139+
echo "Upstream URL set to: $(UPSTREAMURL)";\
140+
echo -n " $(UPSTREAMURL) - branch '$(TARGET_BRANCH)': ";\
141+
git ls-remote --exit-code --heads $(UPSTREAMURL) $(TARGET_BRANCH) >/dev/null &&\
142+
echo "OK" || (echo "NOT FOUND"; exit 1);\
143+
fi
138144

139145
.PHONY: validate-cluster
140146
validate-cluster: ## Do some cluster validations before installing

common/scripts/deploy-pattern.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/bash
2+
set -o pipefail
3+
4+
RUNS=5
5+
# Retry five times because the CRD might not be fully installed yet
6+
echo -n "Installing pattern: "
7+
for i in $(seq 1 ${RUNS}); do \
8+
exec 3>&1 4>&2
9+
OUT=$( { helm template --include-crds --name-template $* 2>&4 | oc apply -f- 2>&4 1>&3; } 4>&1 3>&1)
10+
exec 3>&- 4>&-
11+
ret=$?
12+
if [ ${ret} -eq 0 ]; then
13+
break;
14+
else
15+
echo -n "."
16+
sleep 10
17+
fi
18+
done
19+
20+
# All the runs failed
21+
if [ ${i} -eq ${RUNS} ]; then
22+
echo "Installation failed [${i}/${RUNS}]. Error:"
23+
echo "${OUT}"
24+
exit 1
25+
fi
26+
echo "Done"

0 commit comments

Comments
 (0)