This repository has been archived by the owner on Aug 9, 2022. It is now read-only.
/
generate_objects.go
78 lines (73 loc) · 2.12 KB
/
generate_objects.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
74
75
76
77
78
package testutils
import (
"os"
"path/filepath"
batchv1 "k8s.io/api/batch/v1"
"sigs.k8s.io/yaml"
"github.com/cloudnativedaysjp/reviewapp-operator/domain/models"
)
const generateObjectsBasePath = "testutils/.objects/"
func GenerateObjects(dirname string) (
ra models.ReviewApp,
at models.ApplicationTemplate,
mt models.ManifestsTemplate,
app models.Application,
manifests models.Manifests,
preStopJt models.JobTemplate,
preStopJob batchv1.Job,
) {
{ // ReviewApp
raFilePath := filepath.Join(generateObjectsBasePath, dirname, "ra.yaml")
raBytes, err := os.ReadFile(raFilePath)
if err == nil {
_ = yaml.Unmarshal(raBytes, &ra)
}
}
{ // ApplicationTemplate
atFilePath := filepath.Join(generateObjectsBasePath, dirname, "at.yaml")
atBytes, err := os.ReadFile(atFilePath)
if err == nil {
_ = yaml.Unmarshal(atBytes, &at)
}
}
{ // ManifestsTemplate
mtFilePath := filepath.Join(generateObjectsBasePath, dirname, "mt.yaml")
mtBytes, err := os.ReadFile(mtFilePath)
if err == nil {
_ = yaml.Unmarshal(mtBytes, &mt)
}
}
{ // Application
appFilePath := filepath.Join(generateObjectsBasePath, dirname, "app.yaml")
appBytes, err := os.ReadFile(appFilePath)
if err == nil {
app = models.Application(appBytes)
}
}
{ // some manifests from ManifestsTemplate
manifests = make(map[string]string)
manifestsDirPath := filepath.Join(generateObjectsBasePath, dirname, "manifests")
files, _ := os.ReadDir(manifestsDirPath)
for _, f := range files {
manifestBytes, err := os.ReadFile(filepath.Join(manifestsDirPath, f.Name()))
if err == nil {
manifests[f.Name()] = string(manifestBytes)
}
}
}
{ // JobTemplate (preStopJob)
preStopJtFilePath := filepath.Join(generateObjectsBasePath, dirname, "preStopJt.yaml")
preStopJtBytes, err := os.ReadFile(preStopJtFilePath)
if err == nil {
_ = yaml.Unmarshal(preStopJtBytes, &preStopJt)
}
}
{ // Job (preStopJob)
preStopJobFilePath := filepath.Join(generateObjectsBasePath, dirname, "preStopJob.yaml")
preStopJobBytes, err := os.ReadFile(preStopJobFilePath)
if err == nil {
_ = yaml.Unmarshal(preStopJobBytes, &preStopJob)
}
}
return
}