github.com/jenkins-x/jx/v2@v2.1.155/pkg/kube/volumes.go (about) 1 package kube 2 3 import ( 4 corev1 "k8s.io/api/core/v1" 5 ) 6 7 // CombineVolumes combines all the given volumes together ignoring duplicates 8 func CombineVolumes(volumes []corev1.Volume, otherVolumes ...corev1.Volume) []corev1.Volume { 9 answer := append([]corev1.Volume{}, volumes...) 10 for _, v := range otherVolumes { 11 if !ContainsVolume(answer, v) { 12 answer = append(answer, v) 13 } 14 } 15 return answer 16 } 17 18 // ContainsVolume returns true if the given volume slice contains the given volume 19 func ContainsVolume(volumes []corev1.Volume, volume corev1.Volume) bool { 20 for _, v := range volumes { 21 if v.Name == volume.Name { 22 return true 23 } 24 } 25 return false 26 } 27 28 // ContainsVolumeMount returns true if the given volume mount slice contains the given volume 29 func ContainsVolumeMount(volumes []corev1.VolumeMount, volume corev1.VolumeMount) bool { 30 for _, v := range volumes { 31 if v.Name == volume.Name { 32 return true 33 } 34 } 35 return false 36 }