-
Notifications
You must be signed in to change notification settings - Fork 345
/
util.go
37 lines (32 loc) · 959 Bytes
/
util.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package util
import (
"k8s.io/api/core/v1"
)
// RemoveDuplicatedVolumes defines to remove the last duplicated items in slice if the Name of Volume is the same
func RemoveDuplicatedVolumes(volumes []v1.Volume) []v1.Volume {
var results []v1.Volume
existing := map[string]bool{}
for _, volume := range volumes {
if existing[volume.Name] {
continue
}
results = append(results, volume)
existing[volume.Name] = true
}
// Return the new slice.
return results
}
// RemoveDuplicatedVolumeMounts defines to remove the last duplicated item in slice if the Name of Volume is the same
func RemoveDuplicatedVolumeMounts(volumeMounts []v1.VolumeMount) []v1.VolumeMount {
var results []v1.VolumeMount
existing := map[string]bool{}
for _, volumeMount := range volumeMounts {
if existing[volumeMount.Name] {
continue
}
results = append(results, volumeMount)
existing[volumeMount.Name] = true
}
// Return the new slice.
return results
}