Skip to content

Commit fcf5457

Browse files
authored
Feat: define TiBR CRDs (#6217)
1 parent 92d20f3 commit fcf5457

File tree

6 files changed

+17719
-0
lines changed

6 files changed

+17719
-0
lines changed

api/br/v1alpha1/tibr_types.go

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
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="tibr"
30+
// +kubebuilder:selectablefield:JSONPath=`.spec.cluster.name`
31+
// +kubebuilder:printcolumn:name="Cluster",type=string,JSONPath=`.spec.cluster.name`
32+
// +kubebuilder:printcolumn:name="ScheduleType",type=string,JSONPath=`.spec.autoSchedule.type`
33+
// +kubebuilder:printcolumn:name="ScheduleAt",type=string,JSONPath=`.spec.autoSchedule.at`
34+
// +kubebuilder:printcolumn:name="Synced",type=string,JSONPath=`.status.conditions[?(@.type=="Synced")].status`
35+
// +kubebuilder:printcolumn:name="Ready",type=string,JSONPath=`.status.conditions[?(@.type=="Ready")].status`
36+
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"
37+
38+
// TiBR is the Schema for the tibr API.
39+
// 1. Allows user to define auto backup schedule.
40+
// 2. Provides http server for user to query backup records, execute restore and query restore progress.
41+
type TiBR struct {
42+
metav1.TypeMeta `json:",inline"`
43+
metav1.ObjectMeta `json:"metadata,omitempty"`
44+
45+
Spec TiBRSpec `json:"spec,omitempty"`
46+
Status TiBRStatus `json:"status,omitempty"`
47+
}
48+
49+
// TiBRSpec defines the desired state of TiBR.
50+
type TiBRSpec struct {
51+
// Cluster is a reference of tidb cluster
52+
Cluster v1alpha1.ClusterReference `json:"cluster"`
53+
// AutoSchedule define auto backup strategy for TiBR, it's optional
54+
AutoSchedule *TiBRAutoSchedule `json:"autoSchedule,omitempty"`
55+
// Image is image of br service, default is pingcap/tikv
56+
Image *string `json:"image,omitempty"`
57+
Config v1alpha1.ConfigFile `json:"config,omitempty"`
58+
// Overlay defines a k8s native resource template patch
59+
Overlay *v1alpha1.Overlay `json:"overlay,omitempty"`
60+
}
61+
62+
// TiBRStatus defines the observed state of TiBR.
63+
type TiBRStatus struct {
64+
v1alpha1.CommonStatus `json:",inline"`
65+
}
66+
67+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
68+
// +kubebuilder:object:root=true
69+
70+
// TiBRList contains a list of TiBR.
71+
type TiBRList struct {
72+
metav1.TypeMeta `json:",inline"`
73+
metav1.ListMeta `json:"metadata,omitempty"`
74+
Items []TiBR `json:"items"`
75+
}
76+
77+
type TiBRAutoScheduleType string
78+
79+
const (
80+
TiBRAutoScheduleTypePerDay TiBRAutoScheduleType = "per-day"
81+
TiBRAutoScheduleTypePerHour TiBRAutoScheduleType = "per-hour"
82+
TiBRAutoScheduleTypePerMinute TiBRAutoScheduleType = "per-minute"
83+
)
84+
85+
// +kubebuilder:validation:XValidation:rule="(self.type== 'per-day' && self.at >= 0 && self.at <= 23)|| (self.type == 'per-hour' && self.at >= 0 && self.at <= 59) || (self.type == 'per-minute' && self.at == 0)"
86+
// +kubebuilder:validation:Message="if type is per-day, at is the hour of day; if type is per-hour, at is the minute of hour; if type is per-minute, it should be 0"
87+
type TiBRAutoSchedule struct {
88+
// Type defines the schedule type, such as per-day, per-hour, per-minute
89+
// +kubebuilder:validation:Enum=per-day;per-hour;per-minute
90+
Type TiBRAutoScheduleType `json:"type"`
91+
// At defines the schedule time of backup
92+
At uint32 `json:"at"`
93+
}

api/br/v1alpha1/tibrgc_types.go

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
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

Comments
 (0)