|
| 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 | + "github.com/pingcap/tidb-operator/api/v2/core/v1alpha1" |
| 21 | +) |
| 22 | + |
| 23 | +// +genclient |
| 24 | +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object |
| 25 | +// +k8s:openapi-gen=true |
| 26 | +// +kubebuilder:object:root=true |
| 27 | +// +kubebuilder:subresource:status |
| 28 | +// +kubebuilder:resource:categories=br |
| 29 | +// +kubebuilder:resource:shortName="tibrgc" |
| 30 | +// +kubebuilder:selectablefield:JSONPath=`.spec.cluster.name` |
| 31 | +// +kubebuilder:printcolumn:name="Cluster",type=string,JSONPath=`.spec.cluster.name` |
| 32 | +// +kubebuilder:printcolumn:name="Strategy",type=string,JSONPath=`.spec.gcStrategy.type` |
| 33 | +// +kubebuilder:printcolumn:name="Synced",type=string,JSONPath=`.status.conditions[?(@.type=="Synced")].status` |
| 34 | +// +kubebuilder:printcolumn:name="Ready",type=string,JSONPath=`.status.conditions[?(@.type=="Ready")].status` |
| 35 | +// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp" |
| 36 | + |
| 37 | +// TiBRGC is the Schema for the tibrgc API. It allows users to set backup gc strategy and configure resources fo gc workloads. |
| 38 | +type TiBRGC struct { |
| 39 | + metav1.TypeMeta `json:",inline"` |
| 40 | + metav1.ObjectMeta `json:"metadata,omitempty"` |
| 41 | + |
| 42 | + Spec TiBRGCSpec `json:"spec,omitempty"` |
| 43 | + Status TiBRGCStatus `json:"status,omitempty"` |
| 44 | +} |
| 45 | + |
| 46 | +// TiBRGCSpec defines the desired state of TiBRGC. |
| 47 | +type TiBRGCSpec struct { |
| 48 | + // Cluster is a reference of tidb cluster |
| 49 | + Cluster v1alpha1.ClusterReference `json:"cluster"` |
| 50 | + GCStrategy TiBRGCStrategy `json:"gcStrategy,omitempty"` |
| 51 | + // Image is image of br gc, default is pingcap/tikv |
| 52 | + Image *string `json:"image,omitempty"` |
| 53 | + Overlay TiBRGCOverlay `json:"overlay,omitempty"` |
| 54 | +} |
| 55 | + |
| 56 | +// TiBRGCStatus defines the observed state of TiBRGC. |
| 57 | +type TiBRGCStatus struct { |
| 58 | + v1alpha1.CommonStatus `json:",inline"` |
| 59 | +} |
| 60 | + |
| 61 | +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object |
| 62 | +// +kubebuilder:object:root=true |
| 63 | + |
| 64 | +// TiBRGCList contains a list of TiBRGC. |
| 65 | +type TiBRGCList struct { |
| 66 | + metav1.TypeMeta `json:",inline"` |
| 67 | + metav1.ListMeta `json:"metadata,omitempty"` |
| 68 | + Items []TiBRGC `json:"items"` |
| 69 | +} |
| 70 | + |
| 71 | +type TiBRGCStrategyType string |
| 72 | + |
| 73 | +const ( |
| 74 | + TiBRGCStrategyTypeTieredStorage TiBRGCStrategyType = "tiered-storage" |
| 75 | +) |
| 76 | + |
| 77 | +type TiBRGCStrategy struct { |
| 78 | + // +kubebuilder:validation:Enum=tiered-storage |
| 79 | + Type TiBRGCStrategyType `json:"type"` |
| 80 | + // +listType=map |
| 81 | + // +listMapKey=name |
| 82 | + // +kubebuilder:validation:MaxItems=2 |
| 83 | + TieredStrategies []TieredStorageStrategy `json:"tieredStrategies,omitempty"` |
| 84 | +} |
| 85 | +type TieredStorageStrategyName string |
| 86 | + |
| 87 | +const ( |
| 88 | + TieredStorageStrategyNameToT2Storage TieredStorageStrategyName = "to-t2-storage" |
| 89 | + TieredStorageStrategyNameToT3Storage TieredStorageStrategyName = "to-t3-storage" |
| 90 | +) |
| 91 | + |
| 92 | +type TieredStorageStrategy struct { |
| 93 | + // +kubebuilder:validation:Enum=to-t2-storage;to-t3-storage |
| 94 | + Name TieredStorageStrategyName `json:"name"` |
| 95 | + // +kubebuilder:validation:Minimum=1 |
| 96 | + TimeThresholdDays uint32 `json:"timeThresholdDays"` |
| 97 | +} |
| 98 | + |
| 99 | +type TiBRGCOverlay struct { |
| 100 | + // +listType=map |
| 101 | + // +listMapKey=name |
| 102 | + // +kubebuilder:validation:MaxItems=2 |
| 103 | + Pods []TiBRGCPodOverlay `json:"pods,omitempty"` |
| 104 | +} |
| 105 | + |
| 106 | +type TiBRGCPodOverlay struct { |
| 107 | + // +kubebuilder:validation:Enum=to-t2-storage;to-t3-storage |
| 108 | + Name TieredStorageStrategyName `json:"name"` |
| 109 | + Overlay *v1alpha1.Overlay `json:"overlay,omitempty"` |
| 110 | +} |
0 commit comments