fix: declare one k3s pod volume per storage entry
Mounting one storage entry at two container paths named the same pod volume twice, which Kubernetes rejects as a duplicate, so the chart never applied even though the k3s documentation offers mounting a claim "into the same app at multiple subpaths" as a supported shape. A pod now declares each entry once and binds it at each path it was mounted at. Rendering the chart in a test also surfaced that a cron schedule was emitted unquoted, so any schedule beginning with `*` produced a manifest that could not be parsed at all.
This commit is contained in:
7 files changed
+387
-23
No files matched your search
@@ -293,8 +293,9 @@ func ValidateMountPairs(pairs []AppMountPair) error {
|
||||
}
|
||||
|
||||
// ToProcessVolumes converts the AppMountPairs that apply to processType into
|
||||
// ProcessVolumes. K3s app deployments reference the PVC by name; the PVC
|
||||
// itself is owned by the storage entry's separate helm release.
|
||||
// ProcessVolumes, one per container mount. K3s app deployments reference the
|
||||
// PVC by name; the PVC itself is owned by the storage entry's separate helm
|
||||
// release.
|
||||
//
|
||||
// An empty processType names a workload that belongs to no process type - a
|
||||
// cron job - and so receives default-scoped attachments only.
|
||||
@@ -320,20 +321,54 @@ func ToProcessVolumes(pairs []AppMountPair, processType string) []ProcessVolume
|
||||
return volumes
|
||||
}
|
||||
|
||||
// processVolumesFor returns the volumes one process type's pods receive: the
|
||||
// volumes every workload in the app gets, plus the storage attachments scoped
|
||||
// to that process type. The slice is freshly allocated rather than appended
|
||||
// onto base, so one workload's volumes can never alias another's.
|
||||
func processVolumesFor(base []ProcessVolume, pairs []AppMountPair, processType string) []ProcessVolume {
|
||||
// processVolumesFor returns the volumes one process type's pods receive: what
|
||||
// every workload in the app gets, plus the storage attachments scoped to that
|
||||
// process type. The slice is freshly allocated rather than appended onto base,
|
||||
// so one workload's volumes can never alias another's.
|
||||
//
|
||||
// Entries repeat a Name once per container path, which is what the chart wants:
|
||||
// it renders a volumeMounts entry per element and a pod volume per distinct
|
||||
// Name. Two different sources claiming one Name cannot be rendered that way, so
|
||||
// they are rejected rather than silently collapsed to whichever came first.
|
||||
func processVolumesFor(base []ProcessVolume, pairs []AppMountPair, processType string) ([]ProcessVolume, error) {
|
||||
scoped := ToProcessVolumes(pairs, processType)
|
||||
|
||||
volumes := make([]ProcessVolume, 0, len(base)+len(scoped))
|
||||
volumes = append(volumes, base...)
|
||||
volumes = append(volumes, scoped...)
|
||||
return volumes
|
||||
|
||||
sources := map[string]ProcessVolume{}
|
||||
for _, volume := range volumes {
|
||||
existing, seen := sources[volume.Name]
|
||||
if seen && !sameVolumeSource(existing, volume) {
|
||||
return nil, fmt.Errorf("volume name %q is claimed by two different sources in one pod", volume.Name)
|
||||
}
|
||||
sources[volume.Name] = volume
|
||||
}
|
||||
|
||||
return volumes, nil
|
||||
}
|
||||
|
||||
// asK8sVolumeMount is a small helper used by tests / other callers that
|
||||
// want a corev1.VolumeMount from a ProcessVolume.
|
||||
// sameVolumeSource reports whether two same-named volumes resolve to the same
|
||||
// backing source and can therefore share one pod volume.
|
||||
func sameVolumeSource(first ProcessVolume, second ProcessVolume) bool {
|
||||
if (first.PersistentClaim == nil) != (second.PersistentClaim == nil) {
|
||||
return false
|
||||
}
|
||||
if first.PersistentClaim != nil && *first.PersistentClaim != *second.PersistentClaim {
|
||||
return false
|
||||
}
|
||||
if (first.EmptyDir == nil) != (second.EmptyDir == nil) {
|
||||
return false
|
||||
}
|
||||
if first.EmptyDir != nil && *first.EmptyDir != *second.EmptyDir {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// asK8sVolumeMount converts a ProcessVolume into the corev1 mount shape for
|
||||
// callers that work against the Kubernetes API types directly.
|
||||
func asK8sVolumeMount(v ProcessVolume) corev1.VolumeMount {
|
||||
return corev1.VolumeMount{
|
||||
Name: v.Name,
|
||||
|
||||
Reference in new issue
Block a user