Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DEV (kubevirtci): allow redploying the operator/webhook #3208

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,12 @@ cluster-down:
cluster-sync:
IMAGE_REGISTRY=$(IMAGE_REGISTRY) REGISTRY_NAMESPACE=$(REGISTRY_NAMESPACE) ./cluster/sync.sh

cluster-redeploy-operator:
IMAGE_REGISTRY=$(IMAGE_REGISTRY) REGISTRY_NAMESPACE=$(REGISTRY_NAMESPACE) ./cluster/sync-pod.sh operator

cluster-redeploy-webhook:
IMAGE_REGISTRY=$(IMAGE_REGISTRY) REGISTRY_NAMESPACE=$(REGISTRY_NAMESPACE) ./cluster/sync-pod.sh webhook

cluster-clean:
CMD="./cluster/kubectl.sh" ./hack/clean.sh

Expand Down Expand Up @@ -267,6 +273,8 @@ bump-hco:
cluster-up \
cluster-down \
cluster-sync \
cluster-redeploy-operator \
cluster-redeploy-webhook \
cluster-clean \
stageRegistry \
functest \
Expand Down
50 changes: 50 additions & 0 deletions cluster/sync-pod.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/bin/bash -ex

source ./hack/common.sh
source ./_kubevirtci/cluster-up/cluster/ephemeral-provider-common.sh

function set_env() {
if [ ${KUBEVIRT_PROVIDER} != "external" ]; then
registry_port=$(${_cri_bin} ps | grep -Po '(?<=0.0.0.0:)\d+(?=->5000\/tcp)' | head -n 1)
if [ -z "$registry_port" ]; then
>&2 echo "unable to get the registry port"
exit 1
fi
export IMAGE_REGISTRY=localhost:$registry_port
export REGISTRY=registry:5000
export CMD="./cluster/kubectl.sh"
else
if [ "${REGISTRY_NAMESPACE}" == "kubevirt" ]; then
echo "REGISTRY_NAMESPACE cant be kubevirt when using KUBEVIRT_PROVIDER=external"
exit 1
fi
export REGISTRY=$IMAGE_REGISTRY
export CMD="oc"
fi
}

component_name=$1
if [[ "${component_name}" != "operator" && "${component_name}" != "webhook" ]]; then
echo "must use $0 with \"operator\" or \"webhook\""
exit 1
fi

deployment_name="hyperconverged-cluster-${component_name}"

set_env

# get original number of replicas
replicas=$(${CMD} get deployment -n kubevirt-hyperconverged ${deployment_name} -o jsonpath='{ .spec.replicas }')
# make sure the restarting the pod, will force it to use the new image
num_cont=$(${CMD} get deployment -n kubevirt-hyperconverged ${deployment_name} -o json | jq '.spec.template.spec.containers | length')
for i in $(seq $num_cont); do
ind=$((i-1))
${CMD} patch deployment -n kubevirt-hyperconverged ${deployment_name} --type=json --patch '[{"op": "replace", "path": "/spec/template/spec/containers/'${ind}'/imagePullPolicy", "value": "Always"}]'
done
# rebuild the image and replace it in the registry
make container-build-${component_name} container-push-${component_name}
# restarting the pod, to force taking the new image
${CMD} scale deployment -n kubevirt-hyperconverged ${deployment_name} --replicas=0
${CMD} scale deployment -n kubevirt-hyperconverged ${deployment_name} --replicas=${replicas}
# make sure the new deployment is ready
${CMD} wait deployment -n kubevirt-hyperconverged ${deployment_name} --for=condition=Available
Loading