Skip to content

Commit

Permalink
Merge pull request #1 from feil0n9wan9/bugfix-merge-volumes
Browse files Browse the repository at this point in the history
Fix nil pointer dereference during merging volumes
  • Loading branch information
zmberg authored Aug 14, 2023
2 parents e676b4e + b2c37f5 commit 980cab7
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions sidecarcontrol/mutating_pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,12 @@ func buildSidecars(control SidecarControl, pod *corev1.Pod, oldPod *corev1.Pod,
sidecarInitContainers = append(sidecarInitContainers, initContainer)
// insert volumes that initContainers used
for _, mount := range initContainer.VolumeMounts {
volumesInSidecars = append(volumesInSidecars, *volumesMap[mount.Name])
volume, ok := volumesMap[mount.Name]
if !ok {
return nil, nil, nil, nil, nil,
fmt.Errorf("%q Volume not found for VolumeMount(%s) in SidecarSet: %v", mount.Name, mount.Name, sidecarSet.Name)
}
volumesInSidecars = append(volumesInSidecars, *volume)
}
}
//process imagePullSecrets
Expand Down Expand Up @@ -293,7 +298,12 @@ func buildSidecars(control SidecarControl, pod *corev1.Pod, oldPod *corev1.Pod,
isInjecting = true
// insert volume that sidecar container used
for _, mount := range sidecarContainer.VolumeMounts {
volumesInSidecars = append(volumesInSidecars, *volumesMap[mount.Name])
volume, ok := volumesMap[mount.Name]
if !ok {
return nil, nil, nil, nil, nil,
fmt.Errorf("%q Volume not found for VolumeMount(%s) in SidecarSet: %v", mount.Name, mount.Name, sidecarSet.Name)
}
volumesInSidecars = append(volumesInSidecars, *volume)
}
// merge VolumeMounts from sidecar.VolumeMounts and shared VolumeMounts
sidecarContainer.VolumeMounts = utils.MergeVolumeMounts(sidecarContainer.VolumeMounts, injectedMounts)
Expand Down

0 comments on commit 980cab7

Please sign in to comment.