@@ -47,6 +47,10 @@ func (d *DevfileV2) DeleteVolumeMount(name string) error {
47
47
found := false
48
48
for i := range d .Components {
49
49
if d .Components [i ].Container != nil && d .Components [i ].Name != name {
50
+ // Volume Mounts can have multiple instances of a volume mounted at different paths
51
+ // As arrays are rearraged/shifted for deletion, we lose one element every time there is a match
52
+ // Looping backward is efficient, otherwise we would have to manually decrement counter
53
+ // if we looped forward
50
54
for j := len (d .Components [i ].Container .VolumeMounts ) - 1 ; j >= 0 ; j -- {
51
55
if d .Components [i ].Container .VolumeMounts [j ].Name == name {
52
56
found = true
@@ -68,17 +72,14 @@ func (d *DevfileV2) DeleteVolumeMount(name string) error {
68
72
69
73
// GetVolumeMountPath gets the mount path of the specified volume mount from the specified container component
70
74
func (d * DevfileV2 ) GetVolumeMountPath (mountName , componentName string ) (string , error ) {
71
- mountFound := false
72
75
componentFound := false
73
- var path string
74
76
75
77
for _ , component := range d .Components {
76
78
if component .Container != nil && component .Name == componentName {
77
79
componentFound = true
78
80
for _ , volumeMount := range component .Container .VolumeMounts {
79
81
if volumeMount .Name == mountName {
80
- mountFound = true
81
- path = volumeMount .Path
82
+ return volumeMount .Path , nil
82
83
}
83
84
}
84
85
}
@@ -89,9 +90,7 @@ func (d *DevfileV2) GetVolumeMountPath(mountName, componentName string) (string,
89
90
Field : "container component" ,
90
91
Name : componentName ,
91
92
}
92
- } else if ! mountFound {
93
- return "" , fmt .Errorf ("volume %s not mounted to component %s" , mountName , componentName )
94
93
}
95
94
96
- return path , nil
95
+ return "" , fmt . Errorf ( "volume %s not mounted to component %s" , mountName , componentName )
97
96
}
0 commit comments