Skip to content

Commit

Permalink
support older bash versions in generate-flavors.sh (#446)
Browse files Browse the repository at this point in the history
  • Loading branch information
eljohnson92 authored Aug 8, 2024
1 parent b42aba6 commit 8ab18ac
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions hack/generate-flavors.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@ SUPPORTED_CLUSTERCLASSES=(
"clusterclass-kubeadm"
)

declare -A CERT_HOSTPATH=( ["rke2"]="/var/lib/rancher/rke2/server/tls" ["k3s"]="/var/lib/rancher/k3s/server/tls" ["kubeadm"]="/etc/kubernetes/pki")
declare -A CACERT=( ["rke2"]="server-ca.crt" ["k3s"]="server-ca.crt" ["kubeadm"]="ca.crt")
declare -A CERT=( ["rke2"]="server-client.crt" ["k3s"]="server-client.crt" ["kubeadm"]="healthcheck-client.crt")
declare -A KEY=( ["rke2"]="server-client.key" ["k3s"]="server-client.key" ["kubeadm"]="healthcheck-client.key")

for clusterclass in ${SUPPORTED_CLUSTERCLASSES[@]}; do
# clusterctl expects clusterclass not have the "cluster-template" prefix
# except for the actual cluster template using the clusterclass
Expand All @@ -28,6 +23,22 @@ done


for distro in ${SUPPORTED_DISTROS[@]}; do
if [[ ${distro} == "kubeadm" ]]; then
CACERT="ca.crt"
CERT="healthcheck-client.crt"
KEY="healthcheck-client.key"
CERT_HOSTPATH="/etc/kubernetes/pki"
elif [[ ${distro} == "k3s" ]]; then
CACERT="server-ca.crt"
CERT="server-client.crt"
KEY="server-client.key"
CERT_HOSTPATH="/var/lib/rancher/k3s/server/tls"
elif [[ ${distro} == "rke2" ]]; then
CACERT="server-ca.crt"
CERT="server-client.crt"
KEY="server-client.key"
CERT_HOSTPATH="/var/lib/rancher/rke2/server/tls"
fi
for name in $(find "${FLAVORS_DIR}/${distro}/"* -maxdepth 0 -type d -print0 | xargs -0 -I {} basename {}); do
if [[ ${name} == "default" ]]; then
echo "****** Generating ${distro} flavor ******"
Expand All @@ -36,7 +47,7 @@ for distro in ${SUPPORTED_DISTROS[@]}; do
echo "****** Generating ${distro}-${name} flavor ******"
kustomize build "${FLAVORS_DIR}/${distro}/${name}" > "${REPO_ROOT}/templates/cluster-template-${distro}-${name}.yaml"
if grep -Fq "etcd-backup-restore" "${REPO_ROOT}/templates/cluster-template-${distro}-${name}.yaml"; then
sed -i -e "s|\${CERTPATH}|${CERT_HOSTPATH[$distro]}|g; s|\${CACERTFILE}|${CACERT[$distro]}|g; s|\${CERTFILE}|${CERT[$distro]}|g; s|\${KEYFILE}|${KEY[$distro]}|g" "${REPO_ROOT}/templates/cluster-template-${distro}-${name}.yaml"
sed -i -e "s|\${CERTPATH}|${CERT_HOSTPATH}|g; s|\${CACERTFILE}|${CACERT}|g; s|\${CERTFILE}|${CERT}|g; s|\${KEYFILE}|${KEY}|g" "${REPO_ROOT}/templates/cluster-template-${distro}-${name}.yaml"
fi
fi
done
Expand Down

0 comments on commit 8ab18ac

Please sign in to comment.