Skip to content

Commit

Permalink
fix(instances): fix vol name prefix and refactor volume for to mount (p…
Browse files Browse the repository at this point in the history
  • Loading branch information
liubog2008 committed Feb 7, 2025
1 parent 59dcc12 commit f215db0
Show file tree
Hide file tree
Showing 46 changed files with 359 additions and 323 deletions.
25 changes: 13 additions & 12 deletions apis/core/v1alpha1/common_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ const (
// Users may overlay some fields in managed resource such as pods. Names with this
// prefix is preserved to avoid conflicts with fields defined by users.
NamePrefix = "ti-"

// VolNamePrefix is defined for custom persistent volume which may have name conflicts
// with the volumes managed by tidb operator
VolNamePrefix = NamePrefix + "vol-"
)

const (
Expand Down Expand Up @@ -193,12 +197,8 @@ type Volume struct {
// If not specified, the PVC name will be "{component}-{podName}"
Name string `json:"name,omitempty"`

// Path is mount path of this volume
Path string `json:"path"`

// For defines the usage of this volume
// At least one usage is needed for a new volume
For []VolumeUsage `json:"for"`
// Mounts defines mount infos of this volume
Mounts []VolumeMount `json:"mounts"`

// Storage defines the request size of this volume
Storage resource.Quantity `json:"storage"`
Expand All @@ -216,15 +216,16 @@ type Volume struct {
VolumeAttributesClassName *string `json:"volumeAttributesClassName,omitempty"`
}

type VolumeUsage struct {
// Type is a usage type of the volume.
// A volume can be defined for multiple usages.
Type VolumeUsageType `json:"type"`
// SubPath is the relative path of the volume's mount path.
type VolumeMount struct {
// Type is a type of the volume mount.
Type VolumeMountType `json:"type"`
// Mount path of volume, if it's not set, use the default path of this type
MountPath string `json:"mountPath,omitempty"`
// SubPath is the path of the volume's root path.
SubPath string `json:"subPath,omitempty"`
}

type VolumeUsageType string
type VolumeMountType string

// Port defines a listen port
type Port struct {
Expand Down
8 changes: 5 additions & 3 deletions apis/core/v1alpha1/pd_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ var (
)

const (
// VolumeUsageTypePDData means data dir of PD
// The default sub path is "data"
VolumeUsageTypePDData VolumeUsageType = "data"
// VolumeMountTypePDData means data dir of PD
VolumeMountTypePDData VolumeMountType = "data"

VolumeMountPDDataDefaultPath = "/var/lib/pd"
VolumeMountPDDataDefaultSubPath = ""
)

const (
Expand Down
15 changes: 9 additions & 6 deletions apis/core/v1alpha1/tidb_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ var (
_ ComponentAccessor = &TiDB{}
)

const (
// VolumeUsageTypeTiDBSlowLog means the data dir of slowlog
// The default sub path is "slowlog"
// Users can define a persistent volume for slowlog, or an empty dir will be used.
VolumeMountTypeTiDBSlowLog VolumeMountType = "slowlog"

VolumeMountTiDBSlowLogDefaultPath = "/var/log/tidb"
)

const (
TiDBPortNameClient = "mysql-client"
TiDBPortNameStatus = "status"
Expand Down Expand Up @@ -81,7 +90,6 @@ const (
const (
TiDBSlowLogContainerName = NamePrefix + "slowlog"
TiDBDefaultSlowLogVolumeName = NamePrefix + "slowlog"
TiDBDefaultSlowLogDir = "/var/log/tidb"
TiDBSlowLogFileName = "slowlog"
)

Expand Down Expand Up @@ -406,11 +414,6 @@ type TiDBSlowLog struct {
// Default is busybox:1.37.0
Image *string `json:"image,omitempty"`

// VolumeName is the name of the volume used to share the slow log file between the main container and the sidecar.
// If not set, a temparary volume will be used.
// Otherwise, it should be a name of a volume defined in the `volumes` field of the TiDBTemplateSpec.
VolumeName string `json:"volumeName,omitempty"`

// ResourceRequirements defines the resource requirements for the slow log sidecar.
Resources ResourceRequirements `json:"resources,omitempty"`
}
Expand Down
7 changes: 4 additions & 3 deletions apis/core/v1alpha1/tiflash_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ const (
)

const (
// VolumeUsageTypeTiFlashData is the main data dir for the tiflash
// The default sub path of this type is ""
VolumeUsageTypeTiFlashData VolumeUsageType = "data"
// VolumeMountTypeTiFlashData is the main data dir for the tiflash
VolumeMountTypeTiFlashData VolumeMountType = "data"

VolumeMountTiFlashDataDefaultPath = "/var/lib/tiflash"
)

const (
Expand Down
8 changes: 5 additions & 3 deletions apis/core/v1alpha1/tikv_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ var (
)

const (
// VolumeUsageTypeTiKVData is the main data dir for the tikv
// The default sub path of this type is "data"
VolumeUsageTypeTiKVData VolumeUsageType = "data"
// VolumeMountTypeTiKVData is the main data dir for the tikv
// The default sub path of this type is ""
VolumeMountTypeTiKVData VolumeMountType = "data"

VolumeMountTiKVDataDefaultPath = "/var/lib/tikv"
)

const (
Expand Down
14 changes: 7 additions & 7 deletions apis/core/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions examples/basic/01-pd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ spec:
level = "debug"
volumes:
- name: data
path: /var/lib/pd
for:
mounts:
- type: data
storage: 20Gi
3 changes: 1 addition & 2 deletions examples/basic/02-tikv.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ spec:
level = "info"
volumes:
- name: data
path: /var/lib/tikv
for:
mounts:
- type: data
storage: 100Gi
5 changes: 1 addition & 4 deletions examples/basic/04-tiflash.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ spec:
proxyConfig: ""
volumes:
- name: data
# to compatible with the cluster managed by TiDB Operator v1
# this path should often be /data0
path: /data0
for:
mounts:
- type: data
storage: 100Gi
3 changes: 1 addition & 2 deletions examples/bootstrap-sql/01-pd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ spec:
config: ""
volumes:
- name: data
path: /var/lib/pd
for:
mounts:
- type: data
storage: 20Gi
3 changes: 1 addition & 2 deletions examples/bootstrap-sql/02-tikv.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ spec:
config: ""
volumes:
- name: data
path: /var/lib/tikv
for:
mounts:
- type: data
storage: 100Gi
2 changes: 1 addition & 1 deletion examples/overlay/01-pd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ spec:
volumes:
- name: data
path: /var/lib/pd
for:
mounts:
- type: data
storage: 20Gi
overlay:
Expand Down
5 changes: 2 additions & 3 deletions examples/overlay/02-tikv.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ spec:
config: ""
volumes:
- name: data
path: /var/lib/tikv
for:
mounts:
- type: data
storage: 100Gi
storage: 100Gi
5 changes: 2 additions & 3 deletions examples/schedule-policy/01-pd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ spec:
config: ""
volumes:
- name: data
path: /var/lib/pd
for:
mounts:
- type: data
storage: 20Gi
storage: 20Gi
5 changes: 2 additions & 3 deletions examples/schedule-policy/02-tikv.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ spec:
config: ""
volumes:
- name: data
path: /var/lib/tikv
for:
mounts:
- type: data
storage: 100Gi
storage: 100Gi
3 changes: 1 addition & 2 deletions examples/tls/01-pd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ spec:
cert-allowed-cn = ["TiDB"]
volumes:
- name: data
path: /var/lib/pd
for:
mounts:
- type: data
storage: 20Gi
3 changes: 1 addition & 2 deletions examples/tls/02-tikv.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ spec:
cert-allowed-cn = ["TiDB"]
volumes:
- name: data
path: /var/lib/tikv
for:
mounts:
- type: data
storage: 100Gi
3 changes: 1 addition & 2 deletions examples/tls/04-tiflash.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ spec:
cert-allowed-cn = ["TiDB"]
volumes:
- name: data
path: /data0
for:
mounts:
- type: data
storage: 100Gi
24 changes: 10 additions & 14 deletions manifests/crd/core.pingcap.com_pdgroups.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -222,20 +222,20 @@ spec:
A volume can be mounted for multiple different usages.
For example, a volume can be mounted for both data and raft log.
properties:
for:
description: |-
For defines the usage of this volume
At least one usage is needed for a new volume
mounts:
description: Mounts defines mount infos of this volume
items:
properties:
mountPath:
description: Mount path of volume, if it's not
set, use the default path of this type
type: string
subPath:
description: SubPath is the relative path of the
volume's mount path.
description: SubPath is the path of the volume's
root path.
type: string
type:
description: |-
Type is a usage type of the volume.
A volume can be defined for multiple usages.
description: Type is a type of the volume mount.
type: string
required:
- type
Expand All @@ -246,9 +246,6 @@ spec:
Name is volume name.
If not specified, the PVC name will be "{component}-{podName}"
type: string
path:
description: Path is mount path of this volume
type: string
storage:
anyOf:
- type: integer
Expand All @@ -272,8 +269,7 @@ spec:
It's only available when the feature is enabled.
type: string
required:
- for
- path
- mounts
- storage
type: object
type: array
Expand Down
24 changes: 10 additions & 14 deletions manifests/crd/core.pingcap.com_pds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -161,20 +161,20 @@ spec:
A volume can be mounted for multiple different usages.
For example, a volume can be mounted for both data and raft log.
properties:
for:
description: |-
For defines the usage of this volume
At least one usage is needed for a new volume
mounts:
description: Mounts defines mount infos of this volume
items:
properties:
mountPath:
description: Mount path of volume, if it's not set, use
the default path of this type
type: string
subPath:
description: SubPath is the relative path of the volume's
mount path.
description: SubPath is the path of the volume's root
path.
type: string
type:
description: |-
Type is a usage type of the volume.
A volume can be defined for multiple usages.
description: Type is a type of the volume mount.
type: string
required:
- type
Expand All @@ -185,9 +185,6 @@ spec:
Name is volume name.
If not specified, the PVC name will be "{component}-{podName}"
type: string
path:
description: Path is mount path of this volume
type: string
storage:
anyOf:
- type: integer
Expand All @@ -210,8 +207,7 @@ spec:
It's only available when the feature is enabled.
type: string
required:
- for
- path
- mounts
- storage
type: object
type: array
Expand Down
Loading

0 comments on commit f215db0

Please sign in to comment.