Support subPath in generated container (#452)
* mounted volumes now provide a subPath
This commit is contained in:
		
							parent
							
								
									c65a9baedf
								
							
						
					
					
						commit
						3553144cda
					
				|  | @ -282,6 +282,9 @@ properties of the persistent storage that stores postgres data. | ||||||
|   documentation](https://kubernetes.io/docs/concepts/storage/storage-classes/) |   documentation](https://kubernetes.io/docs/concepts/storage/storage-classes/) | ||||||
|   for the details on storage classes. Optional. |   for the details on storage classes. Optional. | ||||||
| 
 | 
 | ||||||
|  | * **subPath** | ||||||
|  |   Subpath to use when mounting volume into Spilo container | ||||||
|  | 
 | ||||||
| ### Sidecar definitions | ### Sidecar definitions | ||||||
| 
 | 
 | ||||||
| Those parameters are defined under the `sidecars` key. They consist of a list | Those parameters are defined under the `sidecars` key. They consist of a list | ||||||
|  |  | ||||||
|  | @ -82,6 +82,7 @@ type MaintenanceWindow struct { | ||||||
| type Volume struct { | type Volume struct { | ||||||
| 	Size         string `json:"size"` | 	Size         string `json:"size"` | ||||||
| 	StorageClass string `json:"storageClass"` | 	StorageClass string `json:"storageClass"` | ||||||
|  | 	SubPath      string `json:"subPath,omitempty"` | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // PostgresqlParam describes PostgreSQL version and pairs of configuration parameter name - values.
 | // PostgresqlParam describes PostgreSQL version and pairs of configuration parameter name - values.
 | ||||||
|  |  | ||||||
|  | @ -181,7 +181,8 @@ var unmarshalCluster = []struct { | ||||||
| 	    "teamId": "ACID", | 	    "teamId": "ACID", | ||||||
| 	    "volume": { | 	    "volume": { | ||||||
| 	      "size": "5Gi", | 	      "size": "5Gi", | ||||||
| 	      "storageClass": "SSD" | 	      "storageClass": "SSD", | ||||||
|  | 	      "subPath": "subdir" | ||||||
| 	    }, | 	    }, | ||||||
| 	    "numberOfInstances": 2, | 	    "numberOfInstances": 2, | ||||||
| 	    "users": { | 	    "users": { | ||||||
|  | @ -263,6 +264,7 @@ var unmarshalCluster = []struct { | ||||||
| 				Volume: Volume{ | 				Volume: Volume{ | ||||||
| 					Size:         "5Gi", | 					Size:         "5Gi", | ||||||
| 					StorageClass: "SSD", | 					StorageClass: "SSD", | ||||||
|  | 					SubPath:      "subdir", | ||||||
| 				}, | 				}, | ||||||
| 				Patroni: Patroni{ | 				Patroni: Patroni{ | ||||||
| 					InitDB: map[string]string{ | 					InitDB: map[string]string{ | ||||||
|  | @ -311,7 +313,7 @@ var unmarshalCluster = []struct { | ||||||
| 			}, | 			}, | ||||||
| 			Error: "", | 			Error: "", | ||||||
| 		}, | 		}, | ||||||
| 		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":""}}`), | 		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":""}}`), | ||||||
| 		err:     nil}, | 		err:     nil}, | ||||||
| 	// example with teamId set in input
 | 	// example with teamId set in input
 | ||||||
| 	{ | 	{ | ||||||
|  |  | ||||||
|  | @ -342,11 +342,12 @@ func isBootstrapOnlyParameter(param string) bool { | ||||||
| 		param == "track_commit_timestamp" | 		param == "track_commit_timestamp" | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func generateVolumeMounts() []v1.VolumeMount { | func generateVolumeMounts(volume acidv1.Volume) []v1.VolumeMount { | ||||||
| 	return []v1.VolumeMount{ | 	return []v1.VolumeMount{ | ||||||
| 		{ | 		{ | ||||||
| 			Name:      constants.DataVolumeName, | 			Name:      constants.DataVolumeName, | ||||||
| 			MountPath: constants.PostgresDataMount, //TODO: fetch from manifest
 | 			MountPath: constants.PostgresDataMount, //TODO: fetch from manifest
 | ||||||
|  | 			SubPath:   volume.SubPath, | ||||||
| 		}, | 		}, | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  | @ -800,7 +801,7 @@ func (c *Cluster) generateStatefulSet(spec *acidv1.PostgresSpec) (*v1beta1.State | ||||||
| 	// pickup the docker image for the spilo container
 | 	// pickup the docker image for the spilo container
 | ||||||
| 	effectiveDockerImage := util.Coalesce(spec.DockerImage, c.OpConfig.DockerImage) | 	effectiveDockerImage := util.Coalesce(spec.DockerImage, c.OpConfig.DockerImage) | ||||||
| 
 | 
 | ||||||
| 	volumeMounts := generateVolumeMounts() | 	volumeMounts := generateVolumeMounts(spec.Volume) | ||||||
| 
 | 
 | ||||||
| 	// generate the spilo container
 | 	// generate the spilo container
 | ||||||
| 	c.logger.Debugf("Generating Spilo container, environment variables: %v", spiloEnvVars) | 	c.logger.Debugf("Generating Spilo container, environment variables: %v", spiloEnvVars) | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue