Skip to content

Commit 0ab1286

Browse files
committed
fpga_plugin: add --output-dir to webhook-create-signed-cert
Setting --output-dir DIR enables writing contents of the secret to DIR instead of creating the secret in the cluster. This allows creating the secret later, for instance during fpga_plugin kustomization. Signed-off-by: Antti Kervinen <[email protected]>
1 parent 0ec3abf commit 0ab1286

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

scripts/webhook-create-signed-cert.sh

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ while [[ $# -gt 0 ]]; do
2121
kubectl="$2"
2222
shift
2323
;;
24+
--output-dir)
25+
output_dir="$2"
26+
shift
27+
;;
2428
esac
2529
shift
2630
done
@@ -29,6 +33,7 @@ done
2933
[ -z ${secret} ] && secret="webhook-certs"
3034
[ -z ${namespace} ] && namespace="default"
3135
[ -z ${kubectl} ] && kubectl="kubectl"
36+
[ -z ${output_dir} ] && output_dir=""
3237

3338
which ${kubectl} > /dev/null 2>&1 || { echo "ERROR: ${kubectl} not found"; exit 1; }
3439

@@ -105,12 +110,25 @@ echo ${serverCert} | base64 --decode > ${tmpdir}/server-cert.pem
105110
# clean-up any previously created secret for our service. Ignore errors if not present.
106111
${kubectl} delete secret ${secret} 2>/dev/null || true
107112

108-
# create the secret with CA cert and server cert/key
109-
${kubectl} create secret generic ${secret} \
110-
--from-file=key.pem=${tmpdir}/server-key.pem \
111-
--from-file=cert.pem=${tmpdir}/server-cert.pem \
112-
--dry-run -o yaml |
113-
${kubectl} -n ${namespace} apply -f -
113+
if [ -z "${output_dir}" ]; then
114+
# create the secret with CA cert and server cert/key
115+
${kubectl} create secret generic ${secret} \
116+
--from-file=key.pem=${tmpdir}/server-key.pem \
117+
--from-file=cert.pem=${tmpdir}/server-cert.pem \
118+
--dry-run -o yaml |
119+
${kubectl} -n ${namespace} apply -f -
120+
else
121+
# save CA cert and server cert/key to output_dir
122+
( cp ${tmpdir}/server-key.pem ${output_dir}/key.pem &&
123+
cp ${tmpdir}/server-cert.pem ${output_dir}/cert.pem ) || {
124+
echo "ERROR: failed to copy ${tmpdir}/server-{key,cert}.pem to output_dir \"${output_dir}\""
125+
exit 1
126+
}
127+
${kubectl} get configmap -n kube-system extension-apiserver-authentication -o=jsonpath='{.data.client-ca-file}' > "${output_dir}/client-ca-file" || {
128+
echo "ERROR: failed to save extension-apiserver-authentication.client-ca-file to output_dir \"${output_dir}\""
129+
exit 1
130+
}
131+
fi
114132

115133
echo "Removing ${tmpdir}"
116134
rm -rf ${tmpdir}

0 commit comments

Comments
 (0)