Skip to content

Commit e61222d

Browse files
committed
return 1 in ci-entrypoint funcs when necessary
1 parent 859a81e commit e61222d

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

scripts/ci-entrypoint.sh

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,11 @@ create_cluster() {
148148
# and any statement must be idempotent so that subsequent retry attempts can make forward progress.
149149
get_cidrs() {
150150
# Get cluster CIDRs from Cluster object
151-
CIDR0=$(${KUBECTL} --kubeconfig "${REPO_ROOT}/${KIND_CLUSTER_NAME}.kubeconfig" get cluster "${CLUSTER_NAME}" -o=jsonpath='{.spec.clusterNetwork.pods.cidrBlocks[0]}')
151+
CIDR0=$(${KUBECTL} --kubeconfig "${REPO_ROOT}/${KIND_CLUSTER_NAME}.kubeconfig" get cluster "${CLUSTER_NAME}" -o=jsonpath='{.spec.clusterNetwork.pods.cidrBlocks[0]}') || return 1
152152
export CIDR0
153-
CIDR_LENGTH=$(${KUBECTL} --kubeconfig "${REPO_ROOT}/${KIND_CLUSTER_NAME}.kubeconfig" get cluster "${CLUSTER_NAME}" -o=jsonpath='{.spec.clusterNetwork.pods.cidrBlocks}' | jq '. | length')
153+
CIDR_LENGTH=$(${KUBECTL} --kubeconfig "${REPO_ROOT}/${KIND_CLUSTER_NAME}.kubeconfig" get cluster "${CLUSTER_NAME}" -o=jsonpath='{.spec.clusterNetwork.pods.cidrBlocks}' | jq '. | length') || return 1
154154
if [[ "${CIDR_LENGTH}" == "2" ]]; then
155-
CIDR1=$(${KUBECTL} get cluster --kubeconfig "${REPO_ROOT}/${KIND_CLUSTER_NAME}.kubeconfig" "${CLUSTER_NAME}" -o=jsonpath='{.spec.clusterNetwork.pods.cidrBlocks[1]}')
155+
CIDR1=$(${KUBECTL} get cluster --kubeconfig "${REPO_ROOT}/${KIND_CLUSTER_NAME}.kubeconfig" "${CLUSTER_NAME}" -o=jsonpath='{.spec.clusterNetwork.pods.cidrBlocks[1]}') || return 1
156156
export CIDR1
157157
fi
158158
}
@@ -162,7 +162,7 @@ get_cidrs() {
162162
# retry it using a `until get_cloud_provider; do sleep 5; done` pattern;
163163
# and any statement must be idempotent so that subsequent retry attempts can make forward progress.
164164
get_cloud_provider() {
165-
CLOUD_PROVIDER=$("${KUBECTL}" --kubeconfig "${REPO_ROOT}/${KIND_CLUSTER_NAME}.kubeconfig" get kubeadmcontrolplane -l cluster.x-k8s.io/cluster-name="${CLUSTER_NAME}" -o=jsonpath='{.items[0].spec.kubeadmConfigSpec.clusterConfiguration.controllerManager.extraArgs.cloud-provider}')
165+
CLOUD_PROVIDER=$("${KUBECTL}" --kubeconfig "${REPO_ROOT}/${KIND_CLUSTER_NAME}.kubeconfig" get kubeadmcontrolplane -l cluster.x-k8s.io/cluster-name="${CLUSTER_NAME}" -o=jsonpath='{.items[0].spec.kubeadmConfigSpec.clusterConfiguration.controllerManager.extraArgs.cloud-provider}') || return 1
166166
if [[ "${CLOUD_PROVIDER:-}" = "azure" ]]; then
167167
IN_TREE="true"
168168
export IN_TREE
@@ -177,10 +177,12 @@ install_calico() {
177177
# Copy the kubeadm configmap to the calico-system namespace.
178178
# This is a workaround needed for the calico-node-windows daemonset
179179
# to be able to run in the calico-system namespace.
180-
"${KUBECTL}" create namespace calico-system --dry-run=client -o yaml | kubectl apply -f -
180+
# First, validate that the kubeadm-config configmap has been created.
181+
"${KUBECTL}" get configmap kubeadm-config --namespace=kube-system -o yaml || return 1
182+
"${KUBECTL}" create namespace calico-system --dry-run=client -o yaml | kubectl apply -f - || return 1
181183
if ! "${KUBECTL}" get configmap kubeadm-config --namespace=calico-system; then
182-
"${KUBECTL}" get configmap kubeadm-config --namespace=kube-system -o yaml > kubeadm-config-kube-system
183-
sed 's/namespace: kube-system/namespace: calico-system/' kubeadm-config-kube-system | "${KUBECTL}" apply -f -
184+
"${KUBECTL}" get configmap kubeadm-config --namespace=kube-system -o yaml > kubeadm-config-kube-system || return 1
185+
sed 's/namespace: kube-system/namespace: calico-system/' kubeadm-config-kube-system | "${KUBECTL}" apply -f - || return 1
184186
rm kubeadm-config-kube-system
185187
fi
186188
# install Calico CNI
@@ -213,7 +215,7 @@ install_cloud_provider_azure() {
213215
CLOUD_CONFIG=""
214216
CONFIG_SECRET_NAME="azure-cloud-provider"
215217
ENABLE_DYNAMIC_RELOADING=true
216-
copy_secret
218+
copy_secret || return 1
217219
fi
218220

219221
CCM_CLUSTER_CIDR="${CIDR0}"
@@ -231,7 +233,7 @@ install_cloud_provider_azure() {
231233
--set cloudControllerManager.cloudConfig="${CLOUD_CONFIG}" \
232234
--set cloudControllerManager.cloudConfigSecretName="${CONFIG_SECRET_NAME}" \
233235
--set cloudControllerManager.logVerbosity="${CCM_LOG_VERBOSITY}" \
234-
--set-string cloudControllerManager.clusterCIDR="${CCM_CLUSTER_CIDR}" "${CCM_IMG_ARGS[@]}"
236+
--set-string cloudControllerManager.clusterCIDR="${CCM_CLUSTER_CIDR}" "${CCM_IMG_ARGS[@]}" || return 1
235237
}
236238

237239
# wait_for_nodes returns when all nodes in the workload cluster are Ready.
@@ -299,11 +301,11 @@ install_addons() {
299301

300302
copy_secret() {
301303
# point at the management cluster
302-
"${KUBECTL}" --kubeconfig "${REPO_ROOT}/${KIND_CLUSTER_NAME}.kubeconfig" get secret "${CLUSTER_NAME}-control-plane-azure-json" -o jsonpath='{.data.control-plane-azure\.json}' | base64 --decode >azure_json
304+
"${KUBECTL}" --kubeconfig "${REPO_ROOT}/${KIND_CLUSTER_NAME}.kubeconfig" get secret "${CLUSTER_NAME}-control-plane-azure-json" -o jsonpath='{.data.control-plane-azure\.json}' | base64 --decode >azure_json || return 1
303305

304306
# create the secret on the workload cluster
305307
"${KUBECTL}" create secret generic "${CONFIG_SECRET_NAME}" -n kube-system \
306-
--from-file=cloud-config=azure_json
308+
--from-file=cloud-config=azure_json || return 1
307309
rm azure_json
308310
}
309311

0 commit comments

Comments
 (0)