|
| 1 | +// Copyright 2024 PingCAP, Inc. |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +package v1alpha1 |
| 16 | + |
| 17 | +import ( |
| 18 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 19 | +) |
| 20 | + |
| 21 | +const ( |
| 22 | + TiCDCPortName = "ticdc" // main port |
| 23 | + DefaultTiCDCPort = 8300 |
| 24 | +) |
| 25 | + |
| 26 | +const ( |
| 27 | + // TODO: combine all Health condition |
| 28 | + TiCDCCondHealth = "Health" |
| 29 | + TiCDCHealthReason = "TiCDCHealth" |
| 30 | + |
| 31 | + TiCDCCondSuspended = "Suspended" |
| 32 | + TiCDCSuspendReason = "TiCDCSuspend" |
| 33 | + |
| 34 | + TiCDCGroupCondAvailable = "Available" |
| 35 | + TiCDCGroupAvailableReason = "TiCDCGroupAvailable" |
| 36 | + |
| 37 | + TiCDCGroupCondSuspended = "Suspended" |
| 38 | + TiCDCGroupSuspendReason = "TiCDCGroupSuspend" |
| 39 | +) |
| 40 | + |
| 41 | +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object |
| 42 | +// +kubebuilder:object:root=true |
| 43 | + |
| 44 | +// TiCDCGroupList defines a list of TiCDC groups |
| 45 | +type TiCDCGroupList struct { |
| 46 | + metav1.TypeMeta `json:",inline"` |
| 47 | + metav1.ListMeta `json:"metadata,omitempty"` |
| 48 | + |
| 49 | + Items []TiCDCGroup `json:"items"` |
| 50 | +} |
| 51 | + |
| 52 | +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object |
| 53 | +// +kubebuilder:object:root=true |
| 54 | +// +kubebuilder:subresource:status |
| 55 | +// +kubebuilder:resource:categories=tc |
| 56 | +// +kubebuilder:resource:categories=tg |
| 57 | +// +kubebuilder:printcolumn:name="Cluster",type=string,JSONPath=`.spec.cluster.name` |
| 58 | +// +kubebuilder:printcolumn:name="Available",type=string,JSONPath=`.status.conditions[?(@.type=="Available")].status` |
| 59 | +// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp" |
| 60 | + |
| 61 | +// TiCDCGroup defines a group of similar TiCDC instances |
| 62 | +type TiCDCGroup struct { |
| 63 | + metav1.TypeMeta `json:",inline"` |
| 64 | + metav1.ObjectMeta `json:"metadata,omitempty"` |
| 65 | + |
| 66 | + Spec TiCDCGroupSpec `json:"spec,omitempty"` |
| 67 | + Status TiCDCGroupStatus `json:"status,omitempty"` |
| 68 | +} |
| 69 | + |
| 70 | +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object |
| 71 | +// +kubebuilder:object:root=true |
| 72 | + |
| 73 | +// TiCDCList defines a list of TiCDC instances |
| 74 | +type TiCDCList struct { |
| 75 | + metav1.TypeMeta `json:",inline"` |
| 76 | + metav1.ListMeta `json:"metadata,omitempty"` |
| 77 | + |
| 78 | + Items []TiCDC `json:"items"` |
| 79 | +} |
| 80 | + |
| 81 | +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object |
| 82 | +// +kubebuilder:object:root=true |
| 83 | +// +kubebuilder:subresource:status |
| 84 | +// +kubebuilder:resource:categories=tc |
| 85 | +// +kubebuilder:resource:categories=peer |
| 86 | +// +kubebuilder:printcolumn:name="Cluster",type=string,JSONPath=`.spec.cluster.name` |
| 87 | +// +kubebuilder:printcolumn:name="Healthy",type=string,JSONPath=`.status.conditions[?(@.type=="Health")].status` |
| 88 | +// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp" |
| 89 | + |
| 90 | +// TiCDC defines a TiCDC instance |
| 91 | +type TiCDC struct { |
| 92 | + metav1.TypeMeta `json:",inline"` |
| 93 | + metav1.ObjectMeta `json:"metadata,omitempty"` |
| 94 | + |
| 95 | + Spec TiCDCSpec `json:"spec,omitempty"` |
| 96 | + Status TiCDCStatus `json:"status,omitempty"` |
| 97 | +} |
| 98 | + |
| 99 | +// TiCDCGroupSpec describes the common attributes of a TiCDCGroup |
| 100 | +type TiCDCGroupSpec struct { |
| 101 | + Cluster ClusterReference `json:"cluster"` |
| 102 | + Replicas *int32 `json:"replicas"` |
| 103 | + |
| 104 | + // +listType=map |
| 105 | + // +listMapKey=type |
| 106 | + SchedulePolicies []SchedulePolicy `json:"schedulePolicies,omitempty"` |
| 107 | + |
| 108 | + Template TiCDCTemplate `json:"template"` |
| 109 | +} |
| 110 | + |
| 111 | +type TiCDCTemplate struct { |
| 112 | + ObjectMeta `json:"metadata,omitempty"` |
| 113 | + Spec TiCDCTemplateSpec `json:"spec"` |
| 114 | +} |
| 115 | + |
| 116 | +// TiCDCTemplateSpec can only be specified in TiCDCGroup |
| 117 | +type TiCDCTemplateSpec struct { |
| 118 | + Version string `json:"version"` |
| 119 | + // Image is TiCDC's image |
| 120 | + // If tag is omitted, version will be used as the image tag. |
| 121 | + // Default is pingcap/ticdc |
| 122 | + Image *string `json:"image,omitempty"` |
| 123 | + // Server defines server config for TiCDC |
| 124 | + Server TiCDCServer `json:"server,omitempty"` |
| 125 | + Resources ResourceRequirements `json:"resources,omitempty"` |
| 126 | + UpdateStrategy UpdateStrategy `json:"updateStrategy,omitempty"` |
| 127 | + // Config defines config file of TiCDC |
| 128 | + Config ConfigFile `json:"config,omitempty"` |
| 129 | + |
| 130 | + // Volumes defines persistent volumes of TiCDC, it is optional. |
| 131 | + // If you want to use ephemeral storage or mount sink TLS certs, you can use "overlay" instead. |
| 132 | + Volumes []Volume `json:"volumes,omitempty"` |
| 133 | + // Overlay defines a k8s native resource template patch |
| 134 | + // All resources(pod, pvcs, ...) managed by TiCDC can be overlayed by this field |
| 135 | + // +kubebuilder:validation:Schemaless |
| 136 | + // +kubebuilder:pruning:PreserveUnknownFields |
| 137 | + Overlay *Overlay `json:"overlay,omitempty"` |
| 138 | + |
| 139 | + // GracefulShutdownTimeout is the timeout of gracefully shutdown a TiCDC pod |
| 140 | + // when scaling in or rolling update. |
| 141 | + // Encoded in the format of Go Duration. |
| 142 | + // Defaults to 10m |
| 143 | + GracefulShutdownTimeout *metav1.Duration `json:"gracefulShutdownTimeout,omitempty"` |
| 144 | +} |
| 145 | + |
| 146 | +type TiCDCServer struct { |
| 147 | + // Ports defines all ports listened by TiCDC |
| 148 | + Ports TiCDCPorts `json:"ports,omitempty"` |
| 149 | +} |
| 150 | + |
| 151 | +type TiCDCPorts struct { |
| 152 | + // Port defines main port for TiCDC. |
| 153 | + Port *Port `json:"port,omitempty"` |
| 154 | +} |
| 155 | + |
| 156 | +type TiCDCGroupStatus struct { |
| 157 | + CommonStatus `json:",inline"` |
| 158 | + GroupStatus `json:",inline"` |
| 159 | +} |
| 160 | + |
| 161 | +// TiCDCSpec describes the common attributes of a TiCDC instance |
| 162 | +type TiCDCSpec struct { |
| 163 | + // Cluster is a reference of tidb cluster |
| 164 | + Cluster ClusterReference `json:"cluster"` |
| 165 | + |
| 166 | + // Topology defines the topology domain of this TiCDC instance |
| 167 | + // It will be translated into a node affinity config |
| 168 | + // Topology cannot be changed |
| 169 | + Topology Topology `json:"topology,omitempty"` |
| 170 | + |
| 171 | + // Subdomain means the subdomain of the exported TiCDC DNS. |
| 172 | + // A same TiCDC cluster will use a same subdomain |
| 173 | + Subdomain string `json:"subdomain"` |
| 174 | + |
| 175 | + // TiCDCTemplateSpec embedded some fields managed by TiCDCGroup |
| 176 | + TiCDCTemplateSpec `json:",inline"` |
| 177 | +} |
| 178 | + |
| 179 | +type TiCDCStatus struct { |
| 180 | + CommonStatus `json:",inline"` |
| 181 | + |
| 182 | + // ID is the member id of this TiCDC instance |
| 183 | + ID string `json:"id"` |
| 184 | + |
| 185 | + // should we need to save IsOwner in status? |
| 186 | + // but this value may be changed when scaling in or rolling update |
| 187 | +} |
0 commit comments