Skip to content

Commit 3553144

Browse files
redbaronFxKu
authored andcommitted
Support subPath in generated container (zalando#452)
* mounted volumes now provide a subPath
1 parent c65a9ba commit 3553144

File tree

4 files changed

+11
-4
lines changed

4 files changed

+11
-4
lines changed

docs/reference/cluster_manifest.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,9 @@ properties of the persistent storage that stores postgres data.
282282
documentation](https://kubernetes.io/docs/concepts/storage/storage-classes/)
283283
for the details on storage classes. Optional.
284284

285+
* **subPath**
286+
Subpath to use when mounting volume into Spilo container
287+
285288
### Sidecar definitions
286289

287290
Those parameters are defined under the `sidecars` key. They consist of a list

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ type MaintenanceWindow struct {
8282
type Volume struct {
8383
Size string `json:"size"`
8484
StorageClass string `json:"storageClass"`
85+
SubPath string `json:"subPath,omitempty"`
8586
}
8687

8788
// PostgresqlParam describes PostgreSQL version and pairs of configuration parameter name - values.

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,8 @@ var unmarshalCluster = []struct {
181181
"teamId": "ACID",
182182
"volume": {
183183
"size": "5Gi",
184-
"storageClass": "SSD"
184+
"storageClass": "SSD",
185+
"subPath": "subdir"
185186
},
186187
"numberOfInstances": 2,
187188
"users": {
@@ -263,6 +264,7 @@ var unmarshalCluster = []struct {
263264
Volume: Volume{
264265
Size: "5Gi",
265266
StorageClass: "SSD",
267+
SubPath: "subdir",
266268
},
267269
Patroni: Patroni{
268270
InitDB: map[string]string{
@@ -311,7 +313,7 @@ var unmarshalCluster = []struct {
311313
},
312314
Error: "",
313315
},
314-
marshal: []byte(`{"kind":"Postgresql","apiVersion":"acid.zalan.do/v1","metadata":{"name":"acid-testcluster1","creationTimestamp":null},"spec":{"postgresql":{"version":"9.6","parameters":{"log_statement":"all","max_connections":"10","shared_buffers":"32MB"}},"volume":{"size":"5Gi","storageClass":"SSD"},"patroni":{"initdb":{"data-checksums":"true","encoding":"UTF8","locale":"en_US.UTF-8"},"pg_hba":["hostssl all all 0.0.0.0/0 md5","host all all 0.0.0.0/0 md5"],"ttl":30,"loop_wait":10,"retry_timeout":10,"maximum_lag_on_failover":33554432,"slots":{"permanent_logical_1":{"database":"foo","plugin":"pgoutput","type":"logical"}}},"resources":{"requests":{"cpu":"10m","memory":"50Mi"},"limits":{"cpu":"300m","memory":"3000Mi"}},"teamId":"ACID","allowedSourceRanges":["127.0.0.1/32"],"numberOfInstances":2,"users":{"zalando":["superuser","createdb"]},"maintenanceWindows":["Mon:01:00-06:00","Sat:00:00-04:00","05:00-05:15"],"clone":{"cluster":"acid-batman"}},"status":{"PostgresClusterStatus":""}}`),
316+
marshal: []byte(`{"kind":"Postgresql","apiVersion":"acid.zalan.do/v1","metadata":{"name":"acid-testcluster1","creationTimestamp":null},"spec":{"postgresql":{"version":"9.6","parameters":{"log_statement":"all","max_connections":"10","shared_buffers":"32MB"}},"volume":{"size":"5Gi","storageClass":"SSD", "subPath": "subdir"},"patroni":{"initdb":{"data-checksums":"true","encoding":"UTF8","locale":"en_US.UTF-8"},"pg_hba":["hostssl all all 0.0.0.0/0 md5","host all all 0.0.0.0/0 md5"],"ttl":30,"loop_wait":10,"retry_timeout":10,"maximum_lag_on_failover":33554432,"slots":{"permanent_logical_1":{"database":"foo","plugin":"pgoutput","type":"logical"}}},"resources":{"requests":{"cpu":"10m","memory":"50Mi"},"limits":{"cpu":"300m","memory":"3000Mi"}},"teamId":"ACID","allowedSourceRanges":["127.0.0.1/32"],"numberOfInstances":2,"users":{"zalando":["superuser","createdb"]},"maintenanceWindows":["Mon:01:00-06:00","Sat:00:00-04:00","05:00-05:15"],"clone":{"cluster":"acid-batman"}},"status":{"PostgresClusterStatus":""}}`),
315317
err: nil},
316318
// example with teamId set in input
317319
{

pkg/cluster/k8sres.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,11 +342,12 @@ func isBootstrapOnlyParameter(param string) bool {
342342
param == "track_commit_timestamp"
343343
}
344344

345-
func generateVolumeMounts() []v1.VolumeMount {
345+
func generateVolumeMounts(volume acidv1.Volume) []v1.VolumeMount {
346346
return []v1.VolumeMount{
347347
{
348348
Name: constants.DataVolumeName,
349349
MountPath: constants.PostgresDataMount, //TODO: fetch from manifest
350+
SubPath: volume.SubPath,
350351
},
351352
}
352353
}
@@ -800,7 +801,7 @@ func (c *Cluster) generateStatefulSet(spec *acidv1.PostgresSpec) (*v1beta1.State
800801
// pickup the docker image for the spilo container
801802
effectiveDockerImage := util.Coalesce(spec.DockerImage, c.OpConfig.DockerImage)
802803

803-
volumeMounts := generateVolumeMounts()
804+
volumeMounts := generateVolumeMounts(spec.Volume)
804805

805806
// generate the spilo container
806807
c.logger.Debugf("Generating Spilo container, environment variables: %v", spiloEnvVars)

0 commit comments

Comments
 (0)