[Bug] Shallow copy causes different worker configurations #714
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Why are these changes needed?
(1) Shallow copy of a go struct is not encouraged, and see article for more details.
(2) The following code snippet is from
raycluster_controller.go
. We passed the structworker
(type WorkerGroupSpec struct
) to the functioncreateWorkerPod
in the for loop. Due to shallow copy (See (3) for more details),worker
will be updated in each iteration. That is, the specifications of created worker pods may differ based oni
.kuberay/ray-operator/controllers/ray/raycluster_controller.go
Lines 511 to 516 in 0579c90
For example, we can create a RayCluster CR with
worker.replicas = 2
. We can see the following error messages fromkuberay-operator
. After the first worker pod is created, the variableworker
is updated and has 1 volumeMount for/dev/shm
. The second worker pod's specification has two volumeMounts for/dev/shm
. Hence, Kubernetes API server reports the error. You must usekuberay/operator
without commit #690 (e.g.kuberay/operator:v0.3.0
) to reproduce this error. #690 can avoid misconfiguration, but cannot solve the root cause of this PR.(3) "shallow copy of struct" I mentioned in (2) is not totally accurate. A struct is by default deep copied, but elements in the struct may be shallow copied or deep copied. See Shallow copy and Deep copy in Go for more details.
Related issue number
This PR solves a part of #716.
Checks