diff --git a/bin/gcp-cluster-postsync-hook.sh b/bin/gcp-cluster-postsync-hook.sh index 8c1d477..30bb807 100755 --- a/bin/gcp-cluster-postsync-hook.sh +++ b/bin/gcp-cluster-postsync-hook.sh @@ -3,7 +3,7 @@ set -e RELEASE_NAME="${1}" -NAMESPACE="${2:-gcp}" +NAMESPACE="${2:-capg-system}" LIMIT="${3:-1200}" GO_TEMPLATE=' diff --git a/bin/gcp-cluster-presync-hook.sh b/bin/gcp-cluster-presync-hook.sh new file mode 100755 index 0000000..1c5c71c --- /dev/null +++ b/bin/gcp-cluster-presync-hook.sh @@ -0,0 +1,27 @@ +#!/usr/bin/env bash + +set -e + +NAMESPACE="${1:-capg-system}" +REGISTRY="${2}" +VERSION="${3}" + +readonly CONTROLLER_MANAGER_NAME=capg-controller-manager +readonly CONTROLLER_MANAGER_CONTAINER_NAME=manager + +if [[ -n "${REGISTRY}" && -n "${VERSION}" ]]; then + IMAGE="${REGISTRY}:${VERSION}" +else + exit 0 +fi + +if (kubectl --namespace "${NAMESPACE}" get deployment "${CONTROLLER_MANAGER_NAME}" &> /dev/null); then + CURRENT_IMAGE="$(kubectl --namespace "${NAMESPACE}" get deployment "${CONTROLLER_MANAGER_NAME}" --output yaml \ + | yq '.spec.template.spec.containers[] | select(.name == "'"${CONTROLLER_MANAGER_CONTAINER_NAME}"'") | .image')" + + if [[ "${CURRENT_IMAGE}" != "${IMAGE}" ]]; then + kubectl --namespace "${NAMESPACE}" \ + set image deployment "${CONTROLLER_MANAGER_NAME}" "${CONTROLLER_MANAGER_CONTAINER_NAME}=${IMAGE}" + kubectl --namespace "${NAMESPACE}" rollout status deployment "${CONTROLLER_MANAGER_NAME}" + fi +fi diff --git a/bin/gcp-cluster-uninstall-hook.sh b/bin/gcp-cluster-uninstall-hook.sh index a10a81b..1f979a1 100755 --- a/bin/gcp-cluster-uninstall-hook.sh +++ b/bin/gcp-cluster-uninstall-hook.sh @@ -3,7 +3,7 @@ set -e CLUSTER_NAME="${1}" -NAMESPACE="${2}" +NAMESPACE="${2:-capg-system}" WAIT_FOR_CLUSTER_DELETION="${3:-false}" kubectl --namespace "${NAMESPACE}" delete cluster "${CLUSTER_NAME}" "--wait=${WAIT_FOR_CLUSTER_DELETION}"