Skip to content

Commit 9362ba8

Browse files
fix: Corrects the problems identified by Copilot:
* etcd download: use arch variable instead of hard-coded amd64 Replace hard-coded linux-amd64 in etcd tarball download URL and output filename with linux- to support both amd64 and arm64 architectures. * container-selinux: install from distro repos instead of CentOS 7 mirror Remove hard-coded CentOS 7 x86_64 RPM URL for container-selinux and install directly from the system's configured repositories, which handles architecture and version automatically. * build_name: fix dead-code fallback default Check whether parameter is empty before constructing build_name, so the fallback default setup--.iso is actually reachable. * CNI download: fail on HTTP errors for both URL attempts Use curl -f on both primary and legacy CNI download URLs and exit with a clear error if neither succeeds, instead of only checking for 404 on the first attempt. * temp directory: use mktemp and trap for cleanup Replace fixed /tmp/iso with mktemp -d to avoid collisions between concurrent runs, and register a trap EXIT to ensure cleanup on failure or early exit.
1 parent 7fbad05 commit 9362ba8

File tree

1 file changed

+32
-30
lines changed

1 file changed

+32
-30
lines changed

scripts/util/create-kubernetes-binaries-iso-with-cilium.sh

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -64,19 +64,25 @@ RELEASE="v${2}"
6464
VAL="1.18.0"
6565
output_dir="${1}"
6666
start_dir="$PWD"
67-
iso_dir="/tmp/iso"
67+
iso_dir=$(mktemp -d)
68+
trap 'rm -rf "${iso_dir}"' EXIT
6869
working_dir="${iso_dir}/"
69-
mkdir -p "${working_dir}"
70-
build_name="${5}-${ARCH_SUFFIX}.iso"
71-
[ -z "${build_name}" ] && build_name="setup-${RELEASE}-${ARCH_SUFFIX}.iso"
70+
if [ -n "${5}" ]; then
71+
build_name="${5}-${ARCH_SUFFIX}.iso"
72+
else
73+
build_name="setup-${RELEASE}-${ARCH_SUFFIX}.iso"
74+
fi
7275

7376
CNI_VERSION="v${3}"
7477
echo "Downloading CNI ${CNI_VERSION}..."
7578
cni_dir="${working_dir}/cni/"
7679
mkdir -p "${cni_dir}"
77-
cni_status_code=$(curl -sS -L --write-out "%{http_code}\n" "https://github.com/containernetworking/plugins/releases/download/${CNI_VERSION}/cni-plugins-linux-${ARCH}-${CNI_VERSION}.tgz" -o "${cni_dir}/cni-plugins-${ARCH}.tgz")
78-
if [[ ${cni_status_code} -eq 404 ]]; then
79-
curl -sS -L --write-out "%{http_code}\n" "https://github.com/containernetworking/plugins/releases/download/${CNI_VERSION}/cni-plugins-${ARCH}-${CNI_VERSION}.tgz" -o "${cni_dir}/cni-plugins-${ARCH}.tgz"
80+
if ! curl -sSf -L "https://github.com/containernetworking/plugins/releases/download/${CNI_VERSION}/cni-plugins-linux-${ARCH}-${CNI_VERSION}.tgz" -o "${cni_dir}/cni-plugins-${ARCH}.tgz" 2>/dev/null; then
81+
echo "Primary CNI URL failed, trying legacy URL format..."
82+
if ! curl -sSf -L "https://github.com/containernetworking/plugins/releases/download/${CNI_VERSION}/cni-plugins-${ARCH}-${CNI_VERSION}.tgz" -o "${cni_dir}/cni-plugins-${ARCH}.tgz"; then
83+
echo "ERROR: Failed to download CNI plugins ${CNI_VERSION} for ${ARCH} from both URL formats."
84+
exit 1
85+
fi
8086
fi
8187

8288
CRICTL_VERSION="v${4}"
@@ -89,7 +95,7 @@ echo "Downloading Kubernetes tools ${RELEASE}..."
8995
k8s_dir="${working_dir}/k8s"
9096
mkdir -p "${k8s_dir}"
9197
cd "${k8s_dir}"
92-
curl -sS -L --remote-name-all https://dl.k8s.io/release/${RELEASE}/bin/linux/${ARCH}/{kubeadm,kubelet,kubectl}
98+
curl -sS -L --remote-name-all https://dl.k8s.io/release/"${RELEASE}"/bin/linux/${ARCH}/{kubeadm,kubelet,kubectl}
9399
kubeadm_file_permissions=$(stat --format '%a' kubeadm)
94100
chmod +x kubeadm
95101

@@ -98,29 +104,29 @@ cd "${start_dir}"
98104
kubelet_service_file="${working_dir}/kubelet.service"
99105
touch "${kubelet_service_file}"
100106
if [[ $(echo "${2} $VAL" | awk '{print ($1 < $2)}') == 1 ]]; then
101-
curl -sSL "https://raw.githubusercontent.com/kubernetes/kubernetes/${RELEASE}/build/debs/kubelet.service" | sed "s:/usr/bin:/opt/bin:g" > ${kubelet_service_file}
107+
curl -sSL "https://raw.githubusercontent.com/kubernetes/kubernetes/${RELEASE}/build/debs/kubelet.service" | sed "s:/usr/bin:/opt/bin:g" > "${kubelet_service_file}"
102108
else
103-
curl -sSL "https://raw.githubusercontent.com/shapeblue/cloudstack-nonoss/main/cks/kubelet.service" | sed "s:/usr/bin:/opt/bin:g" > ${kubelet_service_file}
109+
curl -sSL "https://raw.githubusercontent.com/shapeblue/cloudstack-nonoss/main/cks/kubelet.service" | sed "s:/usr/bin:/opt/bin:g" > "${kubelet_service_file}"
104110
fi
105111

106112
echo "Downloading 10-kubeadm.conf ${RELEASE}..."
107113
kubeadm_conf_file="${working_dir}/10-kubeadm.conf"
108114
touch "${kubeadm_conf_file}"
109115
if [[ $(echo "${2} $VAL" | awk '{print ($1 < $2)}') == 1 ]]; then
110-
curl -sSL "https://raw.githubusercontent.com/kubernetes/kubernetes/${RELEASE}/build/debs/10-kubeadm.conf" | sed "s:/usr/bin:/opt/bin:g" > ${kubeadm_conf_file}
116+
curl -sSL "https://raw.githubusercontent.com/kubernetes/kubernetes/${RELEASE}/build/debs/10-kubeadm.conf" | sed "s:/usr/bin:/opt/bin:g" > "${kubeadm_conf_file}"
111117
else
112-
curl -sSL "https://raw.githubusercontent.com/shapeblue/cloudstack-nonoss/main/cks/10-kubeadm.conf" | sed "s:/usr/bin:/opt/bin:g" > ${kubeadm_conf_file}
118+
curl -sSL "https://raw.githubusercontent.com/shapeblue/cloudstack-nonoss/main/cks/10-kubeadm.conf" | sed "s:/usr/bin:/opt/bin:g" > "${kubeadm_conf_file}"
113119
fi
114120

115121
AUTOSCALER_URL="https://raw.githubusercontent.com/kubernetes/autoscaler/master/cluster-autoscaler/cloudprovider/cloudstack/examples/cluster-autoscaler-standard.yaml"
116122
echo "Downloading kubernetes cluster autoscaler ${AUTOSCALER_URL}"
117123
autoscaler_conf_file="${working_dir}/autoscaler.yaml"
118-
curl -sSL ${AUTOSCALER_URL} -o ${autoscaler_conf_file}
124+
curl -sSL "${AUTOSCALER_URL}" -o "${autoscaler_conf_file}"
119125

120126
PROVIDER_URL="https://raw.githubusercontent.com/apache/cloudstack-kubernetes-provider/main/deployment.yaml"
121127
echo "Downloading kubernetes cluster provider ${PROVIDER_URL}"
122128
provider_conf_file="${working_dir}/provider.yaml"
123-
curl -sSL ${PROVIDER_URL} -o ${provider_conf_file}
129+
curl -sSL "${PROVIDER_URL}" -o "${provider_conf_file}"
124130

125131
CILIUM_VERSION="${8}"
126132
echo "Generating Cilium ${CILIUM_VERSION} manifest..."
@@ -157,7 +163,7 @@ if ! helm template cilium cilium/cilium --version "${CILIUM_VERSION}" \
157163
--set ipam.operator.clusterPoolIPv4PodCIDRList={10.168.0.0/16} \
158164
--set ipam.operator.clusterPoolIPv4MaskSize=24 \
159165
--set hubble.relay.enabled=false \
160-
--set hubble.ui.enabled=false > ${network_conf_file}; then
166+
--set hubble.ui.enabled=false > "${network_conf_file}"; then
161167
echo "ERROR: Failed to generate Cilium manifest with Helm"
162168
echo "Check if Cilium version ${CILIUM_VERSION} exists in the Helm repository"
163169
exit 1
@@ -167,12 +173,12 @@ echo "Cilium manifest generated successfully"
167173
DASHBOARD_VERSION="2.7.0"
168174
echo "Downloading Kubernetes Dashboard v${DASHBOARD_VERSION}..."
169175
dashboard_conf_file="${working_dir}/dashboard.yaml"
170-
curl -sSl "https://raw.githubusercontent.com/kubernetes/dashboard/v${DASHBOARD_VERSION}/aio/deploy/recommended.yaml" -o ${dashboard_conf_file}
176+
curl -sSL "https://raw.githubusercontent.com/kubernetes/dashboard/v${DASHBOARD_VERSION}/aio/deploy/recommended.yaml" -o "${dashboard_conf_file}"
171177

172178
csi_conf_file="${working_dir}/manifest.yaml"
173179
echo "Including CloudStack CSI Driver manifest"
174-
wget https://github.com/cloudstack/cloudstack-csi-driver/releases/download/v3.0.0/snapshot-crds.yaml -O ${working_dir}/snapshot-crds.yaml
175-
wget https://github.com/cloudstack/cloudstack-csi-driver/releases/download/v3.0.0/manifest.yaml -O ${csi_conf_file}
180+
wget https://github.com/cloudstack/cloudstack-csi-driver/releases/download/v3.0.0/snapshot-crds.yaml -O "${working_dir}/snapshot-crds.yaml"
181+
wget https://github.com/cloudstack/cloudstack-csi-driver/releases/download/v3.0.0/manifest.yaml -O "${csi_conf_file}"
176182

177183
echo "Fetching k8s docker images..."
178184
if ! ctr -v > /dev/null 2>&1; then
@@ -184,22 +190,20 @@ if ! ctr -v > /dev/null 2>&1; then
184190
PKG_MGR="yum"
185191
fi
186192
sudo $PKG_MGR --assumeyes remove docker-common docker container-selinux docker-selinux docker-engine
187-
sudo $PKG_MGR --assumeyes install lvm2 device-mapper device-mapper-persistent-data device-mapper-event device-mapper-libs device-mapper-event-libs
188-
sudo $PKG_MGR --assumeyes install http://mirror.centos.org/centos/7/extras/x86_64/Packages/container-selinux-2.107-3.el7.noarch.rpm
189-
sudo $PKG_MGR --assumeyes install containerd.io
193+
sudo $PKG_MGR --assumeyes install lvm2 device-mapper device-mapper-persistent-data device-mapper-event device-mapper-libs device-mapper-event-libs container-selinux containerd.io
190194
elif [ -f /etc/debian_version ] || command -v apt-get > /dev/null 2>&1; then
191195
sudo apt-get update && sudo apt-get install containerd.io --yes
192196
fi
193197
sudo systemctl enable --now containerd
194198
fi
195199
mkdir -p "${working_dir}/docker"
196-
output=$(${k8s_dir}/kubeadm config images list --kubernetes-version="${RELEASE}")
200+
output=$("${k8s_dir}/kubeadm" config images list --kubernetes-version="${RELEASE}")
197201

198202
# Don't forget about the other image !
199-
autoscaler_image=$(grep "image:" ${autoscaler_conf_file} | cut -d ':' -f2- | tr -d ' ')
203+
autoscaler_image=$(grep "image:" "${autoscaler_conf_file}" | cut -d ':' -f2- | tr -d ' ')
200204
output=$(printf "%s\n" "${output}" "${autoscaler_image}")
201205

202-
provider_image=$(grep "image:" ${provider_conf_file} | cut -d ':' -f2- | tr -d ' ')
206+
provider_image=$(grep "image:" "${provider_conf_file}" | cut -d ':' -f2- | tr -d ' ')
203207
output=$(printf "%s\n" "${output}" "${provider_image}")
204208

205209
# Extract images from manifest.yaml and add to output
@@ -208,7 +212,7 @@ output=$(printf "%s\n%s" "${output}" "${csi_images}")
208212

209213
# Extract all images from yaml manifests (including Cilium network.yaml and Dashboard)
210214
echo "Extracting images from manifest files..."
211-
for i in ${network_conf_file} ${dashboard_conf_file}; do
215+
for i in "${network_conf_file}" "${dashboard_conf_file}"; do
212216
images=$(grep "image:" "$i" | cut -d ':' -f2- | tr -d ' ' | tr -d "'" | tr -d '"')
213217
output=$(printf "%s\n" "${output}" "${images}")
214218
done
@@ -250,14 +254,12 @@ fi
250254
chmod "${kubeadm_file_permissions}" "${working_dir}/k8s/kubeadm"
251255

252256
echo "Updating imagePullPolicy to IfNotPresent in yaml files..."
253-
sed -i "s/imagePullPolicy:.*/imagePullPolicy: IfNotPresent/g" ${working_dir}/*.yaml
257+
sed -i "s/imagePullPolicy:.*/imagePullPolicy: IfNotPresent/g" "${working_dir}"/*.yaml
254258

255259
etcd_dir="${working_dir}/etcd"
256260
mkdir -p "${etcd_dir}"
257261
ETCD_VERSION=v${7}
258262
echo "Downloading etcd ${ETCD_VERSION}..."
259-
curl -sS -L "https://github.com/etcd-io/etcd/releases/download/${ETCD_VERSION}/etcd-${ETCD_VERSION}-linux-amd64.tar.gz" -o ${etcd_dir}/etcd-linux-amd64.tar.gz
260-
261-
mkisofs -o "${output_dir}/${build_name}" -J -R -l "${iso_dir}"
263+
curl -sS -L "https://github.com/etcd-io/etcd/releases/download/${ETCD_VERSION}/etcd-${ETCD_VERSION}-linux-${ARCH}.tar.gz" -o "${etcd_dir}/etcd-linux-${ARCH}.tar.gz"
262264

263-
rm -rf "${iso_dir}"
265+
mkisofs -o "${output_dir}/${build_name}" -J -R -l "${iso_dir}"

0 commit comments

Comments
 (0)