Skip to content

Commit 4b200ca

Browse files
committed
feat: add support for extraPVCs
This commit introduces the `extraPVCs` field in CRD, allowing users to attach additional PVC to main container. #2126 Signed-off-by: Emin Aktas <[email protected]>
1 parent 37c06c5 commit 4b200ca

File tree

7 files changed

+2749
-0
lines changed

7 files changed

+2749
-0
lines changed

config/crd/bases/pxc.percona.com_perconaxtradbclusters.yaml

Lines changed: 672 additions & 0 deletions
Large diffs are not rendered by default.

deploy/bundle.yaml

Lines changed: 672 additions & 0 deletions
Large diffs are not rendered by default.

deploy/crd.yaml

Lines changed: 672 additions & 0 deletions
Large diffs are not rendered by default.

deploy/cw-bundle.yaml

Lines changed: 672 additions & 0 deletions
Large diffs are not rendered by default.

pkg/apis/pxc/v1/pxc_types.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,13 @@ type PodSpec struct {
563563
HookScript string `json:"hookScript,omitempty"`
564564
Lifecycle corev1.Lifecycle `json:"lifecycle,omitempty"`
565565
TopologySpreadConstraints []corev1.TopologySpreadConstraint `json:"topologySpreadConstraints,omitempty"`
566+
ExtraPVCs []ExtraPVC `json:"extraPVCs,omitempty"`
567+
}
568+
569+
type ExtraPVC struct {
570+
VolumeClaimTemplate corev1.PersistentVolumeClaim `json:"volumeClaimTemplate,omitempty"`
571+
MountPath string `json:"mountPath,omitempty"`
572+
ReadOnly *bool `json:"readOnly,omitempty"`
566573
}
567574

568575
func (spec *PodSpec) HasSidecarInternalSecret(secret *corev1.Secret) bool {
@@ -1522,6 +1529,14 @@ func AddSidecarContainers(log logr.Logger, existing, sidecars []corev1.Container
15221529
return existing
15231530
}
15241531

1532+
func AddExtraVolumes(log logr.Logger, existing []corev1.Volume, extraVolumes []ExtraPVC) []corev1.Volume {
1533+
if len(extraVolumes) == 0 {
1534+
return existing
1535+
}
1536+
1537+
return existing
1538+
}
1539+
15251540
func AddSidecarVolumes(log logr.Logger, existing, sidecarVolumes []corev1.Volume) []corev1.Volume {
15261541
if len(sidecarVolumes) == 0 {
15271542
return existing

pkg/apis/pxc/v1/zz_generated.deepcopy.go

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

pkg/pxc/statefulset.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,19 @@ func StatefulSet(ctx context.Context, cl client.Client, sfs api.StatefulApp, pod
4848
return nil, fmt.Errorf("failed to get volumes %v", err)
4949
}
5050

51+
var extraPVCMounts []corev1.VolumeMount
52+
if cr.Spec.PXC.ExtraPVCs != nil {
53+
for _, extraPVC := range cr.Spec.PXC.ExtraPVCs {
54+
sfsVolume.PVCs = append(sfsVolume.PVCs, extraPVC.VolumeClaimTemplate)
55+
pvcMount := corev1.VolumeMount{
56+
Name: extraPVC.VolumeClaimTemplate.GetName(),
57+
MountPath: extraPVC.MountPath,
58+
ReadOnly: *extraPVC.ReadOnly,
59+
}
60+
extraPVCMounts = append(extraPVCMounts, pvcMount)
61+
}
62+
}
63+
5164
if sfsVolume != nil && sfsVolume.Volumes != nil {
5265
pod.Volumes = sfsVolume.Volumes
5366
}
@@ -57,6 +70,11 @@ func StatefulSet(ctx context.Context, cl client.Client, sfs api.StatefulApp, pod
5770
return nil, errors.Wrap(err, "app container")
5871
}
5972

73+
// Attach extraPVCs mounts
74+
if extraPVCMounts != nil {
75+
appC.VolumeMounts = append(appC.VolumeMounts, extraPVCMounts...)
76+
}
77+
6078
pmmC, err := sfs.PMMContainer(ctx, cl, cr.Spec.PMM, secret, cr)
6179
if err != nil {
6280
log.Info(`"pmm container error"`, "secrets", cr.Spec.SecretsName, "internalSecrets", "internal-"+cr.Name, "error", err)

0 commit comments

Comments
 (0)