Skip to content

Commit 0d56dd4

Browse files
unify PVC data and additional PVC reconciliation loop
1 parent 108048f commit 0d56dd4

26 files changed

Lines changed: 688 additions & 871 deletions

api/v1alpha1/clickhousecluster_types.go

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,12 @@ type ClickHouseClusterSpec struct {
4949
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Data Volume Claim Spec"
5050
DataVolumeClaimSpec *corev1.PersistentVolumeClaimSpec `json:"dataVolumeClaimSpec,omitempty"`
5151

52-
// Additional persistent volume claims attached to each ClickHouse pod.
53-
// Each entry creates a volumeClaimTemplate on the StatefulSet, producing
54-
// per-pod PVCs named <name>-<statefulset>-<ordinal>.
55-
// Use for JBOD / multi-disk storage layouts.
52+
// Additional per-pod PVC templates for JBOD / multi-disk storage.
53+
// Each entry is propagated in StatefulSet volumeClaimTemplate, mounted at /var/lib/clickhouse/disks/<name> and
54+
// added to the generated JBOD storage policy.
55+
// The set of disks is fixed at creation.
5656
// +optional
57-
AdditionalDataVolumeClaimSpecs []AdditionalVolumeClaimSpec `json:"additionalDataVolumeClaimSpecs,omitempty"`
57+
AdditionalVolumeClaimTemplates []PersistentVolumeClaimTemplate `json:"additionalVolumeClaimTemplates,omitempty"`
5858

5959
// Additional labels that are added to resources.
6060
// +optional
@@ -116,22 +116,6 @@ type AdditionalPort struct {
116116
Port int32 `json:"port"`
117117
}
118118

119-
// AdditionalVolumeClaimSpec defines an additional persistent volume claim for a ClickHouse pod.
120-
type AdditionalVolumeClaimSpec struct {
121-
// Name used as the volumeClaimTemplate name and the volume/volumeMount name.
122-
// Must be unique and not collide with the primary data volume name.
123-
// Must consist of lowercase alphanumeric characters or hyphens, and start and end with an alphanumeric character.
124-
// Hyphens are automatically converted to underscores in the ClickHouse disk configuration.
125-
// +kubebuilder:validation:Pattern=`^[a-z0-9]([a-z0-9-]*[a-z0-9])?$`
126-
Name string `json:"name"`
127-
// PVC spec for this additional volume.
128-
Spec corev1.PersistentVolumeClaimSpec `json:"spec"`
129-
// MountPath inside the ClickHouse container.
130-
// If empty, defaults to /var/lib/clickhouse/disks/<name>.
131-
// +optional
132-
MountPath string `json:"mountPath,omitempty"`
133-
}
134-
135119
// WithDefaults sets default values for ClickHouseClusterSpec fields.
136120
func (s *ClickHouseClusterSpec) WithDefaults() {
137121
defaultSpec := ClickHouseClusterSpec{
@@ -181,14 +165,9 @@ func (s *ClickHouseClusterSpec) WithDefaults() {
181165
s.DataVolumeClaimSpec.AccessModes = []corev1.PersistentVolumeAccessMode{DefaultAccessMode}
182166
}
183167

184-
for i := range s.AdditionalDataVolumeClaimSpecs {
185-
if len(s.AdditionalDataVolumeClaimSpecs[i].Spec.AccessModes) == 0 {
186-
s.AdditionalDataVolumeClaimSpecs[i].Spec.AccessModes = []corev1.PersistentVolumeAccessMode{DefaultAccessMode}
187-
}
188-
189-
if s.AdditionalDataVolumeClaimSpecs[i].MountPath == "" {
190-
// Keep in sync with internal.AdditionalDiskBasePath.
191-
s.AdditionalDataVolumeClaimSpecs[i].MountPath = "/var/lib/clickhouse/disks/" + s.AdditionalDataVolumeClaimSpecs[i].Name
168+
for i, t := range s.AdditionalVolumeClaimTemplates {
169+
if len(t.Spec.AccessModes) == 0 {
170+
s.AdditionalVolumeClaimTemplates[i].Spec.AccessModes = []corev1.PersistentVolumeAccessMode{DefaultAccessMode}
192171
}
193172
}
194173
}

api/v1alpha1/common.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,3 +562,26 @@ type VersionProbeContainer struct {
562562
// +optional
563563
SecurityContext *corev1.SecurityContext `json:"securityContext,omitempty"`
564564
}
565+
566+
// NamedTemplateMeta defines supported metadata settings for template objects that require a name.
567+
type NamedTemplateMeta struct {
568+
// Name is the resource identifier.
569+
// +kubebuilder:validation:Pattern=`^[a-z]([-a-z0-9]*[a-z0-9])?$`
570+
Name string `json:"name"`
571+
// Labels are labels applied to the template objects.
572+
// +optional
573+
Labels map[string]string `json:"labels,omitempty"`
574+
// Annotations are annotations applied to the template objects.
575+
// +optional
576+
Annotations map[string]string `json:"annotations,omitempty"`
577+
}
578+
579+
// PersistentVolumeClaimTemplate is a named template for a per-replica PersistentVolumeClaim.
580+
type PersistentVolumeClaimTemplate struct {
581+
// Metadata template of the volume claim.
582+
NamedTemplateMeta `json:"metadata,omitempty"`
583+
584+
// Spec defines the desired characteristics of a volume requested by a pod author.
585+
// More info: https://kubernetes.io/docs/concepts/storage/persistent-volumes#persistentvolumeclaims
586+
Spec corev1.PersistentVolumeClaimSpec `json:"spec,omitempty" protobuf:"bytes,2,opt,name=spec"`
587+
}

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 49 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/clickhouse.com_clickhouseclusters.yaml

Lines changed: 57 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -66,31 +66,70 @@ spec:
6666
spec:
6767
description: ClickHouseClusterSpec defines the desired state of ClickHouseCluster.
6868
properties:
69-
additionalDataVolumeClaimSpecs:
69+
additionalPorts:
7070
description: |-
71-
Additional persistent volume claims attached to each ClickHouse pod.
72-
Each entry creates a volumeClaimTemplate on the StatefulSet, producing
73-
per-pod PVCs named <name>-<statefulset>-<ordinal>.
74-
Use for JBOD / multi-disk storage layouts.
71+
AdditionalPorts declares extra TCP ports to expose on the ClickHouse Pod and the operator-managed headless Service.
72+
The operator only adds the ports to the Kubernetes resources, it does not configure the ClickHouse server to listen on them.
7573
items:
76-
description: AdditionalVolumeClaimSpec defines an additional persistent
77-
volume claim for a ClickHouse pod.
74+
description: AdditionalPort declares one extra TCP port to expose
75+
on the ClickHouse Pod and the operator-managed headless Service.
7876
properties:
79-
mountPath:
80-
description: |-
81-
MountPath inside the ClickHouse container.
82-
If empty, defaults to /var/lib/clickhouse/disks/<name>.
83-
type: string
8477
name:
8578
description: |-
86-
Name used as the volumeClaimTemplate name and the volume/volumeMount name.
87-
Must be unique and not collide with the primary data volume name.
88-
Must consist of lowercase alphanumeric characters or hyphens, and start and end with an alphanumeric character.
89-
Hyphens are automatically converted to underscores in the ClickHouse disk configuration.
90-
pattern: ^[a-z0-9]([a-z0-9-]*[a-z0-9])?$
79+
Name uniquely identifies the port within the list. Used as both the container port name and the Service port name.
80+
This must be a DNS_LABEL.
81+
maxLength: 63
82+
pattern: ^[a-z]([-a-z0-9]*[a-z0-9])?$
9183
type: string
84+
port:
85+
description: Port is the TCP port number to expose.
86+
format: int32
87+
maximum: 65535
88+
minimum: 1
89+
type: integer
90+
required:
91+
- name
92+
- port
93+
type: object
94+
type: array
95+
x-kubernetes-list-map-keys:
96+
- name
97+
x-kubernetes-list-type: map
98+
additionalVolumeClaimTemplates:
99+
description: |-
100+
Additional per-pod PVC templates for JBOD / multi-disk storage.
101+
Each entry is propagated in StatefulSet volumeClaimTemplate, mounted at /var/lib/clickhouse/disks/<name> and
102+
added to the generated JBOD storage policy.
103+
The set of disks is fixed at creation.
104+
items:
105+
description: PersistentVolumeClaimTemplate is a named template for
106+
a per-replica PersistentVolumeClaim.
107+
properties:
108+
metadata:
109+
description: Metadata template of the volume claim.
110+
properties:
111+
annotations:
112+
additionalProperties:
113+
type: string
114+
description: Annotations are annotations applied to the
115+
template objects.
116+
type: object
117+
labels:
118+
additionalProperties:
119+
type: string
120+
description: Labels are labels applied to the template objects.
121+
type: object
122+
name:
123+
description: Name is the resource identifier.
124+
pattern: ^[a-z]([-a-z0-9]*[a-z0-9])?$
125+
type: string
126+
required:
127+
- name
128+
type: object
92129
spec:
93-
description: PVC spec for this additional volume.
130+
description: |-
131+
Spec defines the desired characteristics of a volume requested by a pod author.
132+
More info: https://kubernetes.io/docs/concepts/storage/persistent-volumes#persistentvolumeclaims
94133
properties:
95134
accessModes:
96135
description: |-
@@ -284,40 +323,8 @@ spec:
284323
PersistentVolume backing this claim.
285324
type: string
286325
type: object
287-
required:
288-
- name
289-
- spec
290326
type: object
291327
type: array
292-
additionalPorts:
293-
description: |-
294-
AdditionalPorts declares extra TCP ports to expose on the ClickHouse Pod and the operator-managed headless Service.
295-
The operator only adds the ports to the Kubernetes resources, it does not configure the ClickHouse server to listen on them.
296-
items:
297-
description: AdditionalPort declares one extra TCP port to expose
298-
on the ClickHouse Pod and the operator-managed headless Service.
299-
properties:
300-
name:
301-
description: |-
302-
Name uniquely identifies the port within the list. Used as both the container port name and the Service port name.
303-
This must be a DNS_LABEL.
304-
maxLength: 63
305-
pattern: ^[a-z]([-a-z0-9]*[a-z0-9])?$
306-
type: string
307-
port:
308-
description: Port is the TCP port number to expose.
309-
format: int32
310-
maximum: 65535
311-
minimum: 1
312-
type: integer
313-
required:
314-
- name
315-
- port
316-
type: object
317-
type: array
318-
x-kubernetes-list-map-keys:
319-
- name
320-
x-kubernetes-list-type: map
321328
annotations:
322329
additionalProperties:
323330
type: string

dist/chart-cluster/values.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,16 @@ clickhouse:
4949
# ClickHouseCluster.spec — passed verbatim into the CR.
5050
spec:
5151

52-
# Additional persistent volume claims attached to each ClickHouse pod.
53-
# Each entry creates a volumeClaimTemplate on the StatefulSet, producing
54-
# per-pod PVCs named <name>-<statefulset>-<ordinal>.
55-
# Use for JBOD / multi-disk storage layouts.
56-
# additionalDataVolumeClaimSpecs: []
57-
5852
# AdditionalPorts declares extra TCP ports to expose on the ClickHouse Pod and the operator-managed headless Service.
5953
# The operator only adds the ports to the Kubernetes resources, it does not configure the ClickHouse server to listen on them.
6054
# additionalPorts: []
6155

56+
# Additional per-pod PVC templates for JBOD / multi-disk storage.
57+
# Each entry is propagated in StatefulSet volumeClaimTemplate, mounted at /var/lib/clickhouse/disks/<name> and
58+
# added to the generated JBOD storage policy.
59+
# The set of disks is fixed at creation.
60+
# additionalVolumeClaimTemplates: []
61+
6262
# Additional annotations that are added to resources.
6363
# annotations: {}
6464

0 commit comments

Comments
 (0)