Skip to content

Commit 4d59921

Browse files
feat: apply pod/container overrides via strategic merge patch (#150)
1 parent 34efe55 commit 4d59921

12 files changed

Lines changed: 766 additions & 317 deletions

File tree

api/v1alpha1/common.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ type PodTemplateSpec struct {
166166
// TopologySpreadConstraints describes how a group of pods ought to spread across topology
167167
// domains. Scheduler will schedule pods in a way which abides by the constraints.
168168
// All topologySpreadConstraints are ANDed.
169+
// Merged with operator defaults by `topologyKey`.
169170
// +optional
170171
// +patchMergeKey=topologyKey
171172
// +patchStrategy=merge
@@ -177,6 +178,7 @@ type PodTemplateSpec struct {
177178
// ImagePullSecrets is an optional list of references to secrets in the same namespace to use for pulling any of the images used by this PodSpec.
178179
// If specified, these secrets will be passed to individual puller implementations for them to use.
179180
// More info: https://kubernetes.io/docs/concepts/containers/images#specifying-imagepullsecrets-on-a-pod
181+
// Merged with operator defaults by name.
180182
// +optional
181183
// +patchMergeKey=name
182184
// +patchStrategy=merge
@@ -191,7 +193,8 @@ type PodTemplateSpec struct {
191193
// +mapType=atomic
192194
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
193195

194-
// If specified, the pod's scheduling constraints
196+
// If specified, the pod's scheduling constraints.
197+
// Appended to operator defaults: scheduling term lists are concatenated.
195198
// +optional
196199
Affinity *corev1.Affinity `json:"affinity,omitempty"`
197200

@@ -212,6 +215,7 @@ type PodTemplateSpec struct {
212215

213216
// Volumes defines the list of volumes that can be mounted by containers belonging to the pod.
214217
// More info: https://kubernetes.io/docs/concepts/storage/volumes
218+
// Merged with operator defaults by name; a user volume replaces any operator volume with the same name.
215219
// +optional
216220
// +patchMergeKey=name
217221
// +patchStrategy=merge
@@ -220,6 +224,7 @@ type PodTemplateSpec struct {
220224
Volumes []corev1.Volume `json:"volumes,omitempty" patchMergeKey:"name" patchStrategy:"merge"`
221225

222226
// SecurityContext holds pod-level security attributes and common container settings.
227+
// Deep-merged with operator defaults via SMP. When nil, operator defaults are preserved.
223228
// +optional
224229
SecurityContext *corev1.PodSecurityContext `json:"securityContext,omitempty"`
225230

@@ -249,10 +254,14 @@ type ContainerTemplateSpec struct {
249254
ImagePullPolicy corev1.PullPolicy `json:"imagePullPolicy,omitempty"`
250255

251256
// Resources is the resource requirements for the server container.
257+
// Deep-merged with operator defaults via SMP. Individual limits and requests override only matching
258+
// keys; unset fields preserve operator defaults.
252259
// +optional
253260
Resources corev1.ResourceRequirements `json:"resources,omitempty"`
254261

255262
// VolumeMounts is the list of volume mounts for the container.
263+
// Concatenated with operator-generated mounts. Entries sharing a `mountPath` with an operator
264+
// mount are merged into a projected volume.
256265
// +optional
257266
// +patchMergeKey=mountPath
258267
// +patchStrategy=merge
@@ -261,6 +270,7 @@ type ContainerTemplateSpec struct {
261270
VolumeMounts []corev1.VolumeMount `json:"volumeMounts,omitempty" patchMergeKey:"mountPath" patchStrategy:"merge"`
262271

263272
// Env is the list of environment variables to set in the container.
273+
// Merged with operator defaults by name.
264274
// +optional
265275
// +patchMergeKey=name
266276
// +patchStrategy=merge
@@ -269,7 +279,7 @@ type ContainerTemplateSpec struct {
269279
Env []corev1.EnvVar `json:"env,omitempty" patchMergeKey:"name" patchStrategy:"merge"`
270280

271281
// SecurityContext defines the security options the container should be run with.
272-
// If set, the fields of SecurityContext override the equivalent fields of PodSecurityContext.
282+
// Deep-merged with operator defaults via SMP. When nil, operator defaults are preserved.
273283
// More info: https://kubernetes.io/docs/tasks/configure-pod-container/security-context/
274284
// +optional
275285
SecurityContext *corev1.SecurityContext `json:"securityContext,omitempty"`

config/crd/bases/clickhouse.com_clickhouseclusters.yaml

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,9 @@ spec:
7676
description: Parameters passed to the ClickHouse container spec.
7777
properties:
7878
env:
79-
description: Env is the list of environment variables to set in
80-
the container.
79+
description: |-
80+
Env is the list of environment variables to set in the container.
81+
Merged with operator defaults by name.
8182
items:
8283
description: EnvVar represents an environment variable present
8384
in a Container.
@@ -264,8 +265,10 @@ spec:
264265
- IfNotPresent
265266
type: string
266267
resources:
267-
description: Resources is the resource requirements for the server
268-
container.
268+
description: |-
269+
Resources is the resource requirements for the server container.
270+
Deep-merged with operator defaults via SMP. Individual limits and requests override only matching
271+
keys; unset fields preserve operator defaults.
269272
properties:
270273
claims:
271274
description: |-
@@ -326,7 +329,7 @@ spec:
326329
securityContext:
327330
description: |-
328331
SecurityContext defines the security options the container should be run with.
329-
If set, the fields of SecurityContext override the equivalent fields of PodSecurityContext.
332+
Deep-merged with operator defaults via SMP. When nil, operator defaults are preserved.
330333
More info: https://kubernetes.io/docs/tasks/configure-pod-container/security-context/
331334
properties:
332335
allowPrivilegeEscalation:
@@ -519,8 +522,10 @@ spec:
519522
type: object
520523
type: object
521524
volumeMounts:
522-
description: VolumeMounts is the list of volume mounts for the
523-
container.
525+
description: |-
526+
VolumeMounts is the list of volume mounts for the container.
527+
Concatenated with operator-generated mounts. Entries sharing a `mountPath` with an operator
528+
mount are merged into a projected volume.
524529
items:
525530
description: VolumeMount describes a mounting of a Volume within
526531
a container.
@@ -843,7 +848,9 @@ spec:
843848
description: Parameters passed to the ClickHouse pod spec.
844849
properties:
845850
affinity:
846-
description: If specified, the pod's scheduling constraints
851+
description: |-
852+
If specified, the pod's scheduling constraints.
853+
Appended to operator defaults: scheduling term lists are concatenated.
847854
properties:
848855
nodeAffinity:
849856
description: Describes node affinity scheduling rules for
@@ -1766,6 +1773,7 @@ spec:
17661773
ImagePullSecrets is an optional list of references to secrets in the same namespace to use for pulling any of the images used by this PodSpec.
17671774
If specified, these secrets will be passed to individual puller implementations for them to use.
17681775
More info: https://kubernetes.io/docs/concepts/containers/images#specifying-imagepullsecrets-on-a-pod
1776+
Merged with operator defaults by name.
17691777
items:
17701778
description: |-
17711779
LocalObjectReference contains enough information to let you locate the
@@ -1808,8 +1816,9 @@ spec:
18081816
If not specified, the pod will be dispatched by default scheduler.
18091817
type: string
18101818
securityContext:
1811-
description: SecurityContext holds pod-level security attributes
1812-
and common container settings.
1819+
description: |-
1820+
SecurityContext holds pod-level security attributes and common container settings.
1821+
Deep-merged with operator defaults via SMP. When nil, operator defaults are preserved.
18131822
properties:
18141823
appArmorProfile:
18151824
description: |-
@@ -2103,6 +2112,7 @@ spec:
21032112
TopologySpreadConstraints describes how a group of pods ought to spread across topology
21042113
domains. Scheduler will schedule pods in a way which abides by the constraints.
21052114
All topologySpreadConstraints are ANDed.
2115+
Merged with operator defaults by `topologyKey`.
21062116
items:
21072117
description: TopologySpreadConstraint specifies how to spread
21082118
matching pods among the given topology.
@@ -2290,6 +2300,7 @@ spec:
22902300
description: |-
22912301
Volumes defines the list of volumes that can be mounted by containers belonging to the pod.
22922302
More info: https://kubernetes.io/docs/concepts/storage/volumes
2303+
Merged with operator defaults by name; a user volume replaces any operator volume with the same name.
22932304
items:
22942305
description: Volume represents a named volume in a pod that
22952306
may be accessed by any container in the pod.

config/crd/bases/clickhouse.com_keeperclusters.yaml

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,9 @@ spec:
7575
description: Parameters passed to the Keeper container spec.
7676
properties:
7777
env:
78-
description: Env is the list of environment variables to set in
79-
the container.
78+
description: |-
79+
Env is the list of environment variables to set in the container.
80+
Merged with operator defaults by name.
8081
items:
8182
description: EnvVar represents an environment variable present
8283
in a Container.
@@ -263,8 +264,10 @@ spec:
263264
- IfNotPresent
264265
type: string
265266
resources:
266-
description: Resources is the resource requirements for the server
267-
container.
267+
description: |-
268+
Resources is the resource requirements for the server container.
269+
Deep-merged with operator defaults via SMP. Individual limits and requests override only matching
270+
keys; unset fields preserve operator defaults.
268271
properties:
269272
claims:
270273
description: |-
@@ -325,7 +328,7 @@ spec:
325328
securityContext:
326329
description: |-
327330
SecurityContext defines the security options the container should be run with.
328-
If set, the fields of SecurityContext override the equivalent fields of PodSecurityContext.
331+
Deep-merged with operator defaults via SMP. When nil, operator defaults are preserved.
329332
More info: https://kubernetes.io/docs/tasks/configure-pod-container/security-context/
330333
properties:
331334
allowPrivilegeEscalation:
@@ -518,8 +521,10 @@ spec:
518521
type: object
519522
type: object
520523
volumeMounts:
521-
description: VolumeMounts is the list of volume mounts for the
522-
container.
524+
description: |-
525+
VolumeMounts is the list of volume mounts for the container.
526+
Concatenated with operator-generated mounts. Entries sharing a `mountPath` with an operator
527+
mount are merged into a projected volume.
523528
items:
524529
description: VolumeMount describes a mounting of a Volume within
525530
a container.
@@ -828,7 +833,9 @@ spec:
828833
description: Parameters passed to the Keeper pod spec.
829834
properties:
830835
affinity:
831-
description: If specified, the pod's scheduling constraints
836+
description: |-
837+
If specified, the pod's scheduling constraints.
838+
Appended to operator defaults: scheduling term lists are concatenated.
832839
properties:
833840
nodeAffinity:
834841
description: Describes node affinity scheduling rules for
@@ -1751,6 +1758,7 @@ spec:
17511758
ImagePullSecrets is an optional list of references to secrets in the same namespace to use for pulling any of the images used by this PodSpec.
17521759
If specified, these secrets will be passed to individual puller implementations for them to use.
17531760
More info: https://kubernetes.io/docs/concepts/containers/images#specifying-imagepullsecrets-on-a-pod
1761+
Merged with operator defaults by name.
17541762
items:
17551763
description: |-
17561764
LocalObjectReference contains enough information to let you locate the
@@ -1793,8 +1801,9 @@ spec:
17931801
If not specified, the pod will be dispatched by default scheduler.
17941802
type: string
17951803
securityContext:
1796-
description: SecurityContext holds pod-level security attributes
1797-
and common container settings.
1804+
description: |-
1805+
SecurityContext holds pod-level security attributes and common container settings.
1806+
Deep-merged with operator defaults via SMP. When nil, operator defaults are preserved.
17981807
properties:
17991808
appArmorProfile:
18001809
description: |-
@@ -2088,6 +2097,7 @@ spec:
20882097
TopologySpreadConstraints describes how a group of pods ought to spread across topology
20892098
domains. Scheduler will schedule pods in a way which abides by the constraints.
20902099
All topologySpreadConstraints are ANDed.
2100+
Merged with operator defaults by `topologyKey`.
20912101
items:
20922102
description: TopologySpreadConstraint specifies how to spread
20932103
matching pods among the given topology.
@@ -2275,6 +2285,7 @@ spec:
22752285
description: |-
22762286
Volumes defines the list of volumes that can be mounted by containers belonging to the pod.
22772287
More info: https://kubernetes.io/docs/concepts/storage/volumes
2288+
Merged with operator defaults by name; a user volume replaces any operator volume with the same name.
22782289
items:
22792290
description: Volume represents a named volume in a pod that
22802291
may be accessed by any container in the pod.

0 commit comments

Comments
 (0)