Skip to content

Commit 47c0f1e

Browse files
authored
Fix diff when importing podspec resources containing volume_mount (#2061)
1 parent 643cd18 commit 47c0f1e

File tree

3 files changed

+65
-0
lines changed

3 files changed

+65
-0
lines changed

.changelog/2061.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:bug
2+
Fix diff after import when importing resources containing volume_mount
3+
```

kubernetes/structures_container.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,8 @@ func flattenContainerVolumeMounts(in []v1.VolumeMount) ([]interface{}, error) {
297297
if v.SubPath != "" {
298298
m["sub_path"] = v.SubPath
299299
}
300+
301+
m["mount_propagation"] = string(v1.MountPropagationNone)
300302
if v.MountPropagation != nil {
301303
m["mount_propagation"] = string(*v.MountPropagation)
302304
}

kubernetes/structures_container_test.go

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,3 +260,63 @@ func TestExpandContainerEnv(t *testing.T) {
260260
}
261261
}
262262
}
263+
264+
func TestFlattenContainerVolumeMounts_mountPropogation(t *testing.T) {
265+
bidimode := v1.MountPropagationBidirectional
266+
267+
cases := []struct {
268+
Input []v1.VolumeMount
269+
Expected []interface{}
270+
}{
271+
{
272+
[]v1.VolumeMount{
273+
{
274+
Name: "cache",
275+
MountPath: "/cache",
276+
ReadOnly: false,
277+
},
278+
},
279+
[]interface{}{
280+
map[string]interface{}{
281+
"mount_path": "/cache",
282+
"mount_propagation": "None",
283+
"name": "cache",
284+
"read_only": false,
285+
},
286+
},
287+
},
288+
{
289+
[]v1.VolumeMount{
290+
{
291+
Name: "cache",
292+
MountPath: "/cache",
293+
MountPropagation: &bidimode,
294+
ReadOnly: true,
295+
},
296+
},
297+
[]interface{}{
298+
map[string]interface{}{
299+
"mount_path": "/cache",
300+
"mount_propagation": "Bidirectional",
301+
"name": "cache",
302+
"read_only": true,
303+
},
304+
},
305+
},
306+
{
307+
[]v1.VolumeMount{},
308+
[]interface{}{},
309+
},
310+
}
311+
312+
for _, tc := range cases {
313+
output, err := flattenContainerVolumeMounts(tc.Input)
314+
if err != nil {
315+
t.Fatalf("Unexpected failure in flattener.\nInput: %#v, error: %#v", tc.Input, err)
316+
}
317+
if !reflect.DeepEqual(output, tc.Expected) {
318+
t.Fatalf("Unexpected output from expander.\nExpected: %#v\nGiven: %#v",
319+
tc.Expected, output)
320+
}
321+
}
322+
}

0 commit comments

Comments
 (0)