Skip to content
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

Simplify and fix name issue with ToCoreVolume #576

Merged
merged 1 commit into from
Oct 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions modules/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,17 +167,13 @@ func (s *VolumeSource) ToCoreVolumeSource() (*corev1.VolumeSource, error) {

// ToCoreVolume - convert Volume to corev1.Volume
func (s *Volume) ToCoreVolume() (*corev1.Volume, error) {
coreVolume := &corev1.Volume{}

coreVolumeBytes, err := json.Marshal(s)
volSource, err := s.VolumeSource.ToCoreVolumeSource()
if err != nil {
return nil, fmt.Errorf("error marshalling Volume: %w", err)
return nil, err
}

err = json.Unmarshal(coreVolumeBytes, coreVolume)
if err != nil {
return nil, fmt.Errorf("error unmarshalling Volume: %w", err)
coreVolume := &corev1.Volume{
Name: s.Name,
VolumeSource: *volSource,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in case of error when *volSource is nil this will hit a nil ptr dereference error. should check for err condition before.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good call, pushed a fix for that

}

return coreVolume, nil
}
Loading