-
Notifications
You must be signed in to change notification settings - Fork 622
Attach additional volume for postgres, #4210
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
base: main
Are you sure you want to change the base?
Attach additional volume for postgres, #4210
Conversation
pkg/apis/postgres-operator.crunchydata.com/v1beta1/postgrescluster_types.go
Outdated
Show resolved
Hide resolved
pkg/apis/postgres-operator.crunchydata.com/v1beta1/postgrescluster_types.go
Outdated
Show resolved
Hide resolved
pkg/apis/postgres-operator.crunchydata.com/v1beta1/postgrescluster_types.go
Outdated
Show resolved
Hide resolved
pkg/apis/postgres-operator.crunchydata.com/v1beta1/postgrescluster_types.go
Show resolved
Hide resolved
internal/naming/names.go
Outdated
// volume for instance. | ||
func AdditionalVolume(cluster *v1beta1.PostgresCluster, | ||
volume *v1beta1.AdditionalVolume) metav1.ObjectMeta { | ||
// TODO: What's the name for the PVC if not given? |
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 name
field, I imagine. That field should have validation that rejects weird filepath stuff (e.g. slash) and is also valid for K8s API name (subdomain?). We have a few predefined types for names.
[PersistentVolumeClaim (PVC) names are DNS subdomains](https://releases.k8s.io/v1.23.0/pkg/apis/core/validation/validation.go#L2066). |
postgres-operator/pkg/apis/postgres-operator.crunchydata.com/v1beta1/shared_types.go
Lines 32 to 33 in 899c4a0
// +kubebuilder:validation:Pattern=`^[a-z0-9]([-a-z0-9]*[a-z0-9])?([.][a-z0-9]([-a-z0-9]*[a-z0-9])?)*$` | |
type DNS1123Subdomain = string |
d9d4932
to
f906775
Compare
pkg/apis/postgres-operator.crunchydata.com/v1beta1/postgrescluster_types.go
Outdated
Show resolved
Hide resolved
pkg/apis/postgres-operator.crunchydata.com/v1beta1/postgrescluster_types.go
Outdated
Show resolved
Hide resolved
pkg/apis/postgres-operator.crunchydata.com/v1beta1/postgrescluster_types.go
Outdated
Show resolved
Hide resolved
pkg/apis/postgres-operator.crunchydata.com/v1/postgrescluster_types.go
Outdated
Show resolved
Hide resolved
additionalVolumeRequest.ClaimName) | ||
|
||
additionalVolume := corev1.Volume{ | ||
Name: additionalVolumeMount.Name, |
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.
🤔 Ah, hmm. Volume names must be unique in a pod. What happens If someone uses postgres-data
for their volume name? Maybe we should prefix with volume-
?
🤔 🤔 What other (Pod) validation happens on this name in K8s? Maybe a limit on the length?
postgres-operator/internal/postgres/reconcile.go
Lines 26 to 28 in 6a30d72
func DataVolumeMount() corev1.VolumeMount { | |
return corev1.VolumeMount{Name: "postgres-data", MountPath: dataMountPath} | |
} |
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.
For the pod.spec.volumes, its says "Must be a DNS_LABEL and unique within the pod." (cite)
That's what the code comment says, at least.
+1 for a prefix that prevents other problems
ClaimName: additionalVolumeMount.Name, | ||
ReadOnly: additionalVolumeRequest.ReadOnly, |
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.
❓ I'm getting a little mixed up with which name is where. Should this be additionalVolumeRequest.claimName
?
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.
This is a little confusing because I'm switching from using the derived Mount spec to our AdditionalVolume spec -- I think I can clean this up by (a) using the request name above, (b) creating the Mount spec with the ReadOnly field, and (c) sticking to the Mount spec here.
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.
Eh, tackling this and the comment re: naming the volumes, the code is less intuitive than I wanted
|
||
// addAdditionalVolumesToSpecifiedContainers adds additional volumes to the specified | ||
// containers in the specified pod | ||
func addAdditionalVolumesToSpecifiedContainers(template *corev1.PodTemplateSpec, |
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.
👍🏻 I like that this takes a template.
88d226d
to
955087a
Compare
Change the API to allow users to specify preexisting PVCs to attach to specified containers in the postgres instance pods. Issues: [PGO-2556]
955087a
to
0f1cf63
Compare
template.Spec.Volumes = append( | ||
template.Spec.Volumes, | ||
additionalVolume) |
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.
This is probably fine, but just to clarify, it seems we will always add the volume even if we don't mount it to any containers (which would only happen if the user specifies a container(s) but none of the containers specified actually exist in the pod)...
Do we want to warn the user in any way if any of the containers they've specified don't exist? 🤔 Seems unlikely the user would do this on purpose, but if they misspell/typo their container name and don't realize it...
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.
Yeah, it's funny, I was just talking with Andrew earlier in the week about how some people might want to not add the volume to any containers through our system, but mount them manually through, say, the sidecar container spec.
But we don't actually let people mount to no containers: we have some (list the containers) and all (a blank list). Should we add a "none" option or special keyword?
But yeah, right now, we have (a) no way to skip mounting and (b) no validation on the containers being present.
Now if I mispell "database" when trying to mount to the pod, what should our behavior be? I guess we should error out because, likely, if a user put in the wrong container name, and we just warned and created the pod, then they'd find out later, and fix the spec, causing the pod to regenerate. What do you think?
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.
What would be the point of the user adding their PVC to volumes.additional
if they don't want us to mount it to any containers?
Yeah I think doing something (error/warning event/log) makes sense if the user specifies a container that doesn't exist.
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.
Yeah, the only potential that I see -- though there might be others -- is that the user has a container definition that already has that volume mounted and it's easier for them (for some reason, potentially CI related) to use that as a custom sidecar (with the volume mounted) rather than define the postgrescluster spec with that volume mounted to that container.
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.
@andrewlecuyer This question isn't a blocker (as we can refine the solution as we move forwards) but I want to raise it:
If the user supplies a container that doesn't exist, what should our behavior be?
Options:
- Ignore that issue, let them figure it out. (Con: not very user friendly to not provide feedback)
- Issue a warning event, but continue to reconcile the pod (Con: if they see the warning, the user will have to fix the spec, which will cause a pod regeneration of a mis-spec'ed pod)
- Error, stop reconciling pod, issue event
for i := range template.Spec.Containers { | ||
if names.Len() == 0 || names.Has(template.Spec.Containers[i].Name) { | ||
template.Spec.Containers[i].VolumeMounts = append( | ||
template.Spec.Containers[i].VolumeMounts, | ||
additionalVolumeMount) | ||
} | ||
} | ||
|
||
for i := range template.Spec.InitContainers { | ||
if names.Len() == 0 || names.Has(template.Spec.InitContainers[i].Name) { | ||
template.Spec.InitContainers[i].VolumeMounts = append( | ||
template.Spec.InitContainers[i].VolumeMounts, | ||
additionalVolumeMount) | ||
} | ||
} | ||
|
||
template.Spec.Volumes = append( |
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.
If the PVC specified by the user doesn't actually exist, what happens? I'm pretty sure that the Pod will break in some fashion... Do we want to provide any protection from this footgun? 🤔
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.
If the PVC doesn't exist, the pod will not be scheduled and we get a warning event from K8s:
5s Warning FailedScheduling pod/hippo-instance1-f8kj-0 0/1 nodes are available: persistentvolumeclaim "task-pv-claim" not found.
It might be nice to check if the PVCs exist, but we don't really do anything for those areas in our spec where we allow a user to specify a preexisting volume (or configmap, secret, etc.).
(I do kind of like the idea of checking the env before accepting a postgrescluster spec, but that's not really what we do.)
Checklist:
Type of Changes:
What is the current behavior (link to any open issues here)?
Only can add additional volumes to database container through abuse of the tablespace volumes.
What is the new behavior (if this is a feature change)?
Ability to add PVC (either BYO or create from template) to multiple containers in the Postgres pod
Other Information:
Issues: [PGO-2556]