Skip to content

Commit 249e289

Browse files
committed
Allow specifying SSH keys
1 parent cfed4ae commit 249e289

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

src/test/java/com/microsoft/jenkins/kubernetes/integration/integration-test.sh

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,15 @@ while [[ $# -gt 0 ]]; do
4848
shift; shift
4949
;;
5050
-k|--ssh-key-file)
51+
# private key to login to the Kubernetes master node
5152
export KUBERNETES_CD_KEY_PATH="$2"
5253
shift; shift
5354
;;
55+
--ssh-pubkey-file)
56+
# public key to provision ACS Kubernetes on demand
57+
export KUBERNETES_CD_PUBLIC_KEY_PATH="$2"
58+
shift; shift
59+
;;
5460
--docker-registry)
5561
export KUBERNETES_CD_DOCKER_REGISTRY="$2"
5662
shift; shift
@@ -77,6 +83,18 @@ while [[ $# -gt 0 ]]; do
7783
esac
7884
done
7985

86+
if [[ -z "$KUBERNETES_CD_KEY_PATH" ]]; then
87+
export KUBERNETES_CD_KEY_PATH="$(readlink -f ~/.ssh/id_rsa)"
88+
fi
89+
if [[ ! -f "$KUBERNETES_CD_KEY_PATH" ]]; then
90+
echo "Private key was not specified to authenticate with Kubernetes master node" >&2
91+
exit 1
92+
fi
93+
94+
if [[ -z "$KUBERNETES_CD_ADMIN_USER" ]]; then
95+
export KUBERNETES_CD_ADMIN_USER=azureuser
96+
fi
97+
8098
# common suffix for the names
8199
suffix=$(xxd -p -l 4 /dev/urandom)
82100

@@ -120,11 +138,15 @@ if [[ -n "$resource_group" ]]; then
120138
exit -1
121139
fi
122140

141+
123142
az group create --name "$resource_group" --location SoutheastAsia
124143

125144
if [[ -z "$KUBERNETES_CD_MASTER_HOST" ]]; then
145+
if [[ -z "$KUBERNETES_CD_PUBLIC_KEY_PATH" ]]; then
146+
export KUBERNETES_CD_PUBLIC_KEY_PATH="$(readlink -f ~/.ssh/id_rsa.pub)"
147+
fi
126148
k8s_name="k8s-$suffix"
127-
az acs create --orchestrator-type kubernetes --resource-group "$resource_group" --name "$k8s_name" --agent-count 2 &
149+
az acs create --orchestrator-type kubernetes --resource-group "$resource_group" --name "$k8s_name" --agent-count 2 --ssh-key-value "$KUBERNETES_CD_PUBLIC_KEY_PATH" &
128150
k8s_pid=$!
129151
fi
130152

@@ -157,7 +179,7 @@ if [[ -n "$resource_group" ]]; then
157179
echo -n "Fetch the ACS Kubernetes credentials to $tmpfile "
158180
k8s_ready=0
159181
for i in $(seq 60); do
160-
if az acs kubernetes get-credentials --resource-group "$resource_group" --name "$k8s_name" --file "$tmpfile" >/dev/null 2>&1; then
182+
if az acs kubernetes get-credentials --resource-group "$resource_group" --name "$k8s_name" --file "$tmpfile" --ssh-key-file="$KUBERNETES_CD_KEY_PATH" >/dev/null 2>&1; then
161183
if [[ -s $tmpfile ]]; then
162184
k8s_ready=1
163185
break

0 commit comments

Comments
 (0)