Skip to content

Commit bdb32bc

Browse files
smutelSamuel Mutel
authored and
Samuel Mutel
committed
feat: Add SubPathExpr option for additionalVolumes
1 parent 409e4c7 commit bdb32bc

File tree

8 files changed

+49
-4
lines changed

8 files changed

+49
-4
lines changed

charts/postgres-operator/crds/postgresqls.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ spec:
101101
x-kubernetes-preserve-unknown-fields: true
102102
subPath:
103103
type: string
104+
isSubPathExpr:
105+
type: boolean
104106
allowedSourceRanges:
105107
type: array
106108
nullable: true

docs/reference/cluster_manifest.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ These parameters are grouped directly under the `spec` key in the manifest.
227227
It allows you to mount existing PersistentVolumeClaims, ConfigMaps and Secrets inside the StatefulSet.
228228
Also an `emptyDir` volume can be shared between initContainer and statefulSet.
229229
Additionaly, you can provide a `SubPath` for volume mount (a file in a configMap source volume, for example).
230+
Set `isSubPathExpr` to true if you want to include [API environment variables](https://kubernetes.io/docs/concepts/storage/volumes/#using-subpath-expanded-environment).
230231
You can also specify in which container the additional Volumes will be mounted with the `targetContainers` array option.
231232
If `targetContainers` is empty, additional volumes will be mounted only in the `postgres` container.
232233
If you set the `all` special item, it will be mounted in all containers (postgres + sidecars).

manifests/complete-postgres-manifest.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,16 @@ spec:
8181
# PersistentVolumeClaim:
8282
# claimName: pvc-postgresql-data-partitions
8383
# readyOnly: false
84+
# - name: data
85+
# mountPath: /home/postgres/pgdata/partitions
86+
# subPath: $(NODE_NAME)/$(POD_NAME)
87+
# isSubPathExpr: true
88+
# targetContainers:
89+
# - postgres
90+
# volumeSource:
91+
# PersistentVolumeClaim:
92+
# claimName: pvc-postgresql-data-partitions
93+
# readyOnly: false
8494
# - name: conf
8595
# mountPath: /etc/telegraf
8696
# subPath: telegraf.conf

manifests/postgresql.crd.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ spec:
9999
x-kubernetes-preserve-unknown-fields: true
100100
subPath:
101101
type: string
102+
isSubPathExpr:
103+
type: boolean
102104
allowedSourceRanges:
103105
type: array
104106
nullable: true

pkg/apis/acid.zalan.do/v1/crds.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,9 @@ var PostgresCRDResourceValidation = apiextv1.CustomResourceValidation{
167167
"subPath": {
168168
Type: "string",
169169
},
170+
"isSubPathExpr": {
171+
Type: "boolean",
172+
},
170173
},
171174
},
172175
},

pkg/apis/acid.zalan.do/v1/postgresql_type.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ type AdditionalVolume struct {
141141
Name string `json:"name"`
142142
MountPath string `json:"mountPath"`
143143
SubPath string `json:"subPath,omitempty"`
144+
IsSubPathExpr bool `json:"isSubPathExpr,omitemtpy"`
144145
TargetContainers []string `json:"targetContainers"`
145146
VolumeSource v1.VolumeSource `json:"volumeSource"`
146147
}

pkg/cluster/k8sres.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1751,11 +1751,18 @@ func (c *Cluster) addAdditionalVolumes(podSpec *v1.PodSpec,
17511751
for _, additionalVolume := range additionalVolumes {
17521752
for _, target := range additionalVolume.TargetContainers {
17531753
if podSpec.Containers[i].Name == target || target == "all" {
1754-
mounts = append(mounts, v1.VolumeMount{
1754+
v := v1.VolumeMount{
17551755
Name: additionalVolume.Name,
17561756
MountPath: additionalVolume.MountPath,
1757-
SubPath: additionalVolume.SubPath,
1758-
})
1757+
}
1758+
1759+
if additionalVolume.IsSubPathExpr {
1760+
v.SubPathExpr = additionalVolume.SubPath
1761+
} else {
1762+
v.SubPath = additionalVolume.SubPath
1763+
}
1764+
1765+
mounts = append(mounts, v)
17591766
}
17601767
}
17611768
}

pkg/cluster/k8sres_test.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1812,6 +1812,25 @@ func TestAdditionalVolume(t *testing.T) {
18121812
EmptyDir: &v1.EmptyDirVolumeSource{},
18131813
},
18141814
},
1815+
{
1816+
Name: "test5",
1817+
MountPath: "/test5",
1818+
SubPath: "/test5",
1819+
TargetContainers: nil, // should mount only to postgres
1820+
VolumeSource: v1.VolumeSource{
1821+
EmptyDir: &v1.EmptyDirVolumeSource{},
1822+
},
1823+
},
1824+
{
1825+
Name: "test6",
1826+
MountPath: "/test6",
1827+
SubPath: "$(POD_NAME)",
1828+
IsSubPathExpr: true,
1829+
TargetContainers: nil, // should mount only to postgres
1830+
VolumeSource: v1.VolumeSource{
1831+
EmptyDir: &v1.EmptyDirVolumeSource{},
1832+
},
1833+
},
18151834
}
18161835

18171836
pg := acidv1.Postgresql{
@@ -1865,7 +1884,7 @@ func TestAdditionalVolume(t *testing.T) {
18651884
{
18661885
subTest: "checking volume mounts of postgres container",
18671886
container: constants.PostgresContainerName,
1868-
expectedMounts: []string{"pgdata", "test1", "test3", "test4"},
1887+
expectedMounts: []string{"pgdata", "test1", "test3", "test4", "test5", "test6"},
18691888
},
18701889
{
18711890
subTest: "checking volume mounts of sidecar container",

0 commit comments

Comments
 (0)