-
Notifications
You must be signed in to change notification settings - Fork 488
/
types.go
1965 lines (1675 loc) · 76.9 KB
/
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
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright 2018 PingCAP, Inc.
//
// 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,
// See the License for the specific language governing permissions and
// limitations under the License.
package v1alpha1
import (
"github.com/pingcap/tidb-operator/pkg/util/config"
apps "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
extensionsv1beta1 "k8s.io/api/extensions/v1beta1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
)
const (
// TiKVStateUp represents status of Up of TiKV
TiKVStateUp string = "Up"
// TiKVStateDown represents status of Down of TiKV
TiKVStateDown string = "Down"
// TiKVStateOffline represents status of Offline of TiKV
TiKVStateOffline string = "Offline"
// TiKVStateTombstone represents status of Tombstone of TiKV
TiKVStateTombstone string = "Tombstone"
// DMWorkerStateFree represents status of free of dm-worker
DMWorkerStateFree string = "free"
// DMWorkerStateBound represents status of bound of dm-worker
DMWorkerStateBound string = "bound"
// DMWorkerStateOffline represents status of offline of dm-worker
DMWorkerStateOffline string = "offline"
)
// MemberType represents member type
type MemberType string
const (
// PDMemberType is pd container type
PDMemberType MemberType = "pd"
// TiDBMemberType is tidb container type
TiDBMemberType MemberType = "tidb"
// TiKVMemberType is tikv container type
TiKVMemberType MemberType = "tikv"
// TiFlashMemberType is tiflash container type
TiFlashMemberType MemberType = "tiflash"
// TiCDCMemberType is ticdc container type
TiCDCMemberType MemberType = "ticdc"
// DMMasterMemberType is dm-master container type
DMMasterMemberType MemberType = "dm-master"
// DMWorkerMemberType is dm-worker container type
DMWorkerMemberType MemberType = "dm-worker"
// SlowLogTailerMemberType is tidb slow log tailer container type
SlowLogTailerMemberType MemberType = "slowlog"
// RocksDBLogTailerMemberType is tikv rocksdb log tailer container type
RocksDBLogTailerMemberType MemberType = "rocksdblog"
// RaftLogTailerMemberType is tikv raft log tailer container type
RaftLogTailerMemberType MemberType = "raftlog"
// TidbMonitorMemberType is tidbmonitor type
TidbMonitorMemberType MemberType = "tidbmonitor"
// UnknownMemberType is unknown container type
UnknownMemberType MemberType = "unknown"
)
// MemberPhase is the current state of member
type MemberPhase string
const (
// NormalPhase represents normal state of TiDB cluster.
NormalPhase MemberPhase = "Normal"
// UpgradePhase represents the upgrade state of TiDB cluster.
UpgradePhase MemberPhase = "Upgrade"
// ScalePhase represents the scaling state of TiDB cluster.
ScalePhase MemberPhase = "Scale"
)
// ConfigUpdateStrategy represents the strategy to update configuration
type ConfigUpdateStrategy string
const (
// ConfigUpdateStrategyInPlace update the configmap without changing the name
ConfigUpdateStrategyInPlace ConfigUpdateStrategy = "InPlace"
// ConfigUpdateStrategyRollingUpdate generate different configmap on configuration update and
// try to rolling-update the pod controller (e.g. statefulset) to apply updates.
ConfigUpdateStrategyRollingUpdate ConfigUpdateStrategy = "RollingUpdate"
)
// +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// TidbCluster is the control script's spec
// +k8s:openapi-gen=true
type TidbCluster struct {
metav1.TypeMeta `json:",inline"`
// +k8s:openapi-gen=false
metav1.ObjectMeta `json:"metadata"`
// Spec defines the behavior of a tidb cluster
Spec TidbClusterSpec `json:"spec"`
// +k8s:openapi-gen=false
// Most recently observed status of the tidb cluster
Status TidbClusterStatus `json:"status"`
}
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// TidbClusterList is TidbCluster list
// +k8s:openapi-gen=true
type TidbClusterList struct {
metav1.TypeMeta `json:",inline"`
// +k8s:openapi-gen=false
metav1.ListMeta `json:"metadata"`
Items []TidbCluster `json:"items"`
}
// TidbClusterSpec describes the attributes that a user creates on a tidb cluster
// +k8s:openapi-gen=true
type TidbClusterSpec struct {
// Discovery spec
Discovery DiscoverySpec `json:"discovery,omitempty"`
// Specify a Service Account
ServiceAccount string `json:"serviceAccount,omitempty"`
// PD cluster spec
// +optional
PD *PDSpec `json:"pd,omitempty"`
// TiDB cluster spec
// +optional
TiDB *TiDBSpec `json:"tidb,omitempty"`
// TiKV cluster spec
// +optional
TiKV *TiKVSpec `json:"tikv,omitempty"`
// TiFlash cluster spec
// +optional
TiFlash *TiFlashSpec `json:"tiflash,omitempty"`
// TiCDC cluster spec
// +optional
TiCDC *TiCDCSpec `json:"ticdc,omitempty"`
// Pump cluster spec
// +optional
Pump *PumpSpec `json:"pump,omitempty"`
// Helper spec
// +optional
Helper *HelperSpec `json:"helper,omitempty"`
// Indicates that the tidb cluster is paused and will not be processed by
// the controller.
// +optional
Paused bool `json:"paused,omitempty"`
// TiDB cluster version
// +optional
Version string `json:"version"`
// TODO: remove optional after defaulting logic introduced
// SchedulerName of TiDB cluster Pods
// +kubebuilder:default=tidb-scheduler
SchedulerName string `json:"schedulerName,omitempty"`
// Persistent volume reclaim policy applied to the PVs that consumed by TiDB cluster
// +kubebuilder:default=Retain
PVReclaimPolicy *corev1.PersistentVolumeReclaimPolicy `json:"pvReclaimPolicy,omitempty"`
// ImagePullPolicy of TiDB cluster Pods
// +kubebuilder:default=IfNotPresent
ImagePullPolicy corev1.PullPolicy `json:"imagePullPolicy,omitempty"`
// ImagePullSecrets is an optional list of references to secrets in the same namespace to use for pulling any of the images.
// +optional
ImagePullSecrets []corev1.LocalObjectReference `json:"imagePullSecrets,omitempty"`
// ConfigUpdateStrategy determines how the configuration change is applied to the cluster.
// UpdateStrategyInPlace will update the ConfigMap of configuration in-place and an extra rolling-update of the
// cluster component is needed to reload the configuration change.
// UpdateStrategyRollingUpdate will create a new ConfigMap with the new configuration and rolling-update the
// related components to use the new ConfigMap, that is, the new configuration will be applied automatically.
// +kubebuilder:validation:Enum=InPlace,RollingUpdate
// +kubebuilder:default=InPlacne
ConfigUpdateStrategy ConfigUpdateStrategy `json:"configUpdateStrategy,omitempty"`
// Whether enable PVC reclaim for orphan PVC left by statefulset scale-in
// Optional: Defaults to false
// +optional
EnablePVReclaim *bool `json:"enablePVReclaim,omitempty"`
// Whether enable the TLS connection between TiDB server components
// Optional: Defaults to nil
// +optional
TLSCluster *TLSCluster `json:"tlsCluster,omitempty"`
// Whether Hostnetwork is enabled for TiDB cluster Pods
// Optional: Defaults to false
// +optional
HostNetwork *bool `json:"hostNetwork,omitempty"`
// Affinity of TiDB cluster Pods.
// Will be overwritten by each cluster component's specific affinity setting, e.g. `spec.tidb.affinity`
// +optional
Affinity *corev1.Affinity `json:"affinity,omitempty"`
// PriorityClassName of TiDB cluster Pods
// Optional: Defaults to omitted
// +optional
PriorityClassName *string `json:"priorityClassName,omitempty"`
// Base node selectors of TiDB cluster Pods, components may add or override selectors upon this respectively
// +optional
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
// Base annotations of TiDB cluster Pods, components may add or override selectors upon this respectively
// +optional
Annotations map[string]string `json:"annotations,omitempty"`
// Base tolerations of TiDB cluster Pods, components may add more tolerations upon this respectively
// +optional
Tolerations []corev1.Toleration `json:"tolerations,omitempty"`
// Time zone of TiDB cluster Pods
// Optional: Defaults to UTC
// +optional
Timezone string `json:"timezone,omitempty"`
// (Deprecated) Services list non-headless services type used in TidbCluster
// +k8s:openapi-gen=false
Services []Service `json:"services,omitempty"`
// TODO: really deprecate this in code
// EnableDynamicConfiguration indicates whether to append `--advertise-status-addr` to the startup parameters of TiKV.
// +optional
EnableDynamicConfiguration *bool `json:"enableDynamicConfiguration,omitempty"`
// TODO: rename this into tikv-specific config name
// ClusterDomain is the Kubernetes Cluster Domain of TiDB cluster
// Optional: Defaults to ""
// +optional
ClusterDomain string `json:"clusterDomain,omitempty"`
// Cluster is the external cluster, if configured, the components in this TidbCluster will join to this configured cluster.
// +optional
Cluster *TidbClusterRef `json:"cluster,omitempty"`
// PDAddresses are the external PD addresses, if configured, the PDs in this TidbCluster will join to the configured PD cluster.
// +optional
PDAddresses []string `json:"pdAddresses,omitempty"`
// StatefulSetUpdateStrategy of TiDB cluster StatefulSets
// +optional
StatefulSetUpdateStrategy apps.StatefulSetUpdateStrategyType `json:"statefulSetUpdateStrategy,omitempty"`
}
// TidbClusterStatus represents the current status of a tidb cluster.
type TidbClusterStatus struct {
ClusterID string `json:"clusterID,omitempty"`
PD PDStatus `json:"pd,omitempty"`
TiKV TiKVStatus `json:"tikv,omitempty"`
TiDB TiDBStatus `json:"tidb,omitempty"`
Pump PumpStatus `json:"pump,omitempty"`
TiFlash TiFlashStatus `json:"tiflash,omitempty"`
TiCDC TiCDCStatus `json:"ticdc,omitempty"`
Monitor *TidbMonitorRef `json:"monitor,omitempty"`
AutoScaler *TidbClusterAutoScalerRef `json:"auto-scaler,omitempty"`
// Represents the latest available observations of a tidb cluster's state.
// +optional
Conditions []TidbClusterCondition `json:"conditions,omitempty"`
}
// TidbClusterCondition describes the state of a tidb cluster at a certain point.
type TidbClusterCondition struct {
// Type of the condition.
Type TidbClusterConditionType `json:"type"`
// Status of the condition, one of True, False, Unknown.
Status corev1.ConditionStatus `json:"status"`
// The last time this condition was updated.
LastUpdateTime metav1.Time `json:"lastUpdateTime,omitempty"`
// Last time the condition transitioned from one status to another.
// +optional
LastTransitionTime metav1.Time `json:"lastTransitionTime,omitempty"`
// The reason for the condition's last transition.
// +optional
Reason string `json:"reason,omitempty"`
// A human readable message indicating details about the transition.
// +optional
Message string `json:"message,omitempty"`
}
// TidbClusterConditionType represents a tidb cluster condition value.
type TidbClusterConditionType string
const (
// TidbClusterReady indicates that the tidb cluster is ready or not.
// This is defined as:
// - All statefulsets are up to date (currentRevision == updateRevision).
// - All PD members are healthy.
// - All TiDB pods are healthy.
// - All TiKV stores are up.
// - All TiFlash stores are up.
TidbClusterReady TidbClusterConditionType = "Ready"
)
// +k8s:openapi-gen=true
// DiscoverySpec contains details of Discovery members
type DiscoverySpec struct {
corev1.ResourceRequirements `json:",inline"`
}
// +k8s:openapi-gen=true
// PDSpec contains details of PD members
type PDSpec struct {
ComponentSpec `json:",inline"`
corev1.ResourceRequirements `json:",inline"`
// Specify a Service Account for pd
ServiceAccount string `json:"serviceAccount,omitempty"`
// The desired ready replicas
// +kubebuilder:validation:Minimum=1
Replicas int32 `json:"replicas"`
// Base image of the component, image tag is now allowed during validation
// +kubebuilder:default=pingcap/pd
// +optional
BaseImage string `json:"baseImage"`
// Service defines a Kubernetes service of PD cluster.
// Optional: Defaults to `.spec.services` in favor of backward compatibility
// +optional
Service *ServiceSpec `json:"service,omitempty"`
// MaxFailoverCount limit the max replicas could be added in failover, 0 means no failover.
// Optional: Defaults to 3
// +kubebuilder:validation:Minimum=0
// +optional
MaxFailoverCount *int32 `json:"maxFailoverCount,omitempty"`
// The storageClassName of the persistent volume for PD data storage.
// Defaults to Kubernetes default storage class.
// +optional
StorageClassName *string `json:"storageClassName,omitempty"`
// StorageVolumes configure additional storage for PD pods.
// +optional
StorageVolumes []StorageVolume `json:"storageVolumes,omitempty"`
// Subdirectory within the volume to store PD Data. By default, the data
// is stored in the root directory of volume which is mounted at
// /var/lib/pd.
// Specifying this will change the data directory to a subdirectory, e.g.
// /var/lib/pd/data if you set the value to "data".
// It's dangerous to change this value for a running cluster as it will
// upgrade your cluster to use a new storage directory.
// Defaults to "" (volume's root).
// +optional
DataSubDir string `json:"dataSubDir,omitempty"`
// Config is the Configuration of pd-servers
// +optional
Config *PDConfigWraper `json:"config,omitempty"`
// TLSClientSecretName is the name of secret which stores tidb server client certificate
// which used by Dashboard.
// +optional
TLSClientSecretName *string `json:"tlsClientSecretName,omitempty"`
// (Deprecated) EnableDashboardInternalProxy would directly set `internal-proxy` in the `PdConfig`.
// Note that this is deprecated, we should just set `dashboard.internal-proxy` in `pd.config`.
// +optional
EnableDashboardInternalProxy *bool `json:"enableDashboardInternalProxy,omitempty"`
// MountClusterClientSecret indicates whether to mount `cluster-client-secret` to the Pod
// +optional
MountClusterClientSecret *bool `json:"mountClusterClientSecret,omitempty"`
}
// TiKVSpec contains details of TiKV members
// +k8s:openapi-gen=true
type TiKVSpec struct {
ComponentSpec `json:",inline"`
corev1.ResourceRequirements `json:",inline"`
// Specify a Service Account for tikv
ServiceAccount string `json:"serviceAccount,omitempty"`
// The desired ready replicas
// +kubebuilder:validation:Minimum=1
Replicas int32 `json:"replicas"`
// Base image of the component, image tag is now allowed during validation
// +kubebuilder:default=pingcap/tikv
// +optional
BaseImage string `json:"baseImage"`
// Whether create the TiKV container in privileged mode, it is highly discouraged to enable this in
// critical environment.
// Optional: defaults to false
// +optional
Privileged *bool `json:"privileged,omitempty"`
// MaxFailoverCount limit the max replicas could be added in failover, 0 means no failover
// Optional: Defaults to 3
// +kubebuilder:validation:Minimum=0
// +optional
MaxFailoverCount *int32 `json:"maxFailoverCount,omitempty"`
// Whether output the RocksDB log in a separate sidecar container
// Optional: Defaults to false
// +optional
SeparateRocksDBLog *bool `json:"separateRocksDBLog,omitempty"`
// Whether output the Raft log in a separate sidecar container
// Optional: Defaults to false
// +optional
SeparateRaftLog *bool `json:"separateRaftLog,omitempty"`
// LogTailer is the configurations of the log tailers for TiKV
// +optional
LogTailer *LogTailerSpec `json:"logTailer,omitempty"`
// The storageClassName of the persistent volume for TiKV data storage.
// Defaults to Kubernetes default storage class.
// +optional
StorageClassName *string `json:"storageClassName,omitempty"`
// Subdirectory within the volume to store TiKV Data. By default, the data
// is stored in the root directory of volume which is mounted at
// /var/lib/tikv.
// Specifying this will change the data directory to a subdirectory, e.g.
// /var/lib/tikv/data if you set the value to "data".
// It's dangerous to change this value for a running cluster as it will
// upgrade your cluster to use a new storage directory.
// Defaults to "" (volume's root).
// +optional
DataSubDir string `json:"dataSubDir,omitempty"`
// Config is the Configuration of tikv-servers
// +optional
Config *TiKVConfigWraper `json:"config,omitempty"`
// RecoverFailover indicates that Operator can recover the failed Pods
// +optional
RecoverFailover bool `json:"recoverFailover,omitempty"`
// MountClusterClientSecret indicates whether to mount `cluster-client-secret` to the Pod
// +optional
MountClusterClientSecret *bool `json:"mountClusterClientSecret,omitempty"`
// EvictLeaderTimeout indicates the timeout to evict tikv leader, in the format of Go Duration.
// Defaults to 10m
// +optional
EvictLeaderTimeout *string `json:"evictLeaderTimeout,omitempty"`
// StorageVolumes configure additional storage for TiKV pods.
// +optional
StorageVolumes []StorageVolume `json:"storageVolumes,omitempty"`
// StoreLabels configures additional labels for TiKV stores.
// +optional
StoreLabels []string `json:"storeLabels,omitempty"`
}
// TiFlashSpec contains details of TiFlash members
// +k8s:openapi-gen=true
type TiFlashSpec struct {
ComponentSpec `json:",inline"`
corev1.ResourceRequirements `json:",inline"`
// Specify a Service Account for TiFlash
ServiceAccount string `json:"serviceAccount,omitempty"`
// The desired ready replicas
// +kubebuilder:validation:Minimum=1
Replicas int32 `json:"replicas"`
// Base image of the component, image tag is now allowed during validation
// +kubebuilder:default=pingcap/tiflash
// +optional
BaseImage string `json:"baseImage"`
// Whether create the TiFlash container in privileged mode, it is highly discouraged to enable this in
// critical environment.
// Optional: defaults to false
// +optional
Privileged *bool `json:"privileged,omitempty"`
// MaxFailoverCount limit the max replicas could be added in failover, 0 means no failover
// Optional: Defaults to 3
// +kubebuilder:validation:Minimum=0
// +optional
MaxFailoverCount *int32 `json:"maxFailoverCount,omitempty"`
// The persistent volume claims of the TiFlash data storages.
// TiFlash supports multiple disks.
StorageClaims []StorageClaim `json:"storageClaims"`
// Config is the Configuration of TiFlash
// +optional
Config *TiFlashConfigWraper `json:"config,omitempty"`
// LogTailer is the configurations of the log tailers for TiFlash
// +optional
LogTailer *LogTailerSpec `json:"logTailer,omitempty"`
// RecoverFailover indicates that Operator can recover the failover Pods
// +optional
RecoverFailover bool `json:"recoverFailover,omitempty"`
}
// TiCDCSpec contains details of TiCDC members
// +k8s:openapi-gen=true
type TiCDCSpec struct {
ComponentSpec `json:",inline"`
corev1.ResourceRequirements `json:",inline"`
// Specify a Service Account for TiCDC
ServiceAccount string `json:"serviceAccount,omitempty"`
// The desired ready replicas
// +kubebuilder:validation:Minimum=1
Replicas int32 `json:"replicas"`
// Base image of the component, image tag is now allowed during validation
// +kubebuilder:default=pingcap/ticdc
// +optional
BaseImage string `json:"baseImage"`
// Config is the Configuration of tidbcdc servers
// +optional
Config *TiCDCConfig `json:"config,omitempty"`
}
// TiCDCConfig is the configuration of tidbcdc
// +k8s:openapi-gen=true
type TiCDCConfig struct {
// Time zone of TiCDC
// Optional: Defaults to UTC
// +optional
Timezone *string `json:"timezone,omitempty"`
// CDC GC safepoint TTL duration, specified in seconds
// Optional: Defaults to 86400
// +optional
GCTTL *int32 `json:"gcTTL,omitempty"`
// LogLevel is the log level
// Optional: Defaults to info
// +optional
LogLevel *string `json:"logLevel,omitempty"`
// LogFile is the log file
// Optional: Defaults to /dev/stderr
// +optional
LogFile *string `json:"logFile,omitempty"`
}
// LogTailerSpec represents an optional log tailer sidecar container
// +k8s:openapi-gen=true
type LogTailerSpec struct {
corev1.ResourceRequirements `json:",inline"`
}
// StorageClaim contains details of TiFlash storages
// +k8s:openapi-gen=true
type StorageClaim struct {
// Resources represents the minimum resources the volume should have.
// More info: https://kubernetes.io/docs/concepts/storage/persistent-volumes#resources
// +optional
Resources corev1.ResourceRequirements `json:"resources,omitempty"`
// Name of the StorageClass required by the claim.
// More info: https://kubernetes.io/docs/concepts/storage/persistent-volumes#class-1
// +optional
StorageClassName *string `json:"storageClassName,omitempty"`
}
// TiDBSpec contains details of TiDB members
// +k8s:openapi-gen=true
type TiDBSpec struct {
ComponentSpec `json:",inline"`
corev1.ResourceRequirements `json:",inline"`
// Specify a Service Account for tidb
ServiceAccount string `json:"serviceAccount,omitempty"`
// The desired ready replicas
// +kubebuilder:validation:Minimum=0
Replicas int32 `json:"replicas"`
// Base image of the component, image tag is now allowed during validation
// +kubebuilder:default=pingcap/tidb
// +optional
BaseImage string `json:"baseImage"`
// Service defines a Kubernetes service of TiDB cluster.
// Optional: No kubernetes service will be created by default.
// +optional
Service *TiDBServiceSpec `json:"service,omitempty"`
// Whether enable TiDB Binlog, it is encouraged to not set this field and rely on the default behavior
// Optional: Defaults to true if PumpSpec is non-nil, otherwise false
// +optional
BinlogEnabled *bool `json:"binlogEnabled,omitempty"`
// MaxFailoverCount limit the max replicas could be added in failover, 0 means no failover
// Optional: Defaults to 3
// +kubebuilder:validation:Minimum=0
// +optional
MaxFailoverCount *int32 `json:"maxFailoverCount,omitempty"`
// Whether output the slow log in an separate sidecar container
// Optional: Defaults to true
// +optional
SeparateSlowLog *bool `json:"separateSlowLog,omitempty"`
// Optional volume name configuration for slow query log.
// +optional
SlowLogVolumeName string `json:"slowLogVolumeName,omitempty"`
// The specification of the slow log tailer sidecar
// +optional
SlowLogTailer *TiDBSlowLogTailerSpec `json:"slowLogTailer,omitempty"`
// Whether enable the TLS connection between the SQL client and TiDB server
// Optional: Defaults to nil
// +optional
TLSClient *TiDBTLSClient `json:"tlsClient,omitempty"`
// Plugins is a list of plugins that are loaded by TiDB server, empty means plugin disabled
// +optional
Plugins []string `json:"plugins,omitempty"`
// TODO: additional volumes should be used to hold .so plugin binaries.
// Because this is not a complete implementation, maybe we can change this without backward compatibility.
// Config is the Configuration of tidb-servers
// +optional
Config *TiDBConfigWraper `json:"config,omitempty"`
// Lifecycle describes actions that the management system should take in response to container lifecycle
// events. For the PostStart and PreStop lifecycle handlers, management of the container blocks
// until the action is complete, unless the container process fails, in which case the handler is aborted.
// +optional
Lifecycle *corev1.Lifecycle `json:"lifecycle,omitempty"`
// StorageVolumes configure additional storage for TiDB pods.
// +optional
StorageVolumes []StorageVolume `json:"storageVolumes,omitempty"`
// The storageClassName of the persistent volume for TiDB data storage.
// Defaults to Kubernetes default storage class.
// +optional
StorageClassName *string `json:"storageClassName,omitempty"`
// ReadinessProbe describes actions that probe the tidb's readiness.
// the default behavior is like setting type as "tcp"
// +optional
ReadinessProbe *TiDBProbe `json:"readinessProbe,omitempty"`
}
const (
// TCPProbeType represents the readiness prob method with TCP
TCPProbeType string = "tcp"
// CommandProbeType represents the readiness prob method with arbitrary unix `exec` call format commands
CommandProbeType string = "command"
)
// TiDBProbe contains details of probing tidb.
// +k8s:openapi-gen=true
// default probe by TCPPort on 4000.
type TiDBProbe struct {
// "tcp" will use TCP socket to connetct port 4000
//
// "command" will probe the status api of tidb.
// This will use curl command to request tidb, before v4.0.9 there is no curl in the image,
// So do not use this before v4.0.9.
// +kubebuilder:validation:Enum=tcp,command
// +optional
Type *string `json:"type,omitempty"` // tcp or command
}
// PumpSpec contains details of Pump members
// +k8s:openapi-gen=true
type PumpSpec struct {
ComponentSpec `json:",inline"`
corev1.ResourceRequirements `json:",inline"`
// Specify a Service Account for pump
ServiceAccount string `json:"serviceAccount,omitempty"`
// The desired ready replicas
// +kubebuilder:validation:Minimum=0
Replicas int32 `json:"replicas"`
// Base image of the component, image tag is now allowed during validation
// +kubebuilder:default=pingcap/tidb-binlog
// +optional
BaseImage string `json:"baseImage"`
// The storageClassName of the persistent volume for Pump data storage.
// Defaults to Kubernetes default storage class.
// +optional
StorageClassName *string `json:"storageClassName,omitempty"`
// The configuration of Pump cluster.
// +optional
Config *config.GenericConfig `json:"config,omitempty"`
// +k8s:openapi-gen=false
// For backward compatibility with helm chart
SetTimeZone *bool `json:"setTimeZone,omitempty"`
}
// HelperSpec contains details of helper component
// +k8s:openapi-gen=true
type HelperSpec struct {
// Image used to tail slow log and set kernel parameters if necessary, must have `tail` and `sysctl` installed
// Optional: Defaults to busybox:1.26.2
// +optional
Image *string `json:"image,omitempty"`
// ImagePullPolicy of the component. Override the cluster-level imagePullPolicy if present
// Optional: Defaults to the cluster-level setting
// +optional
ImagePullPolicy *corev1.PullPolicy `json:"imagePullPolicy,omitempty"`
}
// TiDBSlowLogTailerSpec represents an optional log tailer sidecar with TiDB
// +k8s:openapi-gen=true
type TiDBSlowLogTailerSpec struct {
corev1.ResourceRequirements `json:",inline"`
// (Deprecated) Image used for slowlog tailer.
// Use `spec.helper.image` instead
// +k8s:openapi-gen=false
Image *string `json:"image,omitempty"`
// (Deprecated) ImagePullPolicy of the component. Override the cluster-level imagePullPolicy if present
// Use `spec.helper.imagePullPolicy` instead
// +k8s:openapi-gen=false
ImagePullPolicy *corev1.PullPolicy `json:"imagePullPolicy,omitempty"`
}
// ComponentSpec is the base spec of each component, the fields should always accessed by the Basic<Component>Spec() method to respect the cluster-level properties
// +k8s:openapi-gen=true
type ComponentSpec struct {
// (Deprecated) Image of the component
// Use `baseImage` and `version` instead
// +k8s:openapi-gen=false
Image string `json:"image,omitempty"`
// Version of the component. Override the cluster-level version if non-empty
// Optional: Defaults to cluster-level setting
// +optional
Version *string `json:"version,omitempty"`
// ImagePullPolicy of the component. Override the cluster-level imagePullPolicy if present
// Optional: Defaults to cluster-level setting
// +optional
ImagePullPolicy *corev1.PullPolicy `json:"imagePullPolicy,omitempty"`
// ImagePullSecrets is an optional list of references to secrets in the same namespace to use for pulling any of the images.
// +optional
ImagePullSecrets []corev1.LocalObjectReference `json:"imagePullSecrets,omitempty"`
// Whether Hostnetwork of the component is enabled. Override the cluster-level setting if present
// Optional: Defaults to cluster-level setting
// +optional
HostNetwork *bool `json:"hostNetwork,omitempty"`
// Affinity of the component. Override the cluster-level setting if present.
// Optional: Defaults to cluster-level setting
// +optional
Affinity *corev1.Affinity `json:"affinity,omitempty"`
// PriorityClassName of the component. Override the cluster-level one if present
// Optional: Defaults to cluster-level setting
// +optional
PriorityClassName *string `json:"priorityClassName,omitempty"`
// SchedulerName of the component. Override the cluster-level one if present
// Optional: Defaults to cluster-level setting
// +optional
SchedulerName *string `json:"schedulerName,omitempty"`
// NodeSelector of the component. Merged into the cluster-level nodeSelector if non-empty
// Optional: Defaults to cluster-level setting
// +optional
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
// Annotations of the component. Merged into the cluster-level annotations if non-empty
// Optional: Defaults to cluster-level setting
// +optional
Annotations map[string]string `json:"annotations,omitempty"`
// Tolerations of the component. Override the cluster-level tolerations if non-empty
// Optional: Defaults to cluster-level setting
// +optional
Tolerations []corev1.Toleration `json:"tolerations,omitempty"`
// PodSecurityContext of the component
// +optional
PodSecurityContext *corev1.PodSecurityContext `json:"podSecurityContext,omitempty"`
// ConfigUpdateStrategy of the component. Override the cluster-level updateStrategy if present
// Optional: Defaults to cluster-level setting
// +optional
ConfigUpdateStrategy *ConfigUpdateStrategy `json:"configUpdateStrategy,omitempty"`
// List of environment variables to set in the container, like v1.Container.Env.
// Note that the following env names cannot be used and will be overridden by TiDB Operator builtin envs
// - NAMESPACE
// - TZ
// - SERVICE_NAME
// - PEER_SERVICE_NAME
// - HEADLESS_SERVICE_NAME
// - SET_NAME
// - HOSTNAME
// - CLUSTER_NAME
// - POD_NAME
// - BINLOG_ENABLED
// - SLOW_LOG_FILE
// +optional
Env []corev1.EnvVar `json:"env,omitempty"`
// Init containers of the components
// +optional
InitContainers []corev1.Container `json:"initContainers,omitempty"`
// Additional containers of the component.
// +optional
AdditionalContainers []corev1.Container `json:"additionalContainers,omitempty"`
// Additional volumes of component pod.
// +optional
AdditionalVolumes []corev1.Volume `json:"additionalVolumes,omitempty"`
// Additional volume mounts of component pod.
AdditionalVolumeMounts []corev1.VolumeMount `json:"additionalVolumeMounts,omitempty"`
// Optional duration in seconds the pod needs to terminate gracefully. May be decreased in delete request.
// Value must be non-negative integer. The value zero indicates delete immediately.
// If this value is nil, the default grace period will be used instead.
// The grace period is the duration in seconds after the processes running in the pod are sent
// a termination signal and the time when the processes are forcibly halted with a kill signal.
// Set this value longer than the expected cleanup time for your process.
// Defaults to 30 seconds.
// +optional
TerminationGracePeriodSeconds *int64 `json:"terminationGracePeriodSeconds,omitempty"`
// StatefulSetUpdateStrategy indicates the StatefulSetUpdateStrategy that will be
// employed to update Pods in the StatefulSet when a revision is made to
// Template.
// +optional
StatefulSetUpdateStrategy apps.StatefulSetUpdateStrategyType `json:"statefulSetUpdateStrategy,omitempty"`
}
// ServiceSpec specifies the service object in k8s
// +k8s:openapi-gen=true
type ServiceSpec struct {
// Type of the real kubernetes service
Type corev1.ServiceType `json:"type,omitempty"`
// Additional annotations of the kubernetes service object
// +optional
Annotations map[string]string `json:"annotations,omitempty"`
// LoadBalancerIP is the loadBalancerIP of service
// Optional: Defaults to omitted
// +optional
LoadBalancerIP *string `json:"loadBalancerIP,omitempty"`
// ClusterIP is the clusterIP of service
// +optional
ClusterIP *string `json:"clusterIP,omitempty"`
// PortName is the name of service port
// +optional
PortName *string `json:"portName,omitempty"`
// LoadBalancerSourceRanges is the loadBalancerSourceRanges of service
// If specified and supported by the platform, this will restrict traffic through the cloud-provider
// load-balancer will be restricted to the specified client IPs. This field will be ignored if the
// cloud-provider does not support the feature."
// More info: https://kubernetes.io/docs/concepts/services-networking/service/#aws-nlb-support
// Optional: Defaults to omitted
// +optional
LoadBalancerSourceRanges []string `json:"loadBalancerSourceRanges,omitempty"`
}
// TiDBServiceSpec defines `.tidb.service` field of `TidbCluster.spec`.
// +k8s:openapi-gen=true
type TiDBServiceSpec struct {
// +k8s:openapi-gen=false
ServiceSpec
// ExternalTrafficPolicy of the service
// Optional: Defaults to omitted
// +optional
ExternalTrafficPolicy *corev1.ServiceExternalTrafficPolicyType `json:"externalTrafficPolicy,omitempty"`
// Whether expose the status port
// Optional: Defaults to true
// +optional
ExposeStatus *bool `json:"exposeStatus,omitempty"`
// Expose the tidb cluster mysql port to MySQLNodePort
// Optional: Defaults to 0
// +optional
MySQLNodePort *int `json:"mysqlNodePort,omitempty"`
// Expose the tidb status node port to StatusNodePort
// Optional: Defaults to 0
// +optional
StatusNodePort *int `json:"statusNodePort,omitempty"`
// Expose additional ports for TiDB
// Optional: Defaults to omitted
// +optional
AdditionalPorts []corev1.ServicePort `json:"additionalPorts,omitempty"`
}
// (Deprecated) Service represent service type used in TidbCluster
// +k8s:openapi-gen=false
type Service struct {
Name string `json:"name,omitempty"`
Type string `json:"type,omitempty"`
}
// PDStatus is PD status
type PDStatus struct {
Synced bool `json:"synced,omitempty"`
Phase MemberPhase `json:"phase,omitempty"`
StatefulSet *apps.StatefulSetStatus `json:"statefulSet,omitempty"`
// Members contains PDs in current TidbCluster
Members map[string]PDMember `json:"members,omitempty"`
// PeerMembers contains PDs NOT in current TidbCluster
PeerMembers map[string]PDMember `json:"peerMembers,omitempty"`
Leader PDMember `json:"leader,omitempty"`
FailureMembers map[string]PDFailureMember `json:"failureMembers,omitempty"`
UnjoinedMembers map[string]UnjoinedMember `json:"unjoinedMembers,omitempty"`
Image string `json:"image,omitempty"`
}
// PDMember is PD member
type PDMember struct {
Name string `json:"name"`
// member id is actually a uint64, but apimachinery's json only treats numbers as int64/float64
// so uint64 may overflow int64 and thus convert to float64
ID string `json:"id"`
ClientURL string `json:"clientURL"`
Health bool `json:"health"`
// Last time the health transitioned from one to another.
LastTransitionTime metav1.Time `json:"lastTransitionTime,omitempty"`
}
// PDFailureMember is the pd failure member information
type PDFailureMember struct {
PodName string `json:"podName,omitempty"`
MemberID string `json:"memberID,omitempty"`
PVCUID types.UID `json:"pvcUID,omitempty"`
PVCUIDSet map[types.UID]struct{} `json:"pvcUIDSet,omitempty"`
MemberDeleted bool `json:"memberDeleted,omitempty"`
CreatedAt metav1.Time `json:"createdAt,omitempty"`
}
// UnjoinedMember is the pd unjoin cluster member information
type UnjoinedMember struct {
PodName string `json:"podName,omitempty"`
PVCUID types.UID `json:"pvcUID,omitempty"`
CreatedAt metav1.Time `json:"createdAt,omitempty"`
}
// TiDBStatus is TiDB status
type TiDBStatus struct {
Phase MemberPhase `json:"phase,omitempty"`
StatefulSet *apps.StatefulSetStatus `json:"statefulSet,omitempty"`
Members map[string]TiDBMember `json:"members,omitempty"`
FailureMembers map[string]TiDBFailureMember `json:"failureMembers,omitempty"`
ResignDDLOwnerRetryCount int32 `json:"resignDDLOwnerRetryCount,omitempty"`
Image string `json:"image,omitempty"`
}
// TiDBMember is TiDB member
type TiDBMember struct {
Name string `json:"name"`
Health bool `json:"health"`
// Last time the health transitioned from one to another.
LastTransitionTime metav1.Time `json:"lastTransitionTime,omitempty"`