Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,22 @@ set -e
export ARTIFACT_DIR=${ARTIFACT_DIR:-/tmp}

export CAPI_NAMESPACE="openshift-cluster-api"
export CAPI_OPERATOR_NAMESPACE="openshift-cluster-api-operator"


# isOCPVersionLowerThan returns 0 if the current OCP version is lower than the required version, 1 otherwise
function isOCPVersionLowerThan() {
local required_version="${1}"
local version
version=$(oc get clusterversion version -o jsonpath='{.status.desired.version}')
# If version sorted last, it means version >= required, so return 1 (not lower than)
if [[ $(echo -e "${required_version}\n${version}" | sort -V | tail -n 1) == "${version}" ]]; then
return 1
else
return 0
fi
}
export -f isOCPVersionLowerThan

function applyFeatureGate() {
echo "$(date -u --rfc-3339=seconds) - Apply TechPreviewNoUpgrade FeatureGate configuration"
Expand Down Expand Up @@ -34,24 +50,38 @@ function waitForClusterOperatorsRollout() {
}

function waitForRunningPod() {
local REGEXP="${1}"
local MSG="${1}"
local NAMESPACE="${1}"
local REGEXP="${2}"
local MSG="${3}"

while [ "$(oc get pods -n ${CAPI_NAMESPACE} -o name | grep "${REGEXP}" | wc -l)" == 0 ]; do
while [ "$(oc get pods -n ${NAMESPACE} -o name | grep "${REGEXP}" | wc -l)" == 0 ]; do
echo "$(date -u --rfc-3339=seconds) - ${MSG}"
sleep 5
done
}
export -f waitForRunningPod

function ClusterCAPIOperatorPodsCreated() {
waitForRunningPod "cluster-capi-operator" "Waiting for cluster-capi-operator creation"
waitForRunningPod "capi-controller-manager" "Waiting for capi-controller-manager creation"
# OCP >= 4.22: new namespace/deployments structure (see: https://github.com/openshift/cluster-capi-operator/pull/447)
if isOCPVersionLowerThan 4.22; then
waitForRunningPod "${CAPI_NAMESPACE}" "cluster-capi-operator" "Waiting for cluster-capi-operator creation"
else
waitForRunningPod "${CAPI_OPERATOR_NAMESPACE}" "capi-operator" "Waiting for capi-operator creation"
waitForRunningPod "${CAPI_NAMESPACE}" "capi-controllers" "Waiting for capi-controllers creation"
fi

waitForRunningPod "${CAPI_NAMESPACE}" "capi-controller-manager" "Waiting for capi-controller-manager creation"
}
export -f ClusterCAPIOperatorPodsCreated

function waitForClusterCAPIOperatorPodsReadiness() {
echo "$(date -u --rfc-3339=seconds) - Wait for CAPI operands to be ready"
# OCP >= 4.22: new namespace/deployments structure (see: https://github.com/openshift/cluster-capi-operator/pull/447)
if ! isOCPVersionLowerThan 4.22; then
echo "$(date -u --rfc-3339=seconds) - Wait for openshift-cluster-api-operator components to be ready"
waitFor 10m oc wait --all -n "${CAPI_OPERATOR_NAMESPACE}" --for=condition=ready pods
fi

echo "$(date -u --rfc-3339=seconds) - Wait for openshift-cluster-api components to be ready"
waitFor 10m oc wait --all -n "${CAPI_NAMESPACE}" --for=condition=ready pods
}

Expand Down