/
opensearch_types.go
411 lines (361 loc) · 17.8 KB
/
opensearch_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
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
/*
Copyright 2021.
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
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package v1
import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
)
const (
PhasePending = "PENDING"
PhaseRunning = "RUNNING"
)
// OpenSearchHealth is the health of the cluster as returned by the health API.
type OpenSearchHealth string
// Possible traffic light states OpenSearch health can have.
const (
OpenSearchRedHealth OpenSearchHealth = "red"
OpenSearchYellowHealth OpenSearchHealth = "yellow"
OpenSearchGreenHealth OpenSearchHealth = "green"
OpenSearchUnknownHealth OpenSearchHealth = "unknown"
)
// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
type GeneralConfig struct {
*ImageSpec `json:",inline,omitempty"`
//+kubebuilder:default=9200
HttpPort int32 `json:"httpPort,omitempty"`
//+kubebuilder:validation:Enum=Opensearch;Op;OP;os;opensearch
Vendor string `json:"vendor,omitempty"`
Version string `json:"version,omitempty"`
ServiceAccount string `json:"serviceAccount,omitempty"`
ServiceName string `json:"serviceName"`
SetVMMaxMapCount bool `json:"setVMMaxMapCount,omitempty"`
DefaultRepo *string `json:"defaultRepo,omitempty"`
// Extra items to add to the opensearch.yml
AdditionalConfig map[string]string `json:"additionalConfig,omitempty"`
// Adds support for annotations in services
Annotations map[string]string `json:"annotations,omitempty"`
// Drain data nodes controls whether to drain data notes on rolling restart operations
DrainDataNodes bool `json:"drainDataNodes,omitempty"`
PluginsList []string `json:"pluginsList,omitempty"`
Command string `json:"command,omitempty"`
// Additional volumes to mount to all pods in the cluster
AdditionalVolumes []AdditionalVolume `json:"additionalVolumes,omitempty"`
Monitoring MonitoringConfig `json:"monitoring,omitempty"`
// Populate opensearch keystore before startup
Keystore []KeystoreValue `json:"keystore,omitempty"`
SnapshotRepositories []SnapshotRepoConfig `json:"snapshotRepositories,omitempty"`
// Set security context for the cluster pods
PodSecurityContext *corev1.PodSecurityContext `json:"podSecurityContext,omitempty"`
// Set security context for the cluster pods' container
SecurityContext *corev1.SecurityContext `json:"securityContext,omitempty"`
}
type PdbConfig struct {
Enable bool `json:"enable,omitempty"`
MinAvailable *intstr.IntOrString `json:"minAvailable,omitempty"`
MaxUnavailable *intstr.IntOrString `json:"maxUnavailable,omitempty"`
}
type InitHelperConfig struct {
*ImageSpec `json:",inline,omitempty"`
Resources corev1.ResourceRequirements `json:"resources,omitempty"`
Version *string `json:"version,omitempty"`
}
type ProbesConfig struct {
Liveness *ProbeConfig `json:"liveness,omitempty"`
Readiness *ReadinessProbeConfig `json:"readiness,omitempty"`
Startup *ProbeConfig `json:"startup,omitempty"`
}
type ProbeConfig struct {
InitialDelaySeconds int32 `json:"initialDelaySeconds,omitempty"`
PeriodSeconds int32 `json:"periodSeconds,omitempty"`
TimeoutSeconds int32 `json:"timeoutSeconds,omitempty"`
SuccessThreshold int32 `json:"successThreshold,omitempty"`
FailureThreshold int32 `json:"failureThreshold,omitempty"`
}
type ReadinessProbeConfig struct {
InitialDelaySeconds int32 `json:"initialDelaySeconds,omitempty"`
PeriodSeconds int32 `json:"periodSeconds,omitempty"`
TimeoutSeconds int32 `json:"timeoutSeconds,omitempty"`
FailureThreshold int32 `json:"failureThreshold,omitempty"`
}
type NodePool struct {
Component string `json:"component"`
Replicas int32 `json:"replicas"`
DiskSize string `json:"diskSize,omitempty"`
Resources corev1.ResourceRequirements `json:"resources,omitempty"`
Jvm string `json:"jvm,omitempty"`
Roles []string `json:"roles"`
Tolerations []corev1.Toleration `json:"tolerations,omitempty"`
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
Affinity *corev1.Affinity `json:"affinity,omitempty"`
TopologySpreadConstraints []corev1.TopologySpreadConstraint `json:"topologySpreadConstraints,omitempty"`
Persistence *PersistenceConfig `json:"persistence,omitempty"`
AdditionalConfig map[string]string `json:"additionalConfig,omitempty"`
Labels map[string]string `json:"labels,omitempty"`
Annotations map[string]string `json:"annotations,omitempty"`
Env []corev1.EnvVar `json:"env,omitempty"`
PriorityClassName string `json:"priorityClassName,omitempty"`
Pdb *PdbConfig `json:"pdb,omitempty"`
Probes *ProbesConfig `json:"probes,omitempty"`
}
// PersistencConfig defines options for data persistence
type PersistenceConfig struct {
PersistenceSource `json:","`
}
type PersistenceSource struct {
PVC *PVCSource `json:"pvc,omitempty"`
EmptyDir *corev1.EmptyDirVolumeSource `json:"emptyDir,omitempty"`
HostPath *corev1.HostPathVolumeSource `json:"hostPath,omitempty"`
}
type PVCSource struct {
StorageClassName string `json:"storageClass,omitempty"`
AccessModes []corev1.PersistentVolumeAccessMode `json:"accessModes,omitempty"`
}
// ConfMgmt defines which additional services will be deployed
type ConfMgmt struct {
AutoScaler bool `json:"autoScaler,omitempty"`
VerUpdate bool `json:"VerUpdate,omitempty"`
SmartScaler bool `json:"smartScaler,omitempty"`
}
type MonitoringConfig struct {
Enable bool `json:"enable,omitempty"`
MonitoringUserSecret string `json:"monitoringUserSecret,omitempty"`
ScrapeInterval string `json:"scrapeInterval,omitempty"`
PluginURL string `json:"pluginUrl,omitempty"`
TLSConfig *MonitoringConfigTLS `json:"tlsConfig,omitempty"`
Labels map[string]string `json:"labels,omitempty"`
}
type MonitoringConfigTLS struct {
ServerName string `json:"serverName,omitempty"`
InsecureSkipVerify bool `json:"insecureSkipVerify,omitempty"`
}
type BootstrapConfig struct {
Resources corev1.ResourceRequirements `json:"resources,omitempty"`
Tolerations []corev1.Toleration `json:"tolerations,omitempty"`
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
Affinity *corev1.Affinity `json:"affinity,omitempty"`
Jvm string `json:"jvm,omitempty"`
// Extra items to add to the opensearch.yml, defaults to General.AdditionalConfig
AdditionalConfig map[string]string `json:"additionalConfig,omitempty"`
}
type DashboardsServiceSpec struct {
// +kubebuilder:validation:Enum=ClusterIP;NodePort;LoadBalancer
// +kubebuilder:default=ClusterIP
Type corev1.ServiceType `json:"type,omitempty"`
LoadBalancerSourceRanges []string `json:"loadBalancerSourceRanges,omitempty"`
}
type DashboardsConfig struct {
*ImageSpec `json:",inline,omitempty"`
Enable bool `json:"enable,omitempty"`
Resources corev1.ResourceRequirements `json:"resources,omitempty"`
Replicas int32 `json:"replicas"`
Tls *DashboardsTlsConfig `json:"tls,omitempty"`
Version string `json:"version"`
// Base Path for Opensearch Clusters running behind a reverse proxy
BasePath string `json:"basePath,omitempty"`
// Additional properties for opensearch_dashboards.yaml
AdditionalConfig map[string]string `json:"additionalConfig,omitempty"`
// Secret that contains fields username and password for dashboards to use to login to opensearch, must only be supplied if a custom securityconfig is provided
OpensearchCredentialsSecret corev1.LocalObjectReference `json:"opensearchCredentialsSecret,omitempty"`
Env []corev1.EnvVar `json:"env,omitempty"`
AdditionalVolumes []AdditionalVolume `json:"additionalVolumes,omitempty"`
Tolerations []corev1.Toleration `json:"tolerations,omitempty"`
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
Affinity *corev1.Affinity `json:"affinity,omitempty"`
Labels map[string]string `json:"labels,omitempty"`
Annotations map[string]string `json:"annotations,omitempty"`
Service DashboardsServiceSpec `json:"service,omitempty"`
PluginsList []string `json:"pluginsList,omitempty"`
// Set security context for the dashboards pods
PodSecurityContext *corev1.PodSecurityContext `json:"podSecurityContext,omitempty"`
// Set security context for the dashboards pods' container
SecurityContext *corev1.SecurityContext `json:"securityContext,omitempty"`
}
type DashboardsTlsConfig struct {
// Enable HTTPS for Dashboards
Enable bool `json:"enable,omitempty"`
// Generate certificate, if false secret must be provided
Generate bool `json:"generate,omitempty"`
// foobar
TlsCertificateConfig `json:",omitempty"`
}
// Security defines options for managing the opensearch-security plugin
type Security struct {
Tls *TlsConfig `json:"tls,omitempty"`
Config *SecurityConfig `json:"config,omitempty"`
}
// Configure tls usage for transport and http interface
type TlsConfig struct {
Transport *TlsConfigTransport `json:"transport,omitempty"`
Http *TlsConfigHttp `json:"http,omitempty"`
}
type TlsConfigTransport struct {
// If set to true the operator will generate a CA and certificates for the cluster to use, if false secrets with existing certificates must be supplied
Generate bool `json:"generate,omitempty"`
// Configure transport node certificate
PerNode bool `json:"perNode,omitempty"`
TlsCertificateConfig `json:",omitempty"`
// Allowed Certificate DNs for nodes, only used when existing certificates are provided
NodesDn []string `json:"nodesDn,omitempty"`
// DNs of certificates that should have admin access, mainly used for securityconfig updates via securityadmin.sh, only used when existing certificates are provided
AdminDn []string `json:"adminDn,omitempty"`
}
type TlsConfigHttp struct {
// If set to true the operator will generate a CA and certificates for the cluster to use, if false secrets with existing certificates must be supplied
Generate bool `json:"generate,omitempty"`
TlsCertificateConfig `json:",omitempty"`
}
type TlsCertificateConfig struct {
// Optional, name of a TLS secret that contains ca.crt, tls.key and tls.crt data. If ca.crt is in a different secret provide it via the caSecret field
Secret corev1.LocalObjectReference `json:"secret,omitempty"`
// Optional, secret that contains the ca certificate as ca.crt. If this and generate=true is set the existing CA cert from that secret is used to generate the node certs. In this case must contain ca.crt and ca.key fields
CaSecret corev1.LocalObjectReference `json:"caSecret,omitempty"`
}
// Reference to a secret
type TlsSecret struct {
SecretName string `json:"secretName"`
Key *string `json:"key,omitempty"`
}
type SecurityConfig struct {
// Secret that contains the differnt yml files of the opensearch-security config (config.yml, internal_users.yml, ...)
SecurityconfigSecret corev1.LocalObjectReference `json:"securityConfigSecret,omitempty"`
// TLS Secret that contains a client certificate (tls.key, tls.crt, ca.crt) with admin rights in the opensearch cluster. Must be set if transport certificates are provided by user and not generated
AdminSecret corev1.LocalObjectReference `json:"adminSecret,omitempty"`
// Secret that contains fields username and password to be used by the operator to access the opensearch cluster for node draining. Must be set if custom securityconfig is provided.
AdminCredentialsSecret corev1.LocalObjectReference `json:"adminCredentialsSecret,omitempty"`
UpdateJob SecurityUpdateJobConfig `json:"updateJob,omitempty"`
}
// Specific configs for the SecurityConfig update job
type SecurityUpdateJobConfig struct {
Resources corev1.ResourceRequirements `json:"resources,omitempty"`
}
type ImageSpec struct {
Image *string `json:"image,omitempty"`
ImagePullPolicy *corev1.PullPolicy `json:"imagePullPolicy,omitempty"`
ImagePullSecrets []corev1.LocalObjectReference `json:"imagePullSecrets,omitempty"`
}
type AdditionalVolume struct {
// Name to use for the volume. Required.
Name string `json:"name"`
// Path in the container to mount the volume at. Required.
Path string `json:"path"`
// SubPath of the referenced volume to mount.
SubPath string `json:"subPath,omitempty"`
// Secret to use populate the volume
Secret *corev1.SecretVolumeSource `json:"secret,omitempty"`
// ConfigMap to use to populate the volume
ConfigMap *corev1.ConfigMapVolumeSource `json:"configMap,omitempty"`
// EmptyDir to use to populate the volume
EmptyDir *corev1.EmptyDirVolumeSource `json:"emptyDir,omitempty"`
// CSI object to use to populate the volume
CSI *corev1.CSIVolumeSource `json:"csi,omitempty"`
// Whether to restart the pods on content change
RestartPods bool `json:"restartPods,omitempty"`
}
type KeystoreValue struct {
// Secret containing key value pairs
Secret corev1.LocalObjectReference `json:"secret,omitempty"`
// Key mappings from secret to keystore keys
KeyMappings map[string]string `json:"keyMappings,omitempty"`
}
type SnapshotRepoConfig struct {
Name string `json:"name"`
Type string `json:"type"`
Settings map[string]string `json:"settings,omitempty"`
}
// ClusterSpec defines the desired state of OpenSearchCluster
type ClusterSpec struct {
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
// Important: Run "make" to regenerate code after modifying this file
General GeneralConfig `json:"general,omitempty"`
ConfMgmt ConfMgmt `json:"confMgmt,omitempty"`
Bootstrap BootstrapConfig `json:"bootstrap,omitempty"`
Dashboards DashboardsConfig `json:"dashboards,omitempty"`
Security *Security `json:"security,omitempty"`
NodePools []NodePool `json:"nodePools"`
InitHelper InitHelperConfig `json:"initHelper,omitempty"`
}
// ClusterStatus defines the observed state of Es
type ClusterStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
// Important: Run "make" to regenerate code after modifying this file
Phase string `json:"phase,omitempty"`
ComponentsStatus []ComponentStatus `json:"componentsStatus"`
Version string `json:"version,omitempty"`
Initialized bool `json:"initialized,omitempty"`
// AvailableNodes is the number of available instances.
AvailableNodes int32 `json:"availableNodes,omitempty"`
Health OpenSearchHealth `json:"health,omitempty"`
}
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:resource:shortName=os;opensearch
// Es is the Schema for the es API
// +kubebuilder:printcolumn:name="health",type="string",JSONPath=".status.health"
// +kubebuilder:printcolumn:name="nodes",type="integer",JSONPath=".status.availableNodes",description="Available nodes"
// +kubebuilder:printcolumn:name="version",type="string",JSONPath=".status.version",description="Opensearch version"
// +kubebuilder:printcolumn:name="phase",type="string",JSONPath=".status.phase"
// +kubebuilder:printcolumn:name="age",type="date",JSONPath=".metadata.creationTimestamp"
type OpenSearchCluster struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec ClusterSpec `json:"spec,omitempty"`
Status ClusterStatus `json:"status,omitempty"`
}
type ComponentStatus struct {
Component string `json:"component,omitempty"`
Status string `json:"status,omitempty"`
Description string `json:"description,omitempty"`
Conditions []string `json:"conditions,omitempty"`
}
// +kubebuilder:object:root=true
// EsList contains a list of Es
type OpenSearchClusterList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []OpenSearchCluster `json:"items"`
}
func init() {
SchemeBuilder.Register(&OpenSearchCluster{}, &OpenSearchClusterList{})
}
func (s ImageSpec) GetImagePullPolicy() (_ corev1.PullPolicy) {
if p := s.ImagePullPolicy; p != nil {
return *p
}
return
}
func (s ImageSpec) GetImage() string {
if s.Image == nil {
return ""
}
return *s.Image
}
func (s *Security) GetConfig() *SecurityConfig {
if s == nil {
return nil
}
return s.Config
}
func (s *Security) GetTls() *TlsConfig {
if s == nil {
return nil
}
return s.Tls
}
func (sc *SecurityConfig) GetUpdateJob() SecurityUpdateJobConfig {
if sc == nil {
return SecurityUpdateJobConfig{}
}
return sc.UpdateJob
}