Fix spacing issues in YAML files in vnfs
[demo.git] / vnfs / DAaaS / sample-apps / training / sample-horovod-app / templates / config.yaml
1 {{- $workerNum := .Values.worker.number -}}
2 {{- $name := include "horovod.fullname" . }}
3 {{- $slots := 1 }}
4 {{- if index .Values.resources "nvidia.com/gpu" }}
5 {{- $slots := index .Values.resources "nvidia.com/gpu" }}
6 {{- end }}
7 apiVersion: v1
8 kind: ConfigMap
9 metadata:
10   name: {{ template "horovod.fullname" . }}
11   labels:
12     heritage: {{ .Release.Service | quote }}
13     release: {{ .Release.Name | quote }}
14     chart: {{ template "horovod.chart" . }}
15     app: {{ template "horovod.fullname" . }}
16 data:
17   hostfile.config: |
18     {{ $name }}-master slots={{ $slots }}
19     {{- range $i, $none := until (int $workerNum) }}
20     {{ $name }}-{{ $i }}.{{ $name }} slots={{ $slots }}
21     {{- end }}
22   ssh.readiness: |
23     #!/bin/bash
24     set -xev
25     ssh localhost ls
26   master.run: |
27      #!/bin/bash
28      set -x
29      sleep 5
30
31      mkdir -p /root/.ssh
32      rm -f /root/.ssh/config
33      touch /root/.ssh/config
34
35      if [ "$USESECRETS" == "true" ];then
36         set +e
37         yes | cp /etc/secret-volume/id_rsa /root/.ssh/id_rsa
38         yes | cp /etc/secret-volume/authorized_keys /root/.ssh/authorized_keys
39         set -e
40      fi
41
42      if [ -n "$SSHPORT" ]; then
43         echo "Port $SSHPORT" > /root/.ssh/config
44         sed -i "s/^Port.*/Port $SSHPORT /g" /etc/ssh/sshd_config
45      fi
46      echo "StrictHostKeyChecking no" >> /root/.ssh/config
47      /usr/sbin/sshd
48
49      if [ $# -eq 0 ]; then
50           sleep infinity
51         else
52           bash -c "$*"
53      fi
54      sleep 300
55   master.waitWorkerReady: |
56     #!/bin/bash
57     set -xev
58     function updateSSHPort() {
59       mkdir -p /root/.ssh
60       rm -f /root/.ssh/config
61       touch /root/.ssh/config
62
63       if [ -n "$SSHPORT" ]; then
64         echo "Port $SSHPORT" > /root/.ssh/config
65         echo "StrictHostKeyChecking no" >> /root/.ssh/config
66       fi
67     }
68
69     function runCheckSSH() {
70       if [[ "$USESECRETS" == "true" ]];then
71         set +e
72         yes | cp /etc/secret-volume/id_rsa /root/.ssh/id_rsa
73         yes | cp /etc/secret-volume/authorized_keys /root/.ssh/authorized_keys
74         set -e
75       fi
76
77       for i in `cat $1 | awk '{print $(1)}'`;do
78         if [[ "$i" != *"master" ]];then
79           retry 30 ssh -o ConnectTimeout=2 -q $i exit
80         fi
81       done
82     }
83
84     function retry()
85     {
86         local n=0;local try=$1
87         local cmd="${@: 2}"
88         [[ $# -le 1 ]] && {
89             echo "Usage $0 <retry_number> <Command>";
90         }
91         set +e
92         until [[ $n -ge $try ]]
93         do
94           $cmd && break || {
95                   echo "Command Fail.."
96                   ((n++))
97                   echo "retry $n :: [$cmd]"
98                   sleep 1;
99                   }
100         done
101         $cmd
102         if [ $? -ne 0 ]; then
103           exit 1
104         fi
105         set -e
106     }
107     updateSSHPort
108     runCheckSSH $1
109   worker.run: |
110      #!/bin/bash
111      set -x
112
113      mkdir -p /root/.ssh
114      rm -f /root/.ssh/config
115      touch /root/.ssh/config
116
117      if [[ "$USESECRETS" == "true" ]];then
118         set +e
119         yes | cp /etc/secret-volume/id_rsa /root/.ssh/id_rsa
120         yes | cp /etc/secret-volume/authorized_keys /root/.ssh/authorized_keys
121         set -e
122      fi
123
124      if [ -n "$SSHPORT" ]; then
125         echo "Port $SSHPORT" > /root/.ssh/config
126         sed -i "s/^Port.*/Port $SSHPORT /g" /etc/ssh/sshd_config
127      fi
128      echo "StrictHostKeyChecking no" >> /root/.ssh/config
129
130      /usr/sbin/sshd -D