forked from openshift/installer
-
Notifications
You must be signed in to change notification settings - Fork 2
/
userdata.go
41 lines (37 loc) · 889 Bytes
/
userdata.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package machines
import (
"bytes"
"encoding/base64"
"text/template"
"github.com/pkg/errors"
)
var userDataListTmpl = template.Must(template.New("user-data-list").Parse(`
kind: List
apiVersion: v1
metadata:
resourceVersion: ""
selfLink: ""
items:
{{- range $name, $content := . }}
- apiVersion: v1
kind: Secret
metadata:
name: {{$name}}
namespace: openshift-machine-api
type: Opaque
data:
disableTemplating: "dHJ1ZQo="
userData: {{$content}}
{{- end}}
`))
func userDataList(data map[string][]byte) ([]byte, error) {
encodedData := map[string]string{}
for name, content := range data {
encodedData[name] = base64.StdEncoding.EncodeToString(content)
}
buf := &bytes.Buffer{}
if err := userDataListTmpl.Execute(buf, encodedData); err != nil {
return nil, errors.Wrap(err, "failed to execute content.UserDataListTmpl")
}
return buf.Bytes(), nil
}