mirror of
https://github.com/actions/actions-runner-controller.git
synced 2025-12-10 19:50:30 +00:00
Fix panic: slice bounds out of range when runner spec contains volumeMounts. (#2720)
Signed-off-by: Gavin Williams <gavin.williams@machinemax.com>
This commit is contained in:
@@ -607,11 +607,14 @@ func (r *RunnerReconciler) newPod(runner v1alpha1.Runner) (corev1.Pod, error) {
|
|||||||
if runnerSpec.ContainerMode == "kubernetes" {
|
if runnerSpec.ContainerMode == "kubernetes" {
|
||||||
return pod, errors.New("volume mount \"work\" should be specified by workVolumeClaimTemplate in container mode kubernetes")
|
return pod, errors.New("volume mount \"work\" should be specified by workVolumeClaimTemplate in container mode kubernetes")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
podSpecIsPresent, index := workVolumeMountPresent(pod.Spec.Containers[0].VolumeMounts)
|
||||||
|
if podSpecIsPresent {
|
||||||
// remove work volume since it will be provided from runnerSpec.Volumes
|
// remove work volume since it will be provided from runnerSpec.Volumes
|
||||||
// if we don't remove it here we would get a duplicate key error, i.e. two volumes named work
|
// if we don't remove it here we would get a duplicate key error, i.e. two volumes named work
|
||||||
_, index := workVolumeMountPresent(pod.Spec.Containers[0].VolumeMounts)
|
|
||||||
pod.Spec.Containers[0].VolumeMounts = append(pod.Spec.Containers[0].VolumeMounts[:index], pod.Spec.Containers[0].VolumeMounts[index+1:]...)
|
pod.Spec.Containers[0].VolumeMounts = append(pod.Spec.Containers[0].VolumeMounts[:index], pod.Spec.Containers[0].VolumeMounts[index+1:]...)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pod.Spec.Containers[0].VolumeMounts = append(pod.Spec.Containers[0].VolumeMounts, runnerSpec.VolumeMounts...)
|
pod.Spec.Containers[0].VolumeMounts = append(pod.Spec.Containers[0].VolumeMounts, runnerSpec.VolumeMounts...)
|
||||||
}
|
}
|
||||||
@@ -623,12 +626,14 @@ func (r *RunnerReconciler) newPod(runner v1alpha1.Runner) (corev1.Pod, error) {
|
|||||||
if runnerSpec.ContainerMode == "kubernetes" {
|
if runnerSpec.ContainerMode == "kubernetes" {
|
||||||
return pod, errors.New("volume \"work\" should be specified by workVolumeClaimTemplate in container mode kubernetes")
|
return pod, errors.New("volume \"work\" should be specified by workVolumeClaimTemplate in container mode kubernetes")
|
||||||
}
|
}
|
||||||
_, index := workVolumePresent(pod.Spec.Volumes)
|
|
||||||
|
|
||||||
|
podSpecIsPresent, index := workVolumePresent(pod.Spec.Volumes)
|
||||||
|
if podSpecIsPresent {
|
||||||
// remove work volume since it will be provided from runnerSpec.Volumes
|
// remove work volume since it will be provided from runnerSpec.Volumes
|
||||||
// if we don't remove it here we would get a duplicate key error, i.e. two volumes named work
|
// if we don't remove it here we would get a duplicate key error, i.e. two volumes named work
|
||||||
pod.Spec.Volumes = append(pod.Spec.Volumes[:index], pod.Spec.Volumes[index+1:]...)
|
pod.Spec.Volumes = append(pod.Spec.Volumes[:index], pod.Spec.Volumes[index+1:]...)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pod.Spec.Volumes = append(pod.Spec.Volumes, runnerSpec.Volumes...)
|
pod.Spec.Volumes = append(pod.Spec.Volumes, runnerSpec.Volumes...)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user