intel-device-plugins-for-kubernetes icon indicating copy to clipboard operation
intel-device-plugins-for-kubernetes copied to clipboard

Fix code duplicates in pkg/controllers

Open bart0sh opened this issue 4 years ago • 0 comments

There is a lot of copied&pasted code in pkg/controllers, for example in SetupReconciler, NewDaemonSet, UpdateDaemonSet, UpdateStatus, setInitContainer, addVolumeIfMissing functions.

dupl reports quite a bit of duplicates for this code:

pkg/controllers (test) $ dupl -t 50
found 2 clones:
  dsa/controller.go:129,159
  dsa/controller_test.go:158,188
found 6 clones:
  dlb/controller.go:42,53
  dsa/controller.go:46,57
  fpga/controller.go:44,55
  gpu/controller.go:49,60
  qat/controller.go:44,55
  sgx/controller.go:46,57
found 2 clones:
  dlb/controller_test.go:101,126
  gpu/controller_test.go:114,139
found 2 clones:
  dlb/controller.go:65,84
  fpga/controller.go:67,85
found 2 clones:
  reconciler.go:363,381
  reconciler.go:383,401
found 3 clones:
  reconciler.go:233,251
  reconciler.go:253,271
  reconciler.go:273,291
found 2 clones:
  gpu/controller.go:171,207
  sgx/controller.go:78,114
found 2 clones:
  qat/controller_test.go:127,137
  sgx/controller_test.go:161,171
found 2 clones:
  reconciler.go:451,463
  reconciler.go:465,477
found 6 clones:
  dlb/controller.go:108,137
  dsa/controller.go:191,220
  fpga/controller.go:114,143
  gpu/controller.go:282,311
  qat/controller.go:120,149
  sgx/controller.go:172,201
found 6 clones:
  dlb/controller.go:65,72
  dsa/controller.go:69,76
  fpga/controller.go:67,74
  gpu/controller.go:71,78
  qat/controller.go:67,74
  sgx/controller.go:69,76
found 2 clones:
  dlb/controller_test.go:136,146
  dsa/controller_test.go:195,205

Found total 12 clone groups.

It makes sense to look if we can do better than just copying the same code around.

bart0sh avatar Nov 24 '21 10:11 bart0sh