Fix: deepcopy before mutating shared objects
Signed-off-by: dkeven <keven@kubesphere.io>
This commit is contained in:
@@ -123,6 +123,7 @@ func (s *persistentVolumeClaimSearcher) Search(namespace string, conditions *par
|
||||
|
||||
r := make([]interface{}, 0)
|
||||
for _, i := range result {
|
||||
i = i.DeepCopy()
|
||||
inUse := s.countPods(i.Name, i.Namespace)
|
||||
isSnapshotAllow := s.isSnapshotAllowed(i.GetAnnotations()["volume.beta.kubernetes.io/storage-provisioner"])
|
||||
if i.Annotations == nil {
|
||||
|
||||
@@ -91,6 +91,7 @@ func (s *storageClassesSearcher) Search(namespace string, conditions *params.Con
|
||||
|
||||
r := make([]interface{}, 0)
|
||||
for _, i := range result {
|
||||
i = i.DeepCopy()
|
||||
count := s.countPersistentVolumeClaims(i.Name)
|
||||
if i.Annotations == nil {
|
||||
i.Annotations = make(map[string]string)
|
||||
|
||||
@@ -22,8 +22,19 @@ var (
|
||||
},
|
||||
}
|
||||
|
||||
sc1Expected = &v1.StorageClass{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "sc1",
|
||||
Annotations: map[string]string{
|
||||
"kubesphere.io/pvc-count": "1",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
scs = []interface{}{sc1}
|
||||
|
||||
scsExpected = []interface{}{sc1Expected}
|
||||
|
||||
pvc1 = &corev1.PersistentVolumeClaim{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "pvc1",
|
||||
@@ -85,7 +96,7 @@ func TestSearch(t *testing.T) {
|
||||
conditions: ¶ms.Conditions{},
|
||||
orderBy: "name",
|
||||
reverse: true,
|
||||
expected: scs,
|
||||
expected: scsExpected,
|
||||
expectedErr: nil,
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user