Add kubectl-wait-cluster-ephemeral phase

This adds a phase to wait for the target cluster to become initialized,
directed at the ephemeral management cluster.  It re-uses the helper script
already used by the `kubectl-wait-cluster-target` phase, adds parameterization
so that it can watch for both controlPlaneInitialized and controlPlaneReady
conditions, and adds the new phase to the phase plan.

Lack of this waiting was causing errors in some environments.

This also adds a kubectl-wait-node-target phase definition,
in case we ever want to make use of it.

Change-Id: Ic18742dd59a7901b0d985b8c11260bc1b3527a30
This commit is contained in:
Matt McEuen 2021-07-14 12:30:47 -05:00
parent e2e8732fed
commit 2b429eb810
4 changed files with 50 additions and 4 deletions

View File

@ -15,28 +15,29 @@
set -xe
export TIMEOUT=${TIMEOUT:-3600}
export CONDITION=${CONDITION:-"controlPlaneReady"}
end=$(($(date +%s) + $TIMEOUT))
echo "Waiting $TIMEOUT seconds for cluster to reach controlPlaneReady condition" 1>&2
echo "Waiting $TIMEOUT seconds for cluster to reach $CONDITION condition" 1>&2
while true; do
# TODO(vkuzmin): Add ability to wait for multiple clusters
if [ "$(kubectl \
--request-timeout 20s \
--context $KCTL_CONTEXT \
get -f $RENDERED_BUNDLE_PATH \
-o jsonpath='{.status.controlPlaneReady}')" == "true" ]
-o jsonpath={.status.$CONDITION})" == "true" ]
then
echo "Getting information about cluster" 1>&2
kubectl \
--request-timeout 20s \
--context $KCTL_CONTEXT \
get -f $RENDERED_BUNDLE_PATH 1>&2
echo "Cluster successfully reach controlPlaneReady condition" 1>&2
echo "Cluster successfully reach $CONDITION condition" 1>&2
break
else
now=$(date +%s)
if [ $now -gt $end ]; then
echo "Cluster didn't reach controlPlaneReady condition before TIMEOUT=$TIMEOUT, exiting" 1>&2
echo "Cluster didn't reach $CONDITION condition before TIMEOUT=$TIMEOUT, exiting" 1>&2
exit 1
fi
sleep 15

View File

@ -433,6 +433,23 @@ configRef:
---
apiVersion: airshipit.org/v1alpha1
kind: GenericContainer
metadata:
name: kubectl-wait-cluster-init
spec:
image: localhost/toolbox
hostNetwork: true
envVars:
- RESOURCE_GROUP_FILTER=cluster.x-k8s.io
- RESOURCE_VERSION_FILTER=v1alpha3
- RESOURCE_KIND_FILTER=Cluster
- CONDITION=controlPlaneInitialized
configRef:
kind: ConfigMap
name: kubectl-wait-cluster
apiVersion: v1
---
apiVersion: airshipit.org/v1alpha1
kind: GenericContainer
metadata:
name: virsh-eject-cdrom-images
labels:

View File

@ -291,6 +291,17 @@ config:
---
apiVersion: airshipit.org/v1alpha1
kind: Phase
metadata:
name: kubectl-wait-node-target
clusterName: target-cluster
config:
executorRef:
apiVersion: airshipit.org/v1alpha1
kind: GenericContainer
name: kubectl-wait-node
---
apiVersion: airshipit.org/v1alpha1
kind: Phase
metadata:
name: kubectl-get-node-target
clusterName: target-cluster
@ -391,6 +402,18 @@ config:
---
apiVersion: airshipit.org/v1alpha1
kind: Phase
metadata:
name: kubectl-wait-cluster-ephemeral
clusterName: ephemeral-cluster
config:
executorRef:
apiVersion: airshipit.org/v1alpha1
kind: GenericContainer
name: kubectl-wait-cluster-init
documentEntryPoint: ephemeral/controlplane
---
apiVersion: airshipit.org/v1alpha1
kind: Phase
metadata:
name: kubectl-wait-cluster-target
clusterName: target-cluster

View File

@ -49,6 +49,11 @@ phases:
- name: virsh-eject-cdrom-images
# Create target k8s cluster resources
- name: controlplane-ephemeral
# Wait till the cluster is created
# Scripts for this phase placed in manifests/function/phase-helpers/wait_cluster/
# To get ConfigMap for this phase, execute `airshipctl phase render --source config -k ConfigMap`
# and find ConfigMap with name kubectl-wait-cluster
- name: kubectl-wait-cluster-ephemeral
# List all nodes in target cluster
# Scripts for this phase placed in manifests/function/phase-helpers/get_node/
# To get ConfigMap for this phase, execute `airshipctl phase render --source config -k ConfigMap`