-
Notifications
You must be signed in to change notification settings - Fork 217
/
manifest.go
144 lines (125 loc) · 3.72 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
package lvm
import (
"bytes"
"text/template"
"github.com/openshift/assisted-service/internal/common"
)
const defaultDeviceName = "vg1"
// Manifests returns manifests needed to deploy LVM
func Manifests(cluster *common.Cluster) (map[string][]byte, []byte, error) {
lvmSubscription, err := getSubscription(cluster)
if err != nil {
return nil, nil, err
}
lvmNamespace, err := getNamespace()
if err != nil {
return nil, nil, err
}
lvmOperatorGroup, err := getOperatorGroup()
if err != nil {
return nil, nil, err
}
lvmcluster, err := getLvmCluster()
if err != nil {
return nil, nil, err
}
openshiftManifests := make(map[string][]byte)
openshiftManifests["50_openshift-lvm_ns.yaml"] = lvmNamespace
openshiftManifests["50_openshift-lvm_operator_group.yaml"] = lvmOperatorGroup
openshiftManifests["50_openshift-lvm_subscription.yaml"] = lvmSubscription
return openshiftManifests, lvmcluster, nil
}
func getSubscriptionInfo(openshiftVersion string) (map[string]string, error) {
isGreaterOrEqual, err := common.BaseVersionGreaterOrEqual(LvmsMinOpenshiftVersion4_12, openshiftVersion)
if err != nil {
return map[string]string{}, err
}
if !isGreaterOrEqual {
return map[string]string{
"OPERATOR_NAMESPACE": Operator.Namespace,
"OPERATOR_SUBSCRIPTION_NAME": LvmoSubscriptionName,
"OPERATOR_SUBSCRIPTION_SPEC_NAME": LvmoSubscriptionName,
}, nil
}
return map[string]string{
"OPERATOR_NAMESPACE": Operator.Namespace,
"OPERATOR_SUBSCRIPTION_NAME": LvmsSubscriptionName,
"OPERATOR_SUBSCRIPTION_SPEC_NAME": LvmsSubscriptionName,
}, nil
}
func getSubscription(cluster *common.Cluster) ([]byte, error) {
subscriptionInfo, err := getSubscriptionInfo(cluster.OpenshiftVersion)
if err != nil {
return []byte{}, err
}
return executeTemplate(subscriptionInfo, "LvmSubscription", LvmSubscription)
}
func getNamespace() ([]byte, error) {
data := map[string]string{
"OPERATOR_NAMESPACE": Operator.Namespace,
}
return executeTemplate(data, "LvmNamespace", LvmNamespace)
}
func getOperatorGroup() ([]byte, error) {
data := map[string]string{
"OPERATOR_NAMESPACE": Operator.Namespace,
}
return executeTemplate(data, "LvmOperatorGroup", LvmOperatorGroup)
}
func getLvmCluster() ([]byte, error) {
data := map[string]string{
"OPERATOR_NAMESPACE": Operator.Namespace,
"DEVICE_NAME": defaultDeviceName,
}
return executeTemplate(data, "LvmCluster", LvmCluster)
}
func executeTemplate(data map[string]string, contentName, content string) ([]byte, error) {
tmpl, err := template.New(contentName).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 LvmSubscription = `apiVersion: operators.coreos.com/v1alpha1
kind: Subscription
metadata:
name: "{{.OPERATOR_SUBSCRIPTION_NAME}}"
namespace: "{{.OPERATOR_NAMESPACE}}"
spec:
installPlanApproval: Automatic
name: "{{.OPERATOR_SUBSCRIPTION_SPEC_NAME}}"
source: redhat-operators
sourceNamespace: openshift-marketplace`
const LvmNamespace = `apiVersion: v1
kind: Namespace
metadata:
name: "{{.OPERATOR_NAMESPACE}}"
labels:
openshift.io/cluster-monitoring: "true"
spec: {}`
const LvmOperatorGroup = `apiVersion: operators.coreos.com/v1
kind: OperatorGroup
metadata:
name: openshift-storage-operatorgroup
namespace: "{{.OPERATOR_NAMESPACE}}"
spec:
targetNamespaces:
- "{{.OPERATOR_NAMESPACE}}"`
const LvmCluster = `apiVersion: lvm.topolvm.io/v1alpha1
kind: LVMCluster
metadata:
name: lvmcluster-sample
namespace: "{{.OPERATOR_NAMESPACE}}"
spec:
storage:
deviceClasses:
- name: {{.DEVICE_NAME}}
thinPoolConfig:
name: thin-pool-1
sizePercent: 90
overprovisionRatio: 10`