|
| 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 | + meta "github.com/pingcap/tidb-operator/api/v2/meta/v1alpha1" |
| 21 | +) |
| 22 | + |
| 23 | +const ( |
| 24 | + ResourceManagerPortNameClient = "client" |
| 25 | + DefaultResourceManagerPortClient = 3379 |
| 26 | + |
| 27 | + // DefaultResourceManagerMinReadySeconds is default min ready seconds of resource manager |
| 28 | + DefaultResourceManagerMinReadySeconds = 5 |
| 29 | +) |
| 30 | + |
| 31 | +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object |
| 32 | +// +kubebuilder:object:root=true |
| 33 | + |
| 34 | +// ResourceManagerGroupList defines a list of ResourceManager groups |
| 35 | +type ResourceManagerGroupList struct { |
| 36 | + metav1.TypeMeta `json:",inline"` |
| 37 | + metav1.ListMeta `json:"metadata,omitempty"` |
| 38 | + |
| 39 | + Items []ResourceManagerGroup `json:"items"` |
| 40 | +} |
| 41 | + |
| 42 | +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object |
| 43 | +// +kubebuilder:object:root=true |
| 44 | +// +kubebuilder:subresource:status |
| 45 | +// +kubebuilder:subresource:scale:specpath=.spec.replicas,statuspath=.status.replicas,selectorpath=.status.selector |
| 46 | +// +kubebuilder:resource:categories=group,shortName=rmg |
| 47 | +// +kubebuilder:selectablefield:JSONPath=`.spec.cluster.name` |
| 48 | +// +kubebuilder:printcolumn:name="Cluster",type=string,JSONPath=`.spec.cluster.name` |
| 49 | +// +kubebuilder:printcolumn:name="Desired",type=string,JSONPath=`.spec.replicas` |
| 50 | +// +kubebuilder:printcolumn:name="Ready",type=string,JSONPath=`.status.readyReplicas` |
| 51 | +// +kubebuilder:printcolumn:name="Updated",type=string,JSONPath=`.status.updatedReplicas` |
| 52 | +// +kubebuilder:printcolumn:name="UpdateRevision",type=string,JSONPath=`.status.updateRevision` |
| 53 | +// +kubebuilder:printcolumn:name="CurrentRevision",type=string,JSONPath=`.status.currentRevision` |
| 54 | +// +kubebuilder:printcolumn:name="Synced",type=string,JSONPath=`.status.conditions[?(@.type=="Synced")].status` |
| 55 | +// +kubebuilder:printcolumn:name="Ready",type=string,JSONPath=`.status.conditions[?(@.type=="Ready")].status` |
| 56 | +// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp" |
| 57 | + |
| 58 | +// ResourceManagerGroup defines a group of similar ResourceManager instances |
| 59 | +// +kubebuilder:validation:XValidation:rule="size(self.metadata.name) <= 40",message="name must not exceed 40 characters" |
| 60 | +type ResourceManagerGroup struct { |
| 61 | + metav1.TypeMeta `json:",inline"` |
| 62 | + metav1.ObjectMeta `json:"metadata,omitempty"` |
| 63 | + |
| 64 | + Spec ResourceManagerGroupSpec `json:"spec,omitempty"` |
| 65 | + Status ResourceManagerGroupStatus `json:"status,omitempty"` |
| 66 | +} |
| 67 | + |
| 68 | +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object |
| 69 | +// +kubebuilder:object:root=true |
| 70 | + |
| 71 | +// ResourceManagerList defines a list of ResourceManager instances |
| 72 | +type ResourceManagerList struct { |
| 73 | + metav1.TypeMeta `json:",inline"` |
| 74 | + metav1.ListMeta `json:"metadata,omitempty"` |
| 75 | + |
| 76 | + Items []ResourceManager `json:"items"` |
| 77 | +} |
| 78 | + |
| 79 | +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object |
| 80 | +// +kubebuilder:object:root=true |
| 81 | +// +kubebuilder:subresource:status |
| 82 | +// +kubebuilder:resource:categories=instance |
| 83 | +// +kubebuilder:selectablefield:JSONPath=`.spec.cluster.name` |
| 84 | +// +kubebuilder:printcolumn:name="Cluster",type=string,JSONPath=`.spec.cluster.name` |
| 85 | +// +kubebuilder:printcolumn:name="Synced",type=string,JSONPath=`.status.conditions[?(@.type=="Synced")].status` |
| 86 | +// +kubebuilder:printcolumn:name="Ready",type=string,JSONPath=`.status.conditions[?(@.type=="Ready")].status` |
| 87 | +// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp" |
| 88 | + |
| 89 | +// ResourceManager defines a ResourceManager instance |
| 90 | +// +kubebuilder:validation:XValidation:rule="size(self.metadata.name) <= 47",message="name must not exceed 47 characters" |
| 91 | +type ResourceManager struct { |
| 92 | + metav1.TypeMeta `json:",inline"` |
| 93 | + metav1.ObjectMeta `json:"metadata,omitempty"` |
| 94 | + |
| 95 | + Spec ResourceManagerSpec `json:"spec,omitempty"` |
| 96 | + Status ResourceManagerStatus `json:"status,omitempty"` |
| 97 | +} |
| 98 | + |
| 99 | +// ResourceManagerGroupSpec describes the common attributes of a ResourceManagerGroup |
| 100 | + |
| 101 | +type ResourceManagerGroupSpec struct { |
| 102 | + Cluster ClusterReference `json:"cluster"` |
| 103 | + // Features are enabled feature |
| 104 | + Features []meta.Feature `json:"features,omitempty"` |
| 105 | + |
| 106 | + // +kubebuilder:validation:Minimum=0 |
| 107 | + Replicas *int32 `json:"replicas"` |
| 108 | + |
| 109 | + // +listType=map |
| 110 | + // +listMapKey=type |
| 111 | + SchedulePolicies []SchedulePolicy `json:"schedulePolicies,omitempty"` |
| 112 | + |
| 113 | + // MinReadySeconds specifies the minimum number of seconds for which a newly created pod be ready without any of its containers crashing, for it to be considered available. |
| 114 | + // +kubebuilder:validation:Minimum=0 |
| 115 | + // +optional |
| 116 | + MinReadySeconds *int64 `json:"minReadySeconds,omitempty"` |
| 117 | + |
| 118 | + Template ResourceManagerTemplate `json:"template"` |
| 119 | +} |
| 120 | + |
| 121 | +type ResourceManagerTemplate struct { |
| 122 | + ObjectMeta `json:"metadata,omitempty"` |
| 123 | + Spec ResourceManagerTemplateSpec `json:"spec"` |
| 124 | +} |
| 125 | + |
| 126 | +// ResourceManagerTemplateSpec can only be specified in ResourceManagerGroup |
| 127 | +// TODO: It's name may need to be changed to distinguish from PodTemplateSpec |
| 128 | +// +kubebuilder:validation:XValidation:rule="!has(self.overlay) || !has(self.overlay.volumeClaims) || (has(self.volumes) && self.overlay.volumeClaims.all(vc, vc.name in self.volumes.map(v, v.name)))",message="overlay volumeClaims names must exist in volumes" |
| 129 | + |
| 130 | +type ResourceManagerTemplateSpec struct { |
| 131 | + // Version must be a semantic version. |
| 132 | + // It can has a v prefix or not. |
| 133 | + // +kubebuilder:validation:Pattern=`^(v)?(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$` |
| 134 | + Version string `json:"version"` |
| 135 | + |
| 136 | + // Image is pd's image |
| 137 | + // If tag is omitted, version will be used as the image tag. |
| 138 | + // Default is pingcap/pd |
| 139 | + Image *string `json:"image,omitempty"` |
| 140 | + |
| 141 | + // Server defines server config for ResourceManager |
| 142 | + Server ResourceManagerServer `json:"server,omitempty"` |
| 143 | + |
| 144 | + Resources ResourceRequirements `json:"resources,omitempty"` |
| 145 | + |
| 146 | + UpdateStrategy UpdateStrategy `json:"updateStrategy,omitempty"` |
| 147 | + |
| 148 | + // Config defines config file of ResourceManager |
| 149 | + Config ConfigFile `json:"config,omitempty"` |
| 150 | + |
| 151 | + // Security defines security config |
| 152 | + Security *Security `json:"security,omitempty"` |
| 153 | + |
| 154 | + // Volumes defines persistent volumes of ResourceManager |
| 155 | + // +listType=map |
| 156 | + // +listMapKey=name |
| 157 | + // +kubebuilder:validation:MaxItems=256 |
| 158 | + Volumes []Volume `json:"volumes,omitempty"` |
| 159 | + |
| 160 | + // Overlay defines a k8s native resource template patch |
| 161 | + // All resources(pod, pvcs, ...) managed by ResourceManager can be overlayed by this field |
| 162 | + Overlay *Overlay `json:"overlay,omitempty"` |
| 163 | +} |
| 164 | + |
| 165 | +type ResourceManagerServer struct { |
| 166 | + // Ports defines all ports listened by ResourceManager |
| 167 | + Ports ResourceManagerPorts `json:"ports,omitempty"` |
| 168 | +} |
| 169 | + |
| 170 | +type ResourceManagerPorts struct { |
| 171 | + // Client defines port for ResourceManager's api service |
| 172 | + Client *Port `json:"client,omitempty"` |
| 173 | +} |
| 174 | + |
| 175 | +type ResourceManagerGroupStatus struct { |
| 176 | + CommonStatus `json:",inline"` |
| 177 | + GroupStatus `json:",inline"` |
| 178 | +} |
| 179 | + |
| 180 | +// ResourceManagerSpec describes the common attributes of a ResourceManager instance |
| 181 | +// +kubebuilder:validation:XValidation:rule="(!has(oldSelf.topology) && !has(self.topology)) || (has(oldSelf.topology) && has(self.topology))",fieldPath=".topology",message="topology can only be set when creating" |
| 182 | + |
| 183 | +type ResourceManagerSpec struct { |
| 184 | + // Cluster is a reference of tidb cluster |
| 185 | + Cluster ClusterReference `json:"cluster"` |
| 186 | + // Features are enabled feature |
| 187 | + Features []meta.Feature `json:"features,omitempty"` |
| 188 | + |
| 189 | + // Topology defines the topology domain of this ResourceManager instance |
| 190 | + // It will be translated into a node affinity config |
| 191 | + // Topology cannot be changed |
| 192 | + // +kubebuilder:validation:XValidation:rule="self == oldSelf",message="topology is immutable" |
| 193 | + Topology Topology `json:"topology,omitempty"` |
| 194 | + |
| 195 | + // Subdomain means the subdomain of the exported ResourceManager dns. |
| 196 | + // A same ResourceManager cluster will use a same subdomain |
| 197 | + // +kubebuilder:validation:XValidation:rule="self == oldSelf",message="subdomain is immutable" |
| 198 | + Subdomain string `json:"subdomain"` |
| 199 | + |
| 200 | + // ResourceManagerTemplateSpec embedded some fields managed by ResourceManagerGroup |
| 201 | + ResourceManagerTemplateSpec `json:",inline"` |
| 202 | +} |
| 203 | + |
| 204 | +type ResourceManagerStatus struct { |
| 205 | + CommonStatus `json:",inline"` |
| 206 | +} |
0 commit comments