forked from leapsky/bookkeeper-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bookkeepercluster_types.go
339 lines (276 loc) · 10.3 KB
/
bookkeepercluster_types.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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
/**
* Copyright (c) 2018 Dell Inc., or its subsidiaries. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*/
package v1alpha1
import (
"github.com/pravega/bookkeeper-operator/pkg/controller/config"
"k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
const (
// DefaultZookeeperUri is the default ZooKeeper URI in the form of "hostname:port"
DefaultZookeeperUri = "zk-client:2181"
// DefaultServiceType is the default service type for external access
DefaultServiceType = v1.ServiceTypeLoadBalancer
// DefaultPravegaVersion is the default tag used for for the Pravega
// Docker image
DefaultBookkeeperVersion = "0.6.1"
// DefaultBookkeeperImageRepository is the default Docker repository for
// the BookKeeper image
DefaultBookkeeperImageRepository = "pravega/bookkeeper"
// DefaultbookkeeperImagePullPolicy is the default image pull policy used
// for the Bookkeeper Docker image
DefaultBookkeeperImagePullPolicy = v1.PullAlways
// DefaultBookkeeperLedgerVolumeSize is the default volume size for the
// Bookkeeper ledger volume
DefaultBookkeeperLedgerVolumeSize = "10Gi"
// DefaultBookkeeperJournalVolumeSize is the default volume size for the
// Bookkeeper journal volume
DefaultBookkeeperJournalVolumeSize = "10Gi"
// DefaultBookkeeperIndexVolumeSize is the default volume size for the
// Bookkeeper index volume
DefaultBookkeeperIndexVolumeSize = "10Gi"
// MinimumBookkeeperReplicas is the minimum number of Bookkeeper replicas
// accepted
MinimumBookkeeperReplicas = 3
// DefaultBookkeeperRequestCPU is the default CPU request for BookKeeper
DefaultBookkeeperRequestCPU = "500m"
// DefaultBookkeeperLimitCPU is the default CPU limit for BookKeeper
DefaultBookkeeperLimitCPU = "1"
// DefaultBookkeeperRequestMemory is the default memory request for BookKeeper
DefaultBookkeeperRequestMemory = "1Gi"
// DefaultBookkeeperLimitMemory is the limit memory limit for BookKeeper
DefaultBookkeeperLimitMemory = "2Gi"
)
func init() {
SchemeBuilder.Register(&BookkeeperCluster{}, &BookkeeperClusterList{})
}
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// BookkeeperClusterList contains a list of BookkeeperCluster
type BookkeeperClusterList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []BookkeeperCluster `json:"items"`
}
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// BookkeeperCluster is the Schema for the BookkeeperClusters API
// +k8s:openapi-gen=true
type BookkeeperCluster struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec BookkeeperClusterSpec `json:"spec,omitempty"`
Status BookkeeperClusterStatus `json:"status,omitempty"`
}
// WithDefaults set default values when not defined in the spec.
func (bk *BookkeeperCluster) WithDefaults() (changed bool) {
changed = bk.Spec.withDefaults()
return changed
}
// ClusterSpec defines the desired state of BookkeeperCluster
type BookkeeperClusterSpec struct {
// ZookeeperUri specifies the hostname/IP address and port in the format
// "hostname:port".
// By default, the value "zk-client:2181" is used, that corresponds to the
// default Zookeeper service created by the Pravega Zookkeeper operator
// available at: https://github.com/pravega/zookeeper-operator
ZookeeperUri string `json:"zookeeperUri"`
// Image defines the BookKeeper Docker image to use.
// By default, "pravega/bookkeeper" will be used.
Image *BookkeeperImageSpec `json:"image"`
// Replicas defines the number of BookKeeper replicas.
// Minimum is 3. Defaults to 3.
Replicas int32 `json:"replicas"`
// Storage configures the storage for BookKeeper
Storage *BookkeeperStorageSpec `json:"storage"`
// AutoRecovery indicates whether or not BookKeeper auto recovery is enabled.
// Defaults to true.
AutoRecovery *bool `json:"autoRecovery"`
// ServiceAccountName configures the service account used on BookKeeper instances
ServiceAccountName string `json:"serviceAccountName,omitempty"`
// BookieResources specifies the request and limit of resources that bookie can have.
// BookieResources includes CPU and memory resources
Resources *v1.ResourceRequirements `json:"resources,omitempty"`
// Options is the Bookkeeper configuration that is to override the bk_server.conf
// in bookkeeper. Some examples can be found here
// https://github.com/apache/bookkeeper/blob/master/docker/README.md
Options map[string]string `json:"options"`
// JVM is the JVM options for bookkeeper. It will be passed to the JVM for performance tuning.
// If this field is not specified, the operator will use a set of default
// options that is good enough for general deployment.
JVMOptions *JVMOptions `json:"jvmOptions"`
// Provides the name of the configmap created by the user to provide additional key-value pairs
// that need to be configured into the bookie pods as environmental variables
EnvVars string `json:"envVars,omitempty"`
// Version is the expected version of the Pravega cluster.
// The pravega-operator will eventually make the Pravega cluster version
// equal to the expected version.
//
// The version must follow the [semver]( http://semver.org) format, for example "3.2.13".
// Only Pravega released versions are supported: https://github.com/pravega/pravega/releases
//
// If version is not set, default is "0.4.0".
Version string `json:"version"`
}
// BookkeeperImageSpec defines the fields needed for a BookKeeper Docker image
type BookkeeperImageSpec struct {
ImageSpec
}
func (s *BookkeeperImageSpec) withDefaults() (changed bool) {
if s.Repository == "" {
changed = true
s.Repository = DefaultBookkeeperImageRepository
}
s.Tag = ""
if s.PullPolicy == "" {
changed = true
s.PullPolicy = DefaultBookkeeperImagePullPolicy
}
return changed
}
type JVMOptions struct {
MemoryOpts []string `json:"memoryOpts"`
GcOpts []string `json:"gcOpts"`
GcLoggingOpts []string `json:"gcLoggingOpts"`
ExtraOpts []string `json:"extraOpts"`
}
func (s *JVMOptions) withDefaults() (changed bool) {
if s.MemoryOpts == nil {
changed = true
s.MemoryOpts = []string{}
}
if s.GcOpts == nil {
changed = true
s.GcOpts = []string{}
}
if s.GcLoggingOpts == nil {
changed = true
s.GcLoggingOpts = []string{}
}
if s.ExtraOpts == nil {
changed = true
s.ExtraOpts = []string{}
}
return changed
}
// BookkeeperStorageSpec is the configuration of the volumes used in BookKeeper
type BookkeeperStorageSpec struct {
// LedgerVolumeClaimTemplate is the spec to describe PVC for the BookKeeper ledger
// This field is optional. If no PVC spec and there is no default storage class,
// stateful containers will use emptyDir as volume
LedgerVolumeClaimTemplate *v1.PersistentVolumeClaimSpec `json:"ledgerVolumeClaimTemplate"`
// JournalVolumeClaimTemplate is the spec to describe PVC for the BookKeeper journal
// This field is optional. If no PVC spec and there is no default storage class,
// stateful containers will use emptyDir as volume
JournalVolumeClaimTemplate *v1.PersistentVolumeClaimSpec `json:"journalVolumeClaimTemplate"`
// IndexVolumeClaimTemplate is the spec to describe PVC for the BookKeeper index
// This field is optional. If no PVC spec and there is no default storage class,
// stateful containers will use emptyDir as volume
IndexVolumeClaimTemplate *v1.PersistentVolumeClaimSpec `json:"indexVolumeClaimTemplate"`
}
func (s *BookkeeperStorageSpec) withDefaults() (changed bool) {
if s.LedgerVolumeClaimTemplate == nil {
changed = true
s.LedgerVolumeClaimTemplate = &v1.PersistentVolumeClaimSpec{
AccessModes: []v1.PersistentVolumeAccessMode{v1.ReadWriteOnce},
Resources: v1.ResourceRequirements{
Requests: v1.ResourceList{
v1.ResourceStorage: resource.MustParse(DefaultBookkeeperLedgerVolumeSize),
},
},
}
}
if s.JournalVolumeClaimTemplate == nil {
changed = true
s.JournalVolumeClaimTemplate = &v1.PersistentVolumeClaimSpec{
AccessModes: []v1.PersistentVolumeAccessMode{v1.ReadWriteOnce},
Resources: v1.ResourceRequirements{
Requests: v1.ResourceList{
v1.ResourceStorage: resource.MustParse(DefaultBookkeeperJournalVolumeSize),
},
},
}
}
if s.IndexVolumeClaimTemplate == nil {
changed = true
s.IndexVolumeClaimTemplate = &v1.PersistentVolumeClaimSpec{
AccessModes: []v1.PersistentVolumeAccessMode{v1.ReadWriteOnce},
Resources: v1.ResourceRequirements{
Requests: v1.ResourceList{
v1.ResourceStorage: resource.MustParse(DefaultBookkeeperIndexVolumeSize),
},
},
}
}
return changed
}
func (s *BookkeeperClusterSpec) withDefaults() (changed bool) {
if s.ZookeeperUri == "" {
changed = true
s.ZookeeperUri = DefaultZookeeperUri
}
if s.Image == nil {
changed = true
s.Image = &BookkeeperImageSpec{}
}
if s.Image.withDefaults() {
changed = true
}
if !config.TestMode && s.Replicas < MinimumBookkeeperReplicas {
changed = true
s.Replicas = MinimumBookkeeperReplicas
}
if s.Storage == nil {
changed = true
s.Storage = &BookkeeperStorageSpec{}
}
if s.Storage.withDefaults() {
changed = true
}
if s.AutoRecovery == nil {
changed = true
boolTrue := true
s.AutoRecovery = &boolTrue
}
if s.Resources == nil {
changed = true
s.Resources = &v1.ResourceRequirements{
Requests: v1.ResourceList{
v1.ResourceCPU: resource.MustParse(DefaultBookkeeperRequestCPU),
v1.ResourceMemory: resource.MustParse(DefaultBookkeeperRequestMemory),
},
Limits: v1.ResourceList{
v1.ResourceCPU: resource.MustParse(DefaultBookkeeperLimitCPU),
v1.ResourceMemory: resource.MustParse(DefaultBookkeeperLimitMemory),
},
}
}
if s.Options == nil {
s.Options = map[string]string{}
}
if s.JVMOptions == nil {
changed = true
s.JVMOptions = &JVMOptions{}
}
if s.JVMOptions.withDefaults() {
changed = true
}
if s.Version == "" {
s.Version = DefaultBookkeeperVersion
changed = true
}
return changed
}
// ImageSpec defines the fields needed for a Docker repository image
type ImageSpec struct {
Repository string `json:"repository"`
// Deprecated: Use `spec.Version` instead
Tag string `json:"tag,omitempty"`
PullPolicy v1.PullPolicy `json:"pullPolicy"`
}