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

Driver Controller: Fix a nil access bug when accessing DriverSpecDefaults #130

Merged
merged 1 commit into from
Sep 4, 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
44 changes: 24 additions & 20 deletions internal/controller/driver_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,33 +307,37 @@ func (r *driverReconcile) LoadAndValidateDesiredState() error {
return err
}

// Creating a copy of the driver spec, making sure any local changes will not effect the object residing
// in the client's cache
// Cloning default images as the base images before
// merging any user provided images
r.images = maps.Clone(imageDefaults)

if opConfig.Spec.DriverSpecDefaults != nil {
// Creating a copy of the driver spec, making sure any local changes will not effect the object residing
// in the client's cache
r.driver.Spec = *r.driver.Spec.DeepCopy()
mergeDriverSpecs(&r.driver.Spec, opConfig.Spec.DriverSpecDefaults)
}

// If provided, load an imageset from configmap to overwrite default images
r.images = maps.Clone(imageDefaults)
imageSetSpec := opConfig.Spec.DriverSpecDefaults.ImageSet
if imageSetSpec != nil && imageSetSpec.Name != "" {
imageSetCM := corev1.ConfigMap{}
imageSetCM.Name = imageSetSpec.Name
imageSetCM.Namespace = operatorNamespace
if err := r.Get(r.ctx, client.ObjectKeyFromObject(&imageSetCM), &imageSetCM); err != nil {
r.log.Error(
err,
"Unable to load operator config specified image set config map",
"name",
client.ObjectKeyFromObject(&imageSetCM),
)
return err
// If provided, load an imageset from configmap to overwrite default images
imageSetSpec := opConfig.Spec.DriverSpecDefaults.ImageSet
if imageSetSpec != nil && imageSetSpec.Name != "" {
imageSetCM := corev1.ConfigMap{}
imageSetCM.Name = imageSetSpec.Name
imageSetCM.Namespace = operatorNamespace
if err := r.Get(r.ctx, client.ObjectKeyFromObject(&imageSetCM), &imageSetCM); err != nil {
r.log.Error(
err,
"Unable to load operator config specified image set config map",
"name",
client.ObjectKeyFromObject(&imageSetCM),
)
return err
}
maps.Copy(r.images, imageSetCM.Data)
}
maps.Copy(r.images, imageSetCM.Data)
}

// If provided, load an imageset from driver spec overwrite default images
imageSetSpec = r.driver.Spec.ImageSet
imageSetSpec := r.driver.Spec.ImageSet
if imageSetSpec != nil && imageSetSpec.Name != "" {
imageSetCM := corev1.ConfigMap{}
imageSetCM.Name = imageSetSpec.Name
Expand Down
Loading