/
managementcenter_types.go
373 lines (300 loc) · 12.8 KB
/
managementcenter_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
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
package v1alpha1
import (
"fmt"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// ManagementCenterSpec defines the desired state of ManagementCenter.
type ManagementCenterSpec struct {
// Repository to pull the Management Center image from.
// +kubebuilder:default:="docker.io/hazelcast/management-center"
// +optional
Repository string `json:"repository,omitempty"`
// Version of Management Center.
// +kubebuilder:default:="5.3.3"
// +optional
Version string `json:"version,omitempty"`
// Pull policy for the Management Center image
// +kubebuilder:default:="IfNotPresent"
// +optional
ImagePullPolicy corev1.PullPolicy `json:"imagePullPolicy,omitempty"`
// Image pull secrets for the Management Center image
// +optional
ImagePullSecrets []corev1.LocalObjectReference `json:"imagePullSecrets,omitempty"`
// licenseKeySecret is a deprecated alias for licenseKeySecretName.
// +optional
DeprecatedLicenseKeySecret string `json:"licenseKeySecret,omitempty"`
// Name of the secret with Hazelcast Enterprise License Key.
// +optional
LicenseKeySecretName string `json:"licenseKeySecretName,omitempty"`
// Connection configuration for the Hazelcast clusters that Management Center will monitor.
// +optional
HazelcastClusters []HazelcastClusterConfig `json:"hazelcastClusters,omitempty"`
// Configuration to expose Management Center to outside.
// +kubebuilder:default:={type: "LoadBalancer"}
// +optional
ExternalConnectivity *ExternalConnectivityConfiguration `json:"externalConnectivity,omitempty"`
// Configuration for Management Center persistence.
// +kubebuilder:default:={enabled: true, size: "10Gi"}
// +optional
Persistence *MCPersistenceConfiguration `json:"persistence,omitempty"`
// Scheduling details
// +kubebuilder:default:={}
// +optional
Scheduling *SchedulingConfiguration `json:"scheduling,omitempty"`
// Compute Resources required by the MC container.
// +kubebuilder:default:={}
// +optional
Resources *corev1.ResourceRequirements `json:"resources,omitempty"`
// ManagementCenter JVM configuration
// +optional
JVM *MCJVMConfiguration `json:"jvm,omitempty"`
// SecurityProviders to authenticate users in Management Center
// +optional
SecurityProviders *SecurityProviders `json:"securityProvider,omitempty"`
// ManagementCenter Kubernetes resource annotations
// +optional
Annotations map[string]string `json:"annotations,omitempty"`
// ManagementCenter Kubernetes resource labels
// +optional
Labels map[string]string `json:"labels,omitempty"`
}
func (s *ManagementCenterSpec) GetLicenseKeySecretName() string {
if s.LicenseKeySecretName == "" {
return s.DeprecatedLicenseKeySecret
}
return s.LicenseKeySecretName
}
type SecurityProviders struct {
// LDAP security provider
// +optional
LDAP *LDAPProvider `json:"ldap,omitempty"`
}
type LDAPProvider struct {
// URL of your LDAP server, including schema (ldap://) and port.
// +required
URL string `json:"url"`
// CredentialsSecretName is the name of the secret that contains username and password of a user that has admin privileges on the LDAP server.
// The username must be the DN of the user. It is used to connect to the server when authenticating users.
// +required
CredentialsSecretName string `json:"credentialsSecretName"`
// DN to be used for searching users.
// +required
UserDN string `json:"userDN"`
// DN to be used for searching groups.
// +required
GroupDN string `json:"groupDN"`
// Members of these groups and its nested groups have admin privileges on the Management Center.
// +kubebuilder:validation:MinItems:=1
AdminGroups []string `json:"adminGroups"`
// Members of these groups and its nested groups have read and write privileges on the Management Center.
// +kubebuilder:validation:MinItems:=1
UserGroups []string `json:"userGroups"`
// Members of these groups and its nested groups have only read privilege on the Management Center.
// +kubebuilder:validation:MinItems:=1
ReadonlyUserGroups []string `json:"readonlyUserGroups"`
// Members of these groups and its nested groups have the privilege to see only the metrics on the Management Center.
// +kubebuilder:validation:MinItems:=1
MetricsOnlyGroups []string `json:"metricsOnlyGroups"`
// LDAP search filter expression to search for the users.
// For example, uid={0} searches for a username that matches with the uid attribute.
// +required
UserSearchFilter string `json:"userSearchFilter"`
// LDAP search filter expression to search for the groups.
// For example, uniquemember={0} searches for a group that matches with the uniquemember attribute.
// +required
GroupSearchFilter string `json:"groupSearchFilter"`
// NestedGroupSearch enables searching for nested LDAP groups.
// +kubebuilder:default:=false
NestedGroupSearch bool `json:"nestedGroupSearch"`
}
type HazelcastClusterConfig struct {
// Name of the Hazelcast cluster that Management Center will connect to, default is dev.
// +kubebuilder:default:="dev"
// +optional
Name string `json:"name,omitempty"`
// IP address or DNS name of the Hazelcast cluster.
// If the cluster is exposed with a service name in a different namespace, use the following syntax "<service-name>.<service-namespace>".
// +required
Address string `json:"address"`
// TLS client configuration.
// +optional
TLS *TLS `json:"tls,omitempty"`
}
// ExternalConnectivityConfiguration defines how to expose Management Center pod.
type ExternalConnectivityConfiguration struct {
// How Management Center is exposed.
// Valid values are:
// - "ClusterIP"
// - "NodePort"
// - "LoadBalancer" (default)
// +kubebuilder:default:="LoadBalancer"
// +optional
Type ExternalConnectivityType `json:"type,omitempty"`
// Ingress configuration of Management Center
// +optional
Ingress *ExternalConnectivityIngress `json:"ingress,omitempty"`
// OpenShift Route configuration of Management Center
// +optional
Route *ExternalConnectivityRoute `json:"route,omitempty"`
}
// ManagementCenterServiceType returns service type that is used by Management Center (LoadBalancer by default).
func (ec *ExternalConnectivityConfiguration) ManagementCenterServiceType() corev1.ServiceType {
if ec == nil {
return corev1.ServiceTypeClusterIP
}
switch ec.Type {
case ExternalConnectivityTypeClusterIP:
return corev1.ServiceTypeClusterIP
case ExternalConnectivityTypeNodePort:
return corev1.ServiceTypeNodePort
default:
return corev1.ServiceTypeLoadBalancer
}
}
// IsEnabled returns true if external connectivity is enabled.
func (ec *ExternalConnectivityConfiguration) IsEnabled() bool {
return ec != nil && *ec != ExternalConnectivityConfiguration{}
}
// ExternalConnectivityType describes how Management Center is exposed.
// +kubebuilder:validation:Enum=ClusterIP;NodePort;LoadBalancer
type ExternalConnectivityType string
const (
// ExternalConnectivityTypeClusterIP exposes Management Center with ClusterIP service.
ExternalConnectivityTypeClusterIP ExternalConnectivityType = "ClusterIP"
// ExternalConnectivityTypeNodePort exposes Management Center with NodePort service.
ExternalConnectivityTypeNodePort ExternalConnectivityType = "NodePort"
// ExternalConnectivityTypeLoadBalancer exposes Management Center with LoadBalancer service.
ExternalConnectivityTypeLoadBalancer ExternalConnectivityType = "LoadBalancer"
)
// ExternalConnectivityIngress defines ingress configuration of Management Center
type ExternalConnectivityIngress struct {
// Hostname of Management Center exposed by Ingress.
// Ingress controller will use this hostname to route inbound traffic.
// +required
Hostname string `json:"hostname"`
// IngressClassName of the ingress object.
// +optional
IngressClassName string `json:"ingressClassName,omitempty"`
// Annotations added to the ingress object.
// +optional
Annotations map[string]string `json:"annotations,omitempty"`
// Path of the ingress rule.
// +kubebuilder:default:="/"
// +optional
Path string `json:"path,omitempty"`
}
// ExternalConnectivityRoute defines OpenShift route configuration of Management Center
type ExternalConnectivityRoute struct {
// Hostname of Management Center exposed by route.
// Openshift routers will use this hostname to route inbound traffic.
Hostname string `json:"hostname"`
}
// IsEnabled returns true if external connectivity ingress is enabled.
func (eci *ExternalConnectivityIngress) IsEnabled() bool {
return eci != nil
}
// IsEnabled returns true if external connectivity ingress is enabled.
func (ecr *ExternalConnectivityRoute) IsEnabled() bool {
return ecr != nil
}
type MCPersistenceConfiguration struct {
// When true, MC will use a PersistentVolumeClaim to store data.
// +kubebuilder:default:=true
// +optional
Enabled *bool `json:"enabled,omitempty"`
// Name of the PersistentVolumeClaim MC will use for persistence. If not empty,
// MC will use the existing claim instead of creating a new one.
// +optional
ExistingVolumeClaimName string `json:"existingVolumeClaimName,omitempty"`
// StorageClass from which PersistentVolumeClaim will be created.
// +optional
StorageClass *string `json:"storageClass,omitempty"`
// Size of the created PersistentVolumeClaim.
// +kubebuilder:default:="10Gi"
// +optional
Size *resource.Quantity `json:"size,omitempty"`
}
// IsEnabled returns true if persistence configuration is specified.
func (pc *MCPersistenceConfiguration) IsEnabled() bool {
return pc != nil && pc.Enabled != nil && *pc.Enabled
}
// MCJVMConfiguration is a ManagementCenter JVM configuration
type MCJVMConfiguration struct {
// Args is for arbitrary JVM arguments
// +optional
Args []string `json:"args,omitempty"`
}
func (c *MCJVMConfiguration) IsConfigured() bool {
return c != nil && c.Args != nil && len(c.Args) > 0
}
func (sp *SecurityProviders) IsEnabled() bool {
return sp != nil && sp.LDAP != nil
}
// MCPhase represents the current state of the cluster
// +kubebuilder:validation:Enum=Running;Failed;Pending;Configuring;Terminating
type MCPhase string
const (
// McRunning phase is the state when the ManagementCenter is successfully started
McRunning MCPhase = "Running"
// McFailed phase is the state of error during the ManagementCenter startup
McFailed MCPhase = "Failed"
// McConfiguring phase is the state of configuring the ManagementCenter and might be restated
McConfiguring MCPhase = "Configuring"
// McPending phase is the state of starting the cluster when the ManagementCenter is not started yet
McPending MCPhase = "Pending"
// McTerminating phase is the state where deletion of ManagementCenter and dependent resources happen
McTerminating MCPhase = "Terminating"
)
// ManagementCenterStatus defines the observed state of ManagementCenter.
type ManagementCenterStatus struct {
// Phase of the Management Center
// +optional
Phase MCPhase `json:"phase,omitempty"`
// Configured is a flag that indicates if the configuration step has successfully passed
// +optional
Configured bool `json:"configured"`
// Message about the Management Center state
// +optional
Message string `json:"message,omitempty"`
// External addresses of the Management Center instance
// +optional
ExternalAddresses string `json:"externalAddresses,omitempty"`
}
//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
// ManagementCenter is the Schema for the managementcenters API
// +kubebuilder:subresource:status
// +kubebuilder:printcolumn:name="Status",type="string",JSONPath=".status.phase",description="Current state of the Management Center deployment"
// +kubebuilder:printcolumn:name="External-Addresses",type="string",JSONPath=".status.externalAddresses",description="External addresses of the Management Center deployment"
// +kubebuilder:printcolumn:name="Message",type="string",priority=1,JSONPath=".status.message",description="Message for the current ManagementCenter Config"
// +kubebuilder:resource:shortName=mc
type ManagementCenter struct {
metav1.TypeMeta `json:",inline"`
// +optional
metav1.ObjectMeta `json:"metadata,omitempty"`
// Initial values will be filled with its fields' default values.
// +kubebuilder:default:={"repository" : "docker.io/hazelcast/management-center"}
// +optional
Spec ManagementCenterSpec `json:"spec,omitempty"`
// +optional
Status ManagementCenterStatus `json:"status,omitempty"`
}
func (mc *ManagementCenter) DockerImage() string {
return fmt.Sprintf("%s:%s", mc.Spec.Repository, mc.Spec.Version)
}
func (mc *ManagementCenter) ExternalAddressEnabled() bool {
return mc.Spec.ExternalConnectivity.IsEnabled() &&
mc.Spec.ExternalConnectivity.Type == ExternalConnectivityTypeLoadBalancer
}
//+kubebuilder:object:root=true
// ManagementCenterList contains a list of ManagementCenter
type ManagementCenterList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []ManagementCenter `json:"items"`
}
func init() {
SchemeBuilder.Register(&ManagementCenter{}, &ManagementCenterList{})
}