-
Notifications
You must be signed in to change notification settings - Fork 462
/
ManualAppSyncYaml.go
73 lines (69 loc) · 1.9 KB
/
ManualAppSyncYaml.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package chartRepo
import (
"bytes"
"github.com/devtron-labs/devtron/pkg/sql"
"text/template"
)
type AppSyncConfig struct {
DbConfig sql.Config
DockerImage string
AppSyncJobResourcesObj string
}
func manualAppSyncJobByteArr(dockerImage string, appSyncJobResourcesObj string) []byte {
cfg, _ := sql.GetConfig()
configValues := AppSyncConfig{
DbConfig: sql.Config{Addr: cfg.Addr, Database: cfg.Database, User: cfg.User, Password: cfg.Password},
DockerImage: dockerImage,
AppSyncJobResourcesObj: appSyncJobResourcesObj,
}
temp := template.New("manualAppSyncJobByteArr")
temp, _ = temp.Parse(`{"apiVersion": "batch/v1",
"kind": "Job",
"metadata": {
"name": "app-manual-sync-job",
"namespace": "devtroncd"
},
"spec": {
"template": {
"spec": {
"containers": [
{
"name": "chart-sync",
"image": "{{.DockerImage}}",
{{if .AppSyncJobResourcesObj}}
"resources": {{.AppSyncJobResourcesObj}},
{{end}}
"env": [
{
"name": "PG_ADDR",
"value": "{{.DbConfig.Addr}}"
},
{
"name": "PG_DATABASE",
"value": "{{.DbConfig.Database}}"
},
{
"name": "PG_USER",
"value": "{{.DbConfig.User}}"
},
{
"name": "PG_PASSWORD",
"value": "{{.DbConfig.Password}}"
}
]
}
],
"restartPolicy": "OnFailure"
}
},
"backoffLimit": 4,
"activeDeadlineSeconds": 15000
}
}`)
var manualAppSyncJobBufferBytes bytes.Buffer
if err := temp.Execute(&manualAppSyncJobBufferBytes, configValues); err != nil {
return nil
}
manualAppSyncJobByteArr := []byte(manualAppSyncJobBufferBytes.String())
return manualAppSyncJobByteArr
}