-
Notifications
You must be signed in to change notification settings - Fork 1k
Additional volumes capability #736
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
7b155ad
e62242b
07b90ea
4639ea7
1916b5f
316a047
1cf4cc5
e667d86
70eee0e
556ffab
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -494,7 +494,7 @@ func mountShmVolumeNeeded(opConfig config.Config, spec *acidv1.PostgresSpec) *bo | |
| return opConfig.ShmVolume | ||
| } | ||
|
|
||
| func generatePodTemplate( | ||
| func (c *Cluster) generatePodTemplate( | ||
| namespace string, | ||
| labels labels.Set, | ||
| annotations map[string]string, | ||
|
|
@@ -514,6 +514,7 @@ func generatePodTemplate( | |
| additionalSecretMount string, | ||
| additionalSecretMountPath string, | ||
| volumes []v1.Volume, | ||
| additionalVolumes []acidv1.AdditionalVolume, | ||
| ) (*v1.PodTemplateSpec, error) { | ||
|
|
||
| terminateGracePeriodSeconds := terminateGracePeriod | ||
|
|
@@ -553,6 +554,10 @@ func generatePodTemplate( | |
| addSecretVolume(&podSpec, additionalSecretMount, additionalSecretMountPath) | ||
| } | ||
|
|
||
| if additionalVolumes != nil { | ||
| c.addAdditionalVolumes(&podSpec, additionalVolumes) | ||
| } | ||
|
|
||
| template := v1.PodTemplateSpec{ | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Labels: labels, | ||
|
|
@@ -1073,7 +1078,7 @@ func (c *Cluster) generateStatefulSet(spec *acidv1.PostgresSpec) (*appsv1.Statef | |
| annotations := c.generatePodAnnotations(spec) | ||
|
|
||
| // generate pod template for the statefulset, based on the spilo container and sidecars | ||
| podTemplate, err = generatePodTemplate( | ||
| podTemplate, err = c.generatePodTemplate( | ||
| c.Namespace, | ||
| c.labelsSet(true), | ||
| annotations, | ||
|
|
@@ -1093,7 +1098,8 @@ func (c *Cluster) generateStatefulSet(spec *acidv1.PostgresSpec) (*appsv1.Statef | |
| c.OpConfig.AdditionalSecretMount, | ||
| c.OpConfig.AdditionalSecretMountPath, | ||
| volumes, | ||
| ) | ||
| spec.AdditionalVolumes) | ||
|
|
||
| if err != nil { | ||
| return nil, fmt.Errorf("could not generate pod template: %v", err) | ||
| } | ||
|
|
@@ -1287,6 +1293,69 @@ func addSecretVolume(podSpec *v1.PodSpec, additionalSecretMount string, addition | |
| podSpec.Volumes = volumes | ||
| } | ||
|
|
||
| func (c *Cluster) addAdditionalVolumes(podSpec *v1.PodSpec, | ||
| additionalVolumes []acidv1.AdditionalVolume) { | ||
|
|
||
| volumes := podSpec.Volumes | ||
| mountPaths := map[string]acidv1.AdditionalVolume{} | ||
| for i, v := range additionalVolumes { | ||
| if previousVolume, exist := mountPaths[v.MountPath]; exist { | ||
| msg := "Volume %+v cannot be mounted to the same path as %+v" | ||
| c.logger.Warningf(msg, v, previousVolume) | ||
| continue | ||
| } | ||
|
|
||
| if v.MountPath == constants.PostgresDataMount { | ||
| msg := "Cannot mount volume on postgresql data directory, %+v" | ||
| c.logger.Warningf(msg, v) | ||
| continue | ||
| } | ||
|
|
||
| if v.TargetContainers == nil { | ||
| spiloContainer := podSpec.Containers[0] | ||
| additionalVolumes[i].TargetContainers = []string{spiloContainer.Name} | ||
| } | ||
|
|
||
| for _, target := range v.TargetContainers { | ||
| if target == "all" && len(v.TargetContainers) != 1 { | ||
| msg := `Target containers could be either "all" or a list | ||
| of containers, mixing those is not allowed, %+v` | ||
| c.logger.Warningf(msg, v) | ||
| continue | ||
| } | ||
| } | ||
|
|
||
| volumes = append(volumes, | ||
| v1.Volume{ | ||
| Name: v.Name, | ||
| VolumeSource: v.VolumeSource, | ||
| }, | ||
| ) | ||
|
|
||
| mountPaths[v.MountPath] = v | ||
| } | ||
|
|
||
| c.logger.Infof("Mount additional volumes: %+v", additionalVolumes) | ||
|
|
||
| for i := range podSpec.Containers { | ||
| mounts := podSpec.Containers[i].VolumeMounts | ||
| for _, v := range additionalVolumes { | ||
| for _, target := range v.TargetContainers { | ||
| if podSpec.Containers[i].Name == target || target == "all" { | ||
| mounts = append(mounts, v1.VolumeMount{ | ||
| Name: v.Name, | ||
| MountPath: v.MountPath, | ||
| SubPath: v.SubPath, | ||
| }) | ||
| } | ||
| } | ||
| } | ||
| podSpec.Containers[i].VolumeMounts = mounts | ||
| } | ||
|
|
||
| podSpec.Volumes = volumes | ||
| } | ||
|
|
||
| func generatePersistentVolumeClaimTemplate(volumeSize, volumeStorageClass string) (*v1.PersistentVolumeClaim, error) { | ||
|
|
||
| var storageClassName *string | ||
|
|
@@ -1691,7 +1760,7 @@ func (c *Cluster) generateLogicalBackupJob() (*batchv1beta1.CronJob, error) { | |
| annotations := c.generatePodAnnotations(&c.Spec) | ||
|
|
||
| // re-use the method that generates DB pod templates | ||
| if podTemplate, err = generatePodTemplate( | ||
| if podTemplate, err = c.generatePodTemplate( | ||
| c.Namespace, | ||
| labels, | ||
| annotations, | ||
|
|
@@ -1710,8 +1779,9 @@ func (c *Cluster) generateLogicalBackupJob() (*batchv1beta1.CronJob, error) { | |
| "", | ||
| c.OpConfig.AdditionalSecretMount, | ||
| c.OpConfig.AdditionalSecretMountPath, | ||
| nil); err != nil { | ||
| return nil, fmt.Errorf("could not generate pod template for logical backup pod: %v", err) | ||
| nil, | ||
| []acidv1.AdditionalVolume{}); err != nil { | ||
|
||
| return nil, fmt.Errorf("could not generate pod template for logical backup pod: %v", err) | ||
| } | ||
|
|
||
| // overwrite specific params of logical backups pods | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Passing volume[] twice is giving me some headache. The first on was introduced by @zimbatm for the TLS secrets. Maybe that could be mapped to an additionalVolumes too, or it's just renamed tlsVolumes. Anyway, can be done in an extra PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@FxKu -> would this mean that it's either TLS or additionalVolumes?
Our scenario would require both.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no I thought both can be mapped into one array. Hm, but maybe it's also better to keep it separated to highlight the special role of TLS secrets. At least, it has it's own field in the manifest.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@FxKu if there is a new functionality available fully covering a previously specially handled use case, there should be some sort of deprecation. This here seems to be one of those cases where the "old" functionality is simply extended upon and folks simply can move to the new, more feature rich way.
But this could also be the case for the PR implementing a broader sidecar support (#890). Why having multiple things doing the same thing and creating ever more logic to "merge" them and also having to maintain these increasingly complicated code paths.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The two have been merged - see below.
It can be pushed directly: #918
@FxKu and Christian - have a look.
If you want, we can also merge go via @seuf's branch seuf#1 instead - if/once it will be approved by @seuf.
It's same code in both cases.