intel / intel/intel-device-plugins-for-kubernetes

Fix code duplicates in pkg/controllers

Open
#765 0 comments 0 reactions 0 assignees View on GitHub
operator
Dominant language
Go
Stars
147
Forks
223
Avg merge
3d 23h
Merged PRs (30d)
18

Description

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

[dupl](https://github.com/mibk/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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.