-
Notifications
You must be signed in to change notification settings - Fork 217
/
manifest.go
179 lines (159 loc) · 4.18 KB
/
manifest.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
package mce
import (
"bytes"
"fmt"
"text/template"
)
const (
filesystemStorage = "filesystem"
databaseStorage = "database"
imageStorage = "image"
)
var storageSizeGi = map[string]int64{
filesystemStorage: int64(10),
databaseStorage: int64(10),
imageStorage: int64(50),
}
// Manifests returns manifests needed to deploy MCE.
func Manifests() (openshiftManifests map[string][]byte, customManifests []byte, err error) {
// Generate the OpenShift manifests:
namespaceManifest, err := getNamespace()
if err != nil {
return
}
operatorGroupManifest, err := getOperatorGroup()
if err != nil {
return
}
operatorSubscriptionManifest, err := getSubscription()
if err != nil {
return
}
openshiftManifests = map[string][]byte{
"50_openshift-mce_ns.yaml": namespaceManifest,
"50_openshift-mce_operator_group.yaml": operatorGroupManifest,
"50_openshift-mce_operator_subscription.yaml": operatorSubscriptionManifest,
}
mceManifest, err := getMultiClusterEngine()
if err != nil {
return
}
return openshiftManifests, mceManifest, nil
}
func getStorageSize(storageName string) string {
if intSize, ok := storageSizeGi[storageName]; ok {
return fmt.Sprintf("%dGi", intSize)
}
return ""
}
func GetAgentServiceConfigWithPVCManifest(storageClassName string) ([]byte, error) {
vars := map[string]string{
"DATABASE_STORAGE_SIZE": getStorageSize(databaseStorage),
"FILESYSTEM_STORAGE_SIZE": getStorageSize(filesystemStorage),
"IMAGE_STORAGE_SIZE": getStorageSize(imageStorage),
"STORAGE_CLASS_NAME": storageClassName,
}
return executeTemplate(vars, agentServiceConfigTemplate)
}
func getSubscription() ([]byte, error) {
data := map[string]string{
"OPERATOR_NAMESPACE": Operator.Namespace,
"OPERATOR_SUBSCRIPTION_NAME": Operator.SubscriptionName,
}
return executeTemplate(data, operatorSubscriptionManifestTemplate)
}
func getNamespace() ([]byte, error) {
data := map[string]string{
"OPERATOR_NAMESPACE": Operator.Namespace,
}
return executeTemplate(data, namespaceManifestTemplate)
}
func getOperatorGroup() ([]byte, error) {
data := map[string]string{
"OPERATOR_NAMESPACE": Operator.Namespace,
}
return executeTemplate(data, operatorGroupManifestTemplate)
}
func getMultiClusterEngine() ([]byte, error) {
data := map[string]string{
"OPERATOR_NAMESPACE": Operator.Namespace,
}
return executeTemplate(data, clusterEngineManifestTemplate)
}
func executeTemplate(data map[string]string, content string) ([]byte, error) {
tmpl, err := template.New("").Parse(content)
if err != nil {
return nil, err
}
buf := &bytes.Buffer{}
err = tmpl.Execute(buf, data)
if err != nil {
return nil, err
}
return buf.Bytes(), nil
}
const namespaceManifestTemplate = `
apiVersion: v1
kind: Namespace
metadata:
name: {{.OPERATOR_NAMESPACE}}
spec: {}
`
const operatorSubscriptionManifestTemplate = `
apiVersion: operators.coreos.com/v1alpha1
kind: Subscription
metadata:
namespace: "{{ .OPERATOR_NAMESPACE }}"
name: "{{.OPERATOR_SUBSCRIPTION_NAME}}"
spec:
sourceNamespace: openshift-marketplace
source: redhat-operators
name: multicluster-engine
installPlanApproval: Automatic
`
const operatorGroupManifestTemplate = `
apiVersion: operators.coreos.com/v1
kind: OperatorGroup
metadata:
namespace: "{{.OPERATOR_NAMESPACE}}"
name: mce
spec:
targetNamespaces:
- "{{.OPERATOR_NAMESPACE}}"
`
const clusterEngineManifestTemplate = `
apiVersion: multicluster.openshift.io/v1
kind: MultiClusterEngine
metadata:
name: mce
spec:
targetNamespace: "{{.OPERATOR_NAMESPACE}}"
`
const agentServiceConfigTemplate = `
apiVersion: agent-install.openshift.io/v1beta1
kind: AgentServiceConfig
metadata:
name: agent
spec:
databaseStorage:
storageClassName: {{.STORAGE_CLASS_NAME}}
accessModes:
- ReadWriteOnce
resources:
requests:
storage: {{.DATABASE_STORAGE_SIZE}}
filesystemStorage:
storageClassName: {{.STORAGE_CLASS_NAME}}
accessModes:
- ReadWriteOnce
resources:
requests:
storage: {{.FILESYSTEM_STORAGE_SIZE}}
imageStorage:
storageClassName: {{.STORAGE_CLASS_NAME}}
accessModes:
- ReadWriteOnce
resources:
requests:
storage: {{.IMAGE_STORAGE_SIZE}}
`