stark, steven | 6754bc1 | 2019-09-19 15:43:00 -0700 | [diff] [blame^] | 1 | #!/bin/bash |
| 2 | # Copyright 2019 AT&T Intellectual Property. All rights reserved. |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | |
| 16 | PRIVATE_KEY=$1 |
| 17 | KUBECONFIG=$2 |
| 18 | NFS_IP=$3 |
| 19 | ADMIN_USER=$4 |
| 20 | |
| 21 | export KUBECONFIG=$KUBECONFIG |
| 22 | |
| 23 | echo "setting up nfs on AKS nodes" |
| 24 | kubectl create configmap aks-key --from-file=$PRIVATE_KEY |
| 25 | |
| 26 | for IPADDRESS in `kubectl get nodes -o jsonpath='{.items[*].status.addresses[?(@.type=="InternalIP")].address}'`; do |
| 27 | |
| 28 | cat <<EOF | kubectl create -f - |
| 29 | apiVersion: v1 |
| 30 | kind: Pod |
| 31 | metadata: |
| 32 | generateName: configure-nfs- |
| 33 | spec: |
| 34 | containers: |
| 35 | - name: configure-nfs |
| 36 | image: alpine |
| 37 | env: |
| 38 | - name: IP_ADDRESS |
| 39 | value: "$IPADDRESS" |
| 40 | - name: NFS_IP |
| 41 | value: "$NFS_IP" |
| 42 | volumeMounts: |
| 43 | - name: aks-key |
| 44 | mountPath: /aks-key |
| 45 | command: ["/bin/sh"] |
| 46 | args: |
| 47 | - -c |
| 48 | - apk update && \ |
| 49 | apk add openssh-client && \ |
| 50 | sh -c "ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i /aks-key/id_rsa $ADMIN_USER@\$IP_ADDRESS \"sudo apt-get update; sudo apt-get install nfs-common; sudo rm -rf /dockerdata-nfs; sudo mkdir /dockerdata-nfs; sudo mount -t nfs \$NFS_IP:/dockerdata-nfs /dockerdata-nfs/\"" |
| 51 | restartPolicy: Never |
| 52 | volumes: |
| 53 | - name: aks-key |
| 54 | configMap: |
| 55 | name: aks-key |
| 56 | defaultMode: 0600 |
| 57 | EOF |
| 58 | |
| 59 | done |
| 60 | |
| 61 | # TODO |
| 62 | # Add actual pod status check here |
| 63 | echo "sleeping 30 seconds" |
| 64 | sleep 30 |
| 65 | |
| 66 | kubectl delete configmap aks-key |
| 67 | kubectl get pods | grep configure-nfs | while read line; do |
| 68 | pod=`echo $line | awk '{print $1}'` |
| 69 | kubectl delete pod $pod |
| 70 | done |