-
Notifications
You must be signed in to change notification settings - Fork 14
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
remove extra deep copy of object from cache #155
base: main
Are you sure you want to change the base?
Conversation
controller-runtime accepts the pointer to the memory which is reserved by application and runtime deepcopies the object in it's cache to the memory provided by application. this commit removes extra copy of driver spec which isn't required. Signed-off-by: Leela Venkaiah G <[email protected]>
Testing: diff --cc internal/controller/driver_controller.go
index 75a82b8,ce77af7..0000000
--- a/internal/controller/driver_controller.go
+++ b/internal/controller/driver_controller.go
@@@ -312,10 -312,18 +312,16 @@@ func (r *driverReconcile) LoadAndValida
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()
+ r.log.Info("got from cache before merge", "driver", r.driver.Spec)
mergeDriverSpecs(&r.driver.Spec, opConfig.Spec.DriverSpecDefaults)
+ r.log.Info("merged from defaults", "driver", r.driver.Spec)
+ driver := &csiv1a1.Driver{}
+ driver.Name = r.driver.Name
+ driver.Namespace = r.driver.Namespace
+ if err := r.Get(r.ctx, client.ObjectKeyFromObject(driver), driver); err != nil {
+ r.log.Error(err, "failed to get driver", "name", driver.Name)
+ }
+ r.log.Info("got from cache after merge", "driver", driver.Spec)
// If provided, load an imageset from configmap to overwrite default images
imageSetSpec := opConfig.Spec.DriverSpecDefaults.ImageSet ---
apiVersion: csi.ceph.io/v1alpha1
kind: OperatorConfig
metadata:
name: ceph-csi-operator-config
spec:
driverSpecDefaults:
attachRequired: true
clusterName: d4ff6939-86ef-4677-9e64-fee0f622e4da
nodePlugin:
tolerations:
- effect: NoSchedule
key: node-role.kubernetes.io/master
operator: Exists
---
apiVersion: csi.ceph.io/v1alpha1
kind: Driver
metadata:
name: rbd.csi.ceph.com
spec:
attachRequired: false
clusterName: dummy-id
--- Can be seen in below that cache isn't touched w/o deepcopy, as mentioned in #24 (comment), deepcopy of cached items is enabled by default and disabling that functionality is an opt in.
|
@leelavg I am not sure the above test you present tests deep nested pointer structures. |
|
Tested for below config as well, 2 level nested pointer on driver spec apiVersion: csi.ceph.io/v1alpha1
kind: OperatorConfig
metadata:
name: ceph-csi-operator-config
spec:
driverSpecDefaults:
attachRequired: true
clusterName: d4ff6939-86ef-4677-9e64-fee0f622e4da
nodePlugin:
tolerations:
- effect: NoSchedule
key: node-role.kubernetes.io/master
operator: Exists
---
apiVersion: csi.ceph.io/v1alpha1
kind: Driver
metadata:
name: rbd.csi.ceph.com
spec:
attachRequired: false
clusterName: dummy-id
log:
rotation:
logHostPath: /var/lib/cephcsi
maxFiles: 7
maxLogSize: 500M
periodicity: daily
---
|
@leelavg |
|
controller-runtime accepts the pointer to the memory which is reserved by application and runtime deepcopies the object in it's cache to the memory provided by application.
this commit removes extra copy of driver spec which isn't required.
fixes: #58